Learn R Programming

tigris (version 1.6)

blocks: Download a Census block shapefile into R

Description

Description from the US Census Bureau (see link for source): Census blocks are statistical areas bounded on all sides by visible features, such as streets, roads, streams, and railroad tracks, and by non-visible boundaries such as city, town, township, and county limits, and short line-of-sight extensions of streets and roads. Generally, census blocks are small in area; for example, a block in a city. Census blocks in suburban and rural areas may be large, irregular and bounded by a variety of features, such as roads, streams, and/or transmission line rights-of-way. In remote areas census blocks may encompass hundreds of square miles. Census blocks cover all territory in the United States, Puerto Rico, and the Island areas. Blocks do not cross the boundaries of any entity for which the Census Bureau tabulates data.

Usage

blocks(state, county = NULL, year = NULL, ...)

Arguments

state

The two-digit FIPS code (string) of the state you want. Can also be state name or state abbreviation.

county

The three-digit FIPS code (string) of the county you'd like to subset for, or a vector of FIPS codes if you desire multiple counties. Can also be a county name or vector of names.

year

The year for which you'd like to download data (defaults to 2020).

...

arguments to be passed to the underlying `load_tiger` function, which is not exported. Options include class, which can be set to "sf" (the default) or "sp" to request sf or sp class objects, and refresh, which specifies whether or not to re-download shapefiles (defaults to FALSE).

Details

This function will download an entire block shapefile for a selected state into R, and optionally subset by county. A warning: Census block shapefiles are often very large, especially for large states - for example, the block file for Texas is 462MB zipped! If you have a slow or unreliable internet connection, or insufficient memory, this may prove burdensome given that you have to first download by state and then subset.

See Also

https://www2.census.gov/geo/pdfs/maps-data/data/tiger/tgrshp2020/TGRSHP2020_TechDoc.pdf

Other general area functions: block_groups(), counties(), county_subdivisions(), places(), pumas(), school_districts(), states(), tracts(), zctas()

Examples

Run this code
# NOT RUN {
# Simple example using Rose Island, American Samoa
# Be careful with Census blocks for states!

library(tigris)
library(leaflet)

rose_island <- blocks(state = "AS", county = "Rose Island")

leaflet(rose_island) %>%
  addTiles() %>%
  addPolygons()

# }

Run the code above in your browser using DataLab