tiger_blocks_sf {RcensusPkg} | R Documentation |
tiger_blocks_sf
Description
This function performs three tasks:
Download to an output directory a zip file from the TIGER/Line Shapefiles database.
Unzip the zip file and locate the shape file of interest.
Read and convert the shape file to a simple feature object.
Usage
tiger_blocks_sf(
state = NULL,
output_dir = tempdir(),
delete_files = TRUE,
vintage = 2020,
set_crs = NULL,
transform_crs = NULL,
sf_info = FALSE,
do_progress = FALSE,
shapefile = NULL,
express = NULL,
check_na = FALSE
)
Arguments
state |
A required two-digit FIPS code for the state of interest. See usmap::fips function for finding FIPS codes. |
output_dir |
A full directory path where the shapefile and its associated files will be downloaded.
The default is the directory defined by the value returned by |
delete_files |
A logical which if |
vintage |
A numeric that sets the vintage of interest. The default is 2020. |
set_crs |
A numeric or character string which if non-NULL calls sf::st_crs() to set the crs of the geometries and transforms them. |
transform_crs |
A numeric or character string which if non-NULL calls sf::st_transform() to perform a crs transform of the geometries. Note that the crs of the shapefile must not be NA. |
sf_info |
A logical which if |
do_progress |
A logical which if |
shapefile |
A full file path to a shapefile folder with its unzipped files to be processed instead of downloading. |
express |
A logical expression object used to filter the resultant simple feature dataframe. For example, one of the columns of the resultant simple feature dataframe is "COUNTYFP". If you wanted to return just the geometries for Los Alamos, New Mexico (which has a fips code of "028"), then you assign 'express' equal to: expression(COUNTYFP == "028"). The expression will be evaluated and only the tract geometries for Los Alamos will be returned. |
check_na |
A logical which if |
Details
Returns simple feature (sf) of US Census block boundary related geometric polygons, provided by the US Census Bureau's TIGER/Line Shapefiles database. See Simple Features for R for more information on simple features. Along with the geometries, additional block related variables are provided. See Appendix G-1. Record Layout: Block State-based Shapefile) for a description of block related variables of the sf file. For further information on the Census Bureau's shape files see About the 2021 TIGER/Line Shapefiles. From Chapter 4.2 Blocks – "Census blocks are statistical areas bounded on all sides by visible features (e.g., streets, roads, streams, and railroad tracks), and by non-visible boundaries (e.g., city, town, township, county limits, and short line-of-sight extensions of streets and roads)."
The function returns the simple feature object which can easily be mapped (see RplotterPkg::create_sf_plot()) or joined with US Census Bureau demographic data via the GEOID value. Be aware that shapefiles for blocks can be very large and time consuming to download for some states.
Some earlier vintages may have NA for the crs so you may need to specify the crs_transform
to 3426. Also
you may be interested in using a state level crs. See epsg.io to search worldwide for crs.
Value
A data frame object of class sf
Examples
## Not run:
# Beware that downloading and processing state blocks can be time consuming
library(sf)
library(downloader)
library(usmap)
library(withr)
library(data.table)
library(RcensusPkg)
vt_fips <- usmap::fips(state="vermont")
output_dir <- withr::local_tempdir()
if(!dir.exists(output_dir)){
dir.create(output_dir)
}
vt_blocks_sf <- RcensusPkg::tiger_blocks_sf(
state = vt_fips,
output_dir = output_dir,
delete_files = FALSE
)
## End(Not run)