Title: | Spatial Centrality and Dispersion Statistics |
---|---|
Description: | Computing centrographic statistics (central points, standard distance, standard deviation ellipse, standard deviation box) for observations taken at point locations in 2D or 3D. The 'sfcentral' library was inspired in 'aspace' package but conceived to be used in a spatial 'tidyverse' context. |
Authors: | Gabriel V. Gaona [aut, cre] |
Maintainer: | Gabriel V. Gaona <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.1.0 |
Built: | 2025-03-13 05:32:49 UTC |
Source: | https://gitlab.com/gavg712/sfcentral |
Functions to find spatial measures of gravity centers.
st_central_point(.x, .y, ...) ## S3 method for class 'sfg' st_central_point( .x, .y = NULL, weights = NULL, method = c("mean", "median", "geometric", "feature", "min.dist"), ... ) ## S3 method for class 'sf' st_central_point( .x, .y = NULL, weights = NULL, method = c("mean", "median", "geometric", "feature", "min.dist"), ... ) ## S3 method for class 'sfc' st_central_point( .x, .y = NULL, weights = NULL, method = c("mean", "median", "geometric", "feature", "min.dist"), ... )
st_central_point(.x, .y, ...) ## S3 method for class 'sfg' st_central_point( .x, .y = NULL, weights = NULL, method = c("mean", "median", "geometric", "feature", "min.dist"), ... ) ## S3 method for class 'sf' st_central_point( .x, .y = NULL, weights = NULL, method = c("mean", "median", "geometric", "feature", "min.dist"), ... ) ## S3 method for class 'sfc' st_central_point( .x, .y = NULL, weights = NULL, method = c("mean", "median", "geometric", "feature", "min.dist"), ... )
.x , .y
|
|
... |
arguments to be passed to or from other methods |
weights |
Numeric. Used in for weigthed Mean Center. Has to be same length as number of points. |
method |
Character. Type of center point to calculate |
dist |
Atomic numeric, Default 100. Starting distance value for center moving during iterations. |
Spatial centers are spatial measures of the gravity center.
methods
options are:
"mean"
is the mean center (equivalent to centroid of the points) calculated by
the arithmetic mean of each axis;
"geometric"
, is the corresponding geometric mean of each axis;
"median"
, is the median center, a pair of c(median(x), median(y)) coordinates;
"feature"
, is a minimization of the sum of distances from ith point to every point;
"min.dist"
, is iterative looking for the closest point in bbox of .x
that minimizes the sum of distances from ith point to every point in the dataset
"Simple Features"
of lenght 1.
Inspired on aspace::*()
from Ron Buliung & Randy Bui (2012)
Gabriel Gaona
requireNamespace("ggplot2", quietly = TRUE) library(sf, quietly = TRUE) library(ggplot2) bbx <- matrix(c(697047,9553483, 696158,9560476, 700964,9561425, 701745,9555358), byrow = TRUE, ncol = 2) bbx <- st_multipoint(bbx) bbx <- st_cast(bbx,"POLYGON") bbx <- st_sfc(bbx, crs = 31992) set.seed(1234) points <- st_sf(geometry = st_sample(bbx, 100)) mean_center <- st_central_point(points, method = "mean") median_center <- st_central_point(points, method = "median") geom_center <- st_central_point(points, method = "geometric") central_feature <- st_central_point(points, method = "feature") min_dist_center <- st_central_point(points, method = "min.dist") ggplot() + geom_sf(data = points, color = "steelblue", size = 0.5) + geom_sf(data = mean_center, color = "blue", size = 3) + geom_sf(data = median_center, color = "red") + geom_sf(data = geom_center, color = "grey80") + geom_sf(data = central_feature, color = "orange") + geom_sf(data = min_dist_center, color = "green")
requireNamespace("ggplot2", quietly = TRUE) library(sf, quietly = TRUE) library(ggplot2) bbx <- matrix(c(697047,9553483, 696158,9560476, 700964,9561425, 701745,9555358), byrow = TRUE, ncol = 2) bbx <- st_multipoint(bbx) bbx <- st_cast(bbx,"POLYGON") bbx <- st_sfc(bbx, crs = 31992) set.seed(1234) points <- st_sf(geometry = st_sample(bbx, 100)) mean_center <- st_central_point(points, method = "mean") median_center <- st_central_point(points, method = "median") geom_center <- st_central_point(points, method = "geometric") central_feature <- st_central_point(points, method = "feature") min_dist_center <- st_central_point(points, method = "min.dist") ggplot() + geom_sf(data = points, color = "steelblue", size = 0.5) + geom_sf(data = mean_center, color = "blue", size = 3) + geom_sf(data = median_center, color = "red") + geom_sf(data = geom_center, color = "grey80") + geom_sf(data = central_feature, color = "orange") + geom_sf(data = min_dist_center, color = "green")
Calculate the spatial deviaction box from a points sf dataset. #' @author Gabriel Gaona
st_sd_box(.x, centre = NULL, weights = NULL, ...) ## S3 method for class 'sfg' st_sd_box(.x, centre = NULL, weights = NULL, ...) ## S3 method for class 'sf' st_sd_box(.x, centre = NULL, weights = NULL, ...) ## S3 method for class 'sfc' st_sd_box(.x, centre = NULL, weights = NULL, ...)
st_sd_box(.x, centre = NULL, weights = NULL, ...) ## S3 method for class 'sfg' st_sd_box(.x, centre = NULL, weights = NULL, ...) ## S3 method for class 'sf' st_sd_box(.x, centre = NULL, weights = NULL, ...) ## S3 method for class 'sfc' st_sd_box(.x, centre = NULL, weights = NULL, ...)
.x |
|
centre |
Numeric. Coordinates 2D or 3D of central point. Default NULL, performs a calculation of mean_centre() from point localities |
weights |
Numeric. Same length of number of .x. |
... |
ignored |
Depends on input, "coords" returns a data.frame of 2 or 3 columns and 4 or 8 point coordinates. "param" returns a data.frame with centre coordinates, standard deviation in each axis, space(area for 2D, volume for 3D) and number of dimensions in coordinates.
requireNamespace("ggplot2", quietly = TRUE) library(sf, quietly = TRUE) library(ggplot2) bbx <- matrix(c(697047,9553483, 696158,9560476, 700964,9561425, 701745,9555358), byrow = TRUE, ncol = 2) bbx <- st_multipoint(bbx) bbx <- st_cast(bbx,"POLYGON") bbx <- st_sfc(bbx, crs = 31992) set.seed(1234) points <- st_sf(geometry = st_sample(bbx, 100)) SD_BOX <- st_sd_box(points) ggplot() + geom_sf(data = SD_BOX, fill = NA, color = "darkolivegreen") + geom_sf(data = points, color = "steelblue", size = 0.5)
requireNamespace("ggplot2", quietly = TRUE) library(sf, quietly = TRUE) library(ggplot2) bbx <- matrix(c(697047,9553483, 696158,9560476, 700964,9561425, 701745,9555358), byrow = TRUE, ncol = 2) bbx <- st_multipoint(bbx) bbx <- st_cast(bbx,"POLYGON") bbx <- st_sfc(bbx, crs = 31992) set.seed(1234) points <- st_sf(geometry = st_sample(bbx, 100)) SD_BOX <- st_sd_box(points) ggplot() + geom_sf(data = SD_BOX, fill = NA, color = "darkolivegreen") + geom_sf(data = points, color = "steelblue", size = 0.5)
Calculate the spatial deviaction distance from a points sf dataset.
st_sd_distance(.x, centre = NULL, weights = NULL, ...) ## S3 method for class 'sfg' st_sd_distance(.x, centre = NULL, weights = NULL, ...) ## S3 method for class 'sf' st_sd_distance(.x, centre = NULL, weights = NULL, ...) ## S3 method for class 'sfc' st_sd_distance(.x, centre = NULL, weights = NULL, ...)
st_sd_distance(.x, centre = NULL, weights = NULL, ...) ## S3 method for class 'sfg' st_sd_distance(.x, centre = NULL, weights = NULL, ...) ## S3 method for class 'sf' st_sd_distance(.x, centre = NULL, weights = NULL, ...) ## S3 method for class 'sfc' st_sd_distance(.x, centre = NULL, weights = NULL, ...)
.x |
sf points 2D or 3D |
centre |
One central point of class sf, sfc, numeric
(length 2), matrix (2 col, 1 row), data.frame (2 col, 1 row),
or list (length 2). Default |
weights |
Numeric. Same length as number of points in |
... |
other parameters for |
A sf "POLYGON"
with atributes:
radius
(standard deviation distance)
area
surrounding,
perimeter
,
center
coordinates,
weigted
indicator if weights were used or not in the calculaton.
Gabriel Gaona
requireNamespace("ggplot2", quietly = TRUE) library(sf, quietly = TRUE) library(ggplot2) bbx <- matrix(c(697047,9553483, 696158,9560476, 700964,9561425, 701745,9555358), byrow = TRUE, ncol = 2) bbx <- st_multipoint(bbx) bbx <- st_cast(bbx,"POLYGON") bbx <- st_sfc(bbx, crs = 31992) set.seed(1234) points <- st_sf(geometry = st_sample(bbx, 100)) SDD <- st_sd_distance(points) ggplot() + geom_sf(data = SDD, fill = NA, color = "darkolivegreen") + geom_sf(data = points, color = "steelblue", size = 0.5)
requireNamespace("ggplot2", quietly = TRUE) library(sf, quietly = TRUE) library(ggplot2) bbx <- matrix(c(697047,9553483, 696158,9560476, 700964,9561425, 701745,9555358), byrow = TRUE, ncol = 2) bbx <- st_multipoint(bbx) bbx <- st_cast(bbx,"POLYGON") bbx <- st_sfc(bbx, crs = 31992) set.seed(1234) points <- st_sf(geometry = st_sample(bbx, 100)) SDD <- st_sd_distance(points) ggplot() + geom_sf(data = SDD, fill = NA, color = "darkolivegreen") + geom_sf(data = points, color = "steelblue", size = 0.5)
Calculate the spatial deviaction ellipse from a points sf dataset.
st_sd_ellipse(.x, centre = NULL, weights = NULL, ...) ## S3 method for class 'sfg' st_sd_ellipse(.x, centre = NULL, weights = NULL, ...) ## S3 method for class 'sf' st_sd_ellipse(.x, centre = NULL, weights = NULL, ...) ## S3 method for class 'sfc' st_sd_ellipse(.x, centre = NULL, weights = NULL, ...)
st_sd_ellipse(.x, centre = NULL, weights = NULL, ...) ## S3 method for class 'sfg' st_sd_ellipse(.x, centre = NULL, weights = NULL, ...) ## S3 method for class 'sf' st_sd_ellipse(.x, centre = NULL, weights = NULL, ...) ## S3 method for class 'sfc' st_sd_ellipse(.x, centre = NULL, weights = NULL, ...)
.x |
|
centre |
Numeric. Coordinates 2D of central point. Default NULL,
performs a calculation of |
weights |
Numeric. Same length of number of points. |
... |
ignored |
simple features as "POLYGON" with atributes: centre coordinates, values for mayor and minor axis radius (sigma.x and sigma.y), rotation (theta and theta_corrected) and geometry properties (eccentricity, area and perimeter)
Gabriel Gaona
requireNamespace("ggplot2", quietly = TRUE) library(sf, quietly = TRUE) library(ggplot2) bbx <- matrix(c(697047,9553483, 696158,9560476, 700964,9561425, 701745,9555358), byrow = TRUE, ncol = 2) bbx <- st_multipoint(bbx) bbx <- st_cast(bbx,"POLYGON") bbx <- st_sfc(bbx, crs = 31992) set.seed(1234) points <- st_sf(geometry = st_sample(bbx, 100)) SDE <- st_sd_ellipse(points) ggplot() + geom_sf(data = SDE, fill = NA, color = "darkolivegreen") + geom_sf(data = points, color = "steelblue", size = 0.5)
requireNamespace("ggplot2", quietly = TRUE) library(sf, quietly = TRUE) library(ggplot2) bbx <- matrix(c(697047,9553483, 696158,9560476, 700964,9561425, 701745,9555358), byrow = TRUE, ncol = 2) bbx <- st_multipoint(bbx) bbx <- st_cast(bbx,"POLYGON") bbx <- st_sfc(bbx, crs = 31992) set.seed(1234) points <- st_sf(geometry = st_sample(bbx, 100)) SDE <- st_sd_ellipse(points) ggplot() + geom_sf(data = SDE, fill = NA, color = "darkolivegreen") + geom_sf(data = points, color = "steelblue", size = 0.5)