Skip to contents

Median center iteratively calculates the point that minimizes distance to all features. One can specify the groups to calculate individual centers for and weights for each individual point. It is analagous to the ArcGIS Pro Median Center tool.

It uses the methodology introduced by Kuhn and Kuenne (1962).

Currently, median center is only implemenented for projected data.

Usage

median_center(x, group = NULL, weight = NULL, tolerance = 1e-04)

Arguments

x

Input POINT, MULTIPOINT, POLYGON, or MULTIPOLYGON simple features

group

name of character column specifying groups to calculate individual median centers for

weight

name of numeric weight column specifying an individual point's contribution to the median center

tolerance

numeric threshold determining when an estimate improvement is sufficiently small enough to stop iterating (smaller = slower, but more precision)

Value

An sf object with a median center for each group

Examples

df <- data.frame(
  lon = c(-88, -90, -92, -89, -90),
  lat = c(42, 40, 30, 32, 42),
  grp = c("a", "b", "a", "b", "a"),
  wt = c(1, 1, 1, 1, 1)
)
x <- sf::st_as_sf(df, coords = c("lon", "lat"), crs = 4326)
x_transformed <- sf::st_transform(x, crs = "ESRI:102003")
median_center(x_transformed, group = "grp", weight = "wt")
#> Simple feature collection with 2 features and 1 field
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 542640.4 ymin: -147278.5 xmax: 582550.3 ymax: 482723.9
#> Projected CRS: USA_Contiguous_Albers_Equal_Area_Conic
#>   group                   geometry
#> 1     a  POINT (542640.4 482723.9)
#> 2     b POINT (582550.3 -147278.5)