Download shapefiles based on FIPS codes of States, Counties, Cities/CDPs, Tracts, or Blockgroups (not blocks)
Source:R/shapes_from_fips.R
shapes_from_fips.RdDownload shapefiles based on FIPS codes of States, Counties, Cities/CDPs, Tracts, or Blockgroups (not blocks)
Usage
shapes_from_fips(
fips,
myservice_blockgroup = shapes_acs_boundary_service("blockgroup"),
myservice_tract = shapes_acs_boundary_service("tract"),
myservice_place = "tiger",
myservice_county = "cartographic",
allow_multiple_fips_types = TRUE,
year = NULL
)Arguments
- fips
vector of one or more Census FIPS codes such as from
name2fips()- myservice_blockgroup
A feature-service URL (the existing default), "cartographic", or "tiger". The latter two use optional package tigris to download and cache one boundary file per state, without requesting ACS data. This can be much faster than repeated service queries for many blockgroups. "cartographic" uses smaller, generalized 1:500,000 boundaries: fast to download and draw, but simplified and clipped along shorelines. Use it for overview maps, not precise area, buffering, or point-in-polygon analysis. "tiger" retains full TIGER/Line boundary detail; files are larger and slower to download and draw, but state-file caching still avoids repeated queries. The default service follows the active ACS vintage (Esri for 2022/2023, Census TIGERweb ACS2024 for 2024); tigris is required only when explicitly selecting either tigris option.
- myservice_tract
URL of feature service to get tract shapes from. The "cartographic" and "tiger" options are not implemented for tracts; the tract helper warns and uses its default service if these are requested.
- myservice_place
only "tiger" is implemented
- myservice_county
URL of feature service to get shapes from, or "cartographic" or "tiger" to use approx or slow/accurate bounds from tidycensus and tigris packages. Note State bounds are built into this package as data so do not need to be downloaded from a service. County bounds are too, as of the counties_shapefile dataset: the default "cartographic" County bounds are served from that built-in dataset rather than downloaded, falling back to downloading only for any FIPS not found there.
- allow_multiple_fips_types
if enabled, set TRUE to allow mix of blockgroup, tract, city, county, state fips
- year
Boundary year for
tigris::places()and for blockgroups when selecting "cartographic" or "tiger". NULL (the default) uses the calendar-predicted latest TIGER/Line places vintage for places (assuming an October 14 annual release, without checking publication), andacs_endyear()for those blockgroups. Places define areas to analyze and need not share the vintage of the demographic data overlaid on them. Specify a year explicitly to use another vintage for these downloads. County downloads continue to useacs_endyear(); built-in county/state boundaries must be rebuilt for the release's demographic geography. Default tract/blockgroup services follow the active ACS vintage. Service URLs determine their own vintage; year does not change the vintage embedded in a URL. Requested places without a boundary warn with their FIPS codes and year; their rows retain empty geometry, without substituting another vintage.
Details
Results follow the input FIPS order, including duplicates. Empty geometry rows preserve positional alignment for invalid inputs and for valid FIPS whose polygons could not be obtained. Only the supported FIPS types are downloaded; validation and Shiny errors retain their existing behavior.
Choose the boundary source explicitly when accuracy matters. A speed gain from state-file caching does not require simplifying the boundaries: use "tiger" to retain detail. Simplification with "cartographic" can change area, point membership, and buffer results, even if the FIPS codes are unchanged. Cached tigris blockgroups can be read offline; other download paths retain their connectivity checks. Missing polygons remain empty rows in the output.
Blocks are not implemented yet here. For info on blocks bounds, see tigris::block_groups()
Also note the blockwts dataset had a placeholder column block_radius_miles that
was just zero values, but see notes in EJAM/data-raw/datacreate_blockwts.R on how it could be obtained.
If it were used, it could be a way to quickly get the area of each block,
using the formula area = pi * (block_radius_miles^2)
For zip code boundaries, see shapes_from_zip() and EJAM documentation article on zipcodes.
Examples
# shp2 = shapes_from_fips("10001", "10005") # Counties not zip codes!
fipslist = list(
statefips = name2fips(c('DE', 'RI')),
countyfips = fips_counties_from_state_abbrev(c('DE')),
cityfips = name2fips(c('chelsea,MA', 'st. john the baptist parish, LA')),
tractfips = substr(blockgroupstats$bgfips[300:301], 1, 12),
bgfips = blockgroupstats$bgfips[300:301]
)
shp <- list()
# \donttest{
for (i in seq_along(fipslist)) {
shp[[i]] <- shapes_from_fips(fipslist[[i]])
print(shp[[i]])
# mapfast(shp[[i]])
}
# }