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)

Arguments

dir

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.

fips

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

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

Name for the GeoJSON file (without extension) to be written.

year

Year of the shapes, 2013 and after.

resolution

Resolution of the shapes; one of "500k" (default), "5m", or "20m".

strip_features

Logical; if TRUE, will strip all features other than IDs.

simplify

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.

force

Logical; if TRUE, will force a re-download, and overwrite any existing files.

Value

An sf

data.frame with a geometry column containing shapes, and other features in columns.

Examples

if (FALSE) {
# download Virginia counties shapes
shapes <- download_census_shapes(
  "docs/shapes", "va", "county",
  name = "counties",
  simplify = rmapshaper::ms_simplify, keep_shapes = TRUE
)
}