read_ipums_sf | R Documentation |
Read a spatial data file (also referred to as a GIS file or shapefile) from
an IPUMS extract into an sf
object from the
sf package.
read_ipums_sf(
shape_file,
file_select = NULL,
vars = NULL,
encoding = NULL,
bind_multiple = FALSE,
add_layer_var = NULL,
verbose = FALSE,
shape_layer = deprecated()
)
shape_file |
Path to a single .shp file or a .zip archive containing at least one .shp file. See Details section. |
file_select |
If |
vars |
Names of variables to include in the output. Accepts a
character vector of names or a tidyselect selection.
If |
encoding |
Encoding to use when reading the shape file. If |
bind_multiple |
If |
add_layer_var |
If The column name will always be prefixed with |
verbose |
If |
shape_layer |
Some IPUMS products provide shapefiles in a "nested" .zip archive. That is, each shapefile (including a .shp as well as accompanying files) is compressed in its own archive, and the collection of all shapefiles provided in an extract is also compressed into a single .zip archive.
read_ipums_sf()
is designed to handle this structure. However, if any files
are altered such that an internal .zip archive contains multiple
shapefiles, this function will throw an error. If this is the case, you may
need to manually unzip the downloaded file before loading it into R.
An sf object
read_ipums_micro()
or read_nhgis()
to read tabular data from
an IPUMS extract.
ipums_list_files()
to list files in an IPUMS extract.
# Example shapefile from NHGIS
shape_ex1 <- ipums_example("nhgis0972_shape_small.zip")
data_ex1 <- read_nhgis(ipums_example("nhgis0972_csv.zip"), verbose = FALSE)
sf_data <- read_ipums_sf(shape_ex1)
sf_data
# To combine spatial data with tabular data without losing the attributes
# included in the tabular data, use an ipums shape join:
ipums_shape_full_join(data_ex1, sf_data, by = "GISJOIN")
shape_ex2 <- ipums_example("nhgis0712_shape_small.zip")
# Shapefiles are provided in .zip archives that may contain multiple
# files. Select a single file with `file_select`:
read_ipums_sf(shape_ex2, file_select = matches("us_pmsa_1990"))
# Or row-bind files with `bind_multiple`. This may be useful for files of
# the same geographic level that cover different extents)
read_ipums_sf(
shape_ex2,
file_select = matches("us_pmsa"),
bind_multiple = TRUE
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.