Accessing spatial data for Missouri
Source:vignettes/Missouri-Spatial-Data.Rmd
Missouri-Spatial-Data.Rmd
Background
Most of the spatial data in the MDCSpatialData package are derived from two R packages, tigris and FedData. Tigris lets you download sf objects of files from the national TIGER data set, while FedData lets you download spatial data from a variety of sources (NHD, NLCD, NASS, SSUGO, etc.) Your best bet is to look at those reference manuals, but I give a few quick examples here.
Plotting the Missouri spatial boundaries
This can be done easily with ggplot
#not run
MDCSpatialData::counties.mo->counties.mo
MDCSpatialData::state.mo->state.mo
ggplot(counties.mo)+
geom_sf()
ggplot(state.mo)+
geom_sf()
Extracting spatial data from FedData
There are a number of spatial, landcover, and weather data sets you can pull from. Definitley read the reference manual for this package to get a comprehensive idea of what data are available.
# need a boundary shape. If it's not a rectangle or a square, one will be created internal to the function before extracting the data. The bounding area will be extracted from the min/max X and Y coordinates of the polygon.
#get NASS Cropland data layer data this has a size limit for the raster
MDCSpatialData::countes.mo|>
dplyr::filter(NAME=='Boone')->boone.co
FedData::get_nass_cdl(template=boone.co,
label='MO',
year=2023)->cdl.boone
terra::plot(cdl.boone)
# returns a SpatRaster, a terra raster object class
#get NHD data
FedData::get_nhd(template=MDCSpatialData::state.mo,
label='MO', #for use if writing the data to file vs storing in memory.
nhdplus=TRUE)->nhd.mo
#Returns a list with 5 sf objects: Points,lines, flowlines, areas (streams and lakes), and water bodies.
# get HUC12 data (the only scale available in FedData)
FedData::get_wbd(template=MDCSpatialData::state.mo,label='MO')->huc.mo
#returns a sf object