Match Across Geographic Layers
geo_match(from, to, method = "center", tiebreaker = TRUE, epsg = 3857)
smaller geographic level to match up from
larger geographic level to be matched to
string from center, centroid, point, or area for matching method
Should ties be broken? boolean. If FALSE, precincts with no matches get value -1 and precincts with multiple matches get value -2.
numeric EPSG code to planarize to. Default is 3857.
Integer Vector of matches length(to) with values in 1:nrow(from)
library(dplyr)
data(checkerboard)
counties <- sf::st_as_sf(as.data.frame(rbind(
sf::st_union(checkerboard %>% filter(i < 4)),
sf::st_union(checkerboard %>% filter(i >= 4))
)))
geo_match(from = checkerboard, to = counties)
#> Warning: Planarizing skipped. `x` missing CRS.
#> Warning: Planarizing skipped. `x` missing CRS.
#> [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2
#> [39] 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
geo_match(from = checkerboard, to = counties, method = 'area')
#> Warning: Planarizing skipped. `x` missing CRS.
#> [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2
#> [39] 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2