download_census_shapes.Rd
Download cartographic boundary files from the U.S. Census Bureau, and reformat them to simplified GeoJSON files.
download_census_shapes(dir = NULL, fips = "us", entity = "state",
name = NULL, year = 2019, resolution = "500k",
strip_features = FALSE, simplify = NULL, ..., force = FALSE)
Path to a directory in which to save the reformatted files. If these are to be
used in a published site, they should be in the "docs"
directory of the site directory. If not specified,
the shapes are downloaded and returned, but not saved.
State Federal Information Processing Standard (FIPS) code, United States Postal Service (USPS) code, or name; see https://www2.census.gov/geo/docs/reference/state.txt.
Entity name (e.g., "county"
, "tract"
, or "bg"
); see
https://www2.census.gov/geo/tiger/GENZ2019/2019_file_name_def.pdf
(or appropriate year's file). States and counties are only available at the national level, so if these are
requested for a particular state, the national files will be downloaded and subset.
Name for the GeoJSON file (without extension) to be written.
Year of the shapes, 2013 and after.
Resolution of the shapes; one of "500k"
(default), "5m"
, or "20m"
.
Logical; if TRUE
, will strip all features other than IDs.
A function to simplify shapes with, such as rmapshaper::ms_simplify
. This
function should take the sf
data.frame
as its first argument, and return that object
with its geometry
replaced.
Passes additional arguments to simplify
; e.g., for rmapshaper::ms_simplify
,
you might want to specify keep
and set keep_shapes
to TRUE
.
Logical; if TRUE
, will force a re-download, and overwrite any existing files.
An sf
data.frame
with a geometry column containing shapes, and other features in columns.
if (FALSE) {
# download Virginia counties shapes
shapes <- download_census_shapes(
"docs/shapes", "va", "county",
name = "counties",
simplify = rmapshaper::ms_simplify, keep_shapes = TRUE
)
}