Title: | Weighted and Unweighted Spatial Centers |
---|---|
Description: | Generate mean and median weighted or unweighted spatial centers. Functions are analogous to their identically named counterparts within 'ArcGIS Pro'. Median center methodology based off of Kuhn and Kuenne (1962) <doi:10.1111/j.1467-9787.1962.tb00902.x>. |
Authors: | Ryan Zomorrodi [aut, cre, cph] |
Maintainer: | Ryan Zomorrodi <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.0 |
Built: | 2024-10-31 04:50:49 UTC |
Source: | https://github.com/ryanzomorrodi/centr |
Mean center calculates the geographic average center. One can specify the groups to calculate individual centers for groups and weights for each individual point. It is analagous to the ArcGIS Pro Mean Center tool.
If st_is_longlat(x)
, mean center is calculated assuming a
spherical Earth. Projected data is calculated assuming a
"flat" Earth.
mean_center(x, group = NULL, weight = NULL)
mean_center(x, group = NULL, weight = NULL)
x |
Input POINT or POLYGON simple features |
group |
name of character column specifying groups to calculate individual mean centers for |
weight |
name of numeric weight column specifying an individual point's contribution to the mean center |
An sf object with a mean center for each group
df <- data.frame( lon = c(20, 50, 30, 80, 10), lat = c(25, 70, 30, 50, 30), grp = c("a", "b", "a", "b", "a"), wt = c(1, 5, 1, 3, 2) ) x <- sf::st_as_sf(df, coords = c("lon", "lat"), crs = 4326) mean_center(x, group = "grp", weight = "wt")
df <- data.frame( lon = c(20, 50, 30, 80, 10), lat = c(25, 70, 30, 50, 30), grp = c("a", "b", "a", "b", "a"), wt = c(1, 5, 1, 3, 2) ) x <- sf::st_as_sf(df, coords = c("lon", "lat"), crs = 4326) mean_center(x, group = "grp", weight = "wt")
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.
median_center(x, group = NULL, weight = NULL, tolerance = 1e-04)
median_center(x, group = NULL, weight = NULL, tolerance = 1e-04)
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) |
An sf object with a median center for each group
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")
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")