tiger_roads_sf {RcensusPkg} | R Documentation |
tiger_roads_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_roads_sf(
state = NULL,
county = NULL,
output_dir = tempdir(),
delete_files = TRUE,
vintage = 2020,
entity = "us_roads",
set_crs = NULL,
transform_crs = NULL,
sf_info = FALSE,
do_progress = FALSE,
shapefile = NULL,
datafile = NULL,
datafile_key = NULL,
sf_key = "GEOID",
express = NULL,
check_na = FALSE
)
Arguments
state |
A required 2-digit FIPS code for the state of interest. See usmap::fips function for finding FIPS codes. |
county |
The three-digit FIPS code for the county of interest. |
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. The value should be greater than 2010. |
entity |
A string that defines the category of road geometries to return. Acceptable value are "us_roads" (state & county arguments not required), "state_roads" (state argument required), "county_roads" (state & county arguments required). |
set_crs |
A numeric or character string which if non-NULL calls |
transform_crs |
A numeric or character string which if non-NULL calls |
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. |
datafile |
A dataframe containing data that should be joined with this function's resultant simple feature object. |
datafile_key |
The column name from 'datafile' dataframe used to key with the 'sf_key' column of the resultant simple feature dataframe. |
sf_key |
The column from the resultant dataframe used to key with the 'datafile' dataframe. |
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 "STATEFP". If you wanted to return just the geometries for Florida (which has a fips code of "12"), then you assign 'express' equal to: expression(STATEFP == "12"). The expression will be evaluated and only the geometries for Florida will be returned. |
check_na |
A logical which if Note: vintage must be greater than 2010 |
Details
Returns simple feature (sf) of US Census roads 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 roads related variables are provided. See Appendix L-3. Record Layouts: Roads Shapefile) for a description of road 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.12.3 Roads – Primary, Secondary and All Roads – "The primary and secondary roads shapefile contains all linear street features with MTFCCs of primary roads (S1100) or secondary roads (S1200) in the MAF/TIGER System. Secondary roads are main arteries, usually in the U.S. highway, state highway, or county highway system. These roads have one or more lanes of traffic in each direction, may or may not be divided, and usually have at-grade intersections with many other roads and driveways. These roads often have both a local name and a route number."
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.
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
library(downloader)
library(sf)
library(data.table)
library(withr)
library(usmap)
library(RcensusPkg)
# Get the sf geometries of roads in Ohio
# Get the fips for Ohio
oh_fips <- usmap::fips(state = "ohio")
# Define a temporary, self deleting output folder for the downloaded shapefiles
output_dir <- withr::local_tempdir()
if(!dir.exists(output_dir)){
dir.create(output_dir)
}
# Get the sf object
ohio_roads_sf <- RcensusPkg::tiger_roads_sf(
state = oh_fips,
entity = "state_roads",
output_dir = output_dir,
delete_files = FALSE
)