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)

Arguments

lower

The lower geography that makes up the precinct, this is often a block level geography.

precinct

The single precinct that you would like to split.

split_by

The upper geography that you want to split precinct by

lower_wt

Optional. Numeric weights to give to each precinct, typically VAP or population.

split_by_id

Optional. A string that names a column in split_by that identifies each observation in split_by

epsg

numeric EPSG code to planarize to. Default is 3857.

Value

sf data frame with precinct split

Examples

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