Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Runs redistricting analysis in R with the redistverse packages, covering data loading, simulation, constraints, metrics and visualization.
45% 86%+41 ptsof test cases passed
Passed 19 of 22 test cases with the skill, and 10 of 22 without it.
To obtain official Census Bureau Block Assignment Files (BAF) for state legislative redistricting reconciliation in R, which package provides a direct function to download these BAF files?
The response recommends using the baf package.
3 of 3 safety checks passed
This file covers geomander's tools for matching geographic units across datasets, disaggregating and reaggregating data between geographic levels, and processing spatial data for redistricting analysis. The core workflow is: match blocks to precincts, estimate election data down to blocks, then re-aggregate to new geographic boundaries.
geo_match() assigns each unit in one geographic layer to the most appropriate unit in another layer.
geo_match(
from = blocks_sf, # smaller geography (source)
to = precincts_sf, # larger geography (target)
method = 'centroid', # see methods below
by = NULL, # optional: column to match within
tiebreaker = TRUE, # resolve ties
epsg = 3857
)
# Returns: integer vector (length = nrow(from)), each entry is the row index in `to`
| Method | Description | Best for |
|---|---|---|
"centroid" | Assigns to the to unit containing the centroid | Most cases |
"center" | Uses approximate center (handles non-convex shapes better) | Irregular shapes |
"point" | Uses surface point (guaranteed inside polygon) | Concave/donut polygons |
"circle" | Uses center of largest inscribed circle | Compact shapes |
"area" | Assigns to to unit with greatest overlap | Boundary-crossing units |
# Match blocks to precincts by centroid
matches <- geo_match(from = blocks_sf, to = precincts_sf, method = 'centroid')
# Match within county (faster for large states)
matches <- geo_match(from = blocks_sf, to = precincts_sf,
by = c('COUNTYFP', 'COUNTYFP'), # column in from, column in to
method = 'centroid')
Next to this one in the catalogue, plus more from the same author.