Learn R Programming

sfcentral (version 0.1.0)

st_central_point: Spatial centrality

Description

Functions to find spatial measures of gravity centers.

Usage

st_central_point(.x, .y, ...)

# S3 method for sfg st_central_point( .x, .y = NULL, weights = NULL, method = c("mean", "median", "geometric", "feature", "min.dist"), ... )

# S3 method for sf st_central_point( .x, .y = NULL, weights = NULL, method = c("mean", "median", "geometric", "feature", "min.dist"), ... )

# S3 method for sfc st_central_point( .x, .y = NULL, weights = NULL, method = c("mean", "median", "geometric", "feature", "min.dist"), ... )

Value

"Simple Features" of lenght 1.

Arguments

.x, .y

sf points 2D or 3D

...

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.

Author

Gabriel Gaona

Details

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

Examples

Run this code
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")

Run the code above in your browser using DataLab