States often split a precinct when they create districts but rarely provide the geography for the split precinct. This allows you to split a precinct using a lower geography, typically blocks.
split_precinct(lower, precinct, split_by, lower_wt, split_by_id, epsg = 3857)
The lower geography that makes up the precinct, this is often a block level geography.
The single precinct that you would like to split.
The upper geography that you want to split precinct by
Optional. Numeric weights to give to each precinct, typically VAP or population.
Optional. A string that names a column in split_by that identifies each observation in split_by
numeric EPSG code to planarize to. Default is 3857.
sf data frame with precinct split
library(sf)
#> Linking to GEOS 3.10.2, GDAL 3.4.1, PROJ 8.2.1; sf_use_s2() is TRUE
data(checkerboard)
low <- checkerboard |> dplyr::slice(1:3, 9:11)
prec <- checkerboard |>
dplyr::slice(1:3) |>
dplyr::summarize(geometry = sf::st_union(geometry))
dists <- checkerboard |>
dplyr::slice(1:3, 9:11) |>
dplyr::mutate(dist = c(1, 2, 2, 1, 3, 3)) |>
dplyr::group_by(dist) |>
dplyr::summarize(geometry = sf::st_union(geometry))
split_precinct(low, prec, dists, split_by_id = 'dist')
#> Warning: Planarizing skipped. `x` missing CRS.
#> Warning: Planarizing skipped. `x` missing CRS.
#> Simple feature collection with 2 features and 2 fields
#> Geometry type: POLYGON
#> Dimension: XY
#> Bounding box: xmin: 0 ymin: 0 xmax: 1 ymax: 3
#> CRS: NA
#> # A tibble: 2 × 3
#> new geometry id
#> * <int> <POLYGON> <dbl>
#> 1 1 ((0 0, 1 0, 1 1, 0 1, 0 0)) 1
#> 2 2 ((1 1, 0 1, 0 2, 0 3, 1 3, 1 2, 1 1)) 2