Skip to contents

Downloads Census ZIP Code Tabulation Area (ZCTA) boundaries for the specified zip code(s), returning polygons that can be analyzed like any other shapefile, as with ejamit(zipcode = 10605) which uses this function. See the Zipcodes article/vignette for more background.

Usage

shapes_from_zip(zipcode, year = NULL, ...)

Arguments

zipcode

vector of one or more 5-digit zip codes, as numbers or text (leading zeroes are restored if missing, so 1001 means zip code 01001, and a ZIP+4 like "10605-1234" is truncated to its first 5 digits)

year

optional year of ZCTA vintage, passed to tigris::zctas(). If NULL (default), the tigris package default is used.

...

passed to tigris::zctas()

Value

A spatial data.frame (sf::sf) with one row per zip code found (in the same order as the requested zip codes), including a zip column.

Details

Census uses ZIP Code Tabulation Areas (ZCTAs), which are generalized areal representations of United States Postal Service (USPS) ZIP Code service areas – see help("zctas", package = "tigris"). Some zip codes (e.g., ones used only for PO boxes or single buildings) have no ZCTA polygon, and this function warns about and drops those.

Note the first use can be slow, since tigris::zctas() downloads a large national file, but it is cached locally (see tigris::tigris_cache_dir()) so later calls are fast.

Examples

if (FALSE) { # \dontrun{
  shp <- shapes_from_zip(c("10012", "10506"))
  mapfast(shp)
  out <- ejamit(shapefile = shp) # same as out <- ejamit(zipcode = c("10012", "10506"))
  } # }