Title: | Functions to Automate Downloading Geospatial Data Available from Several Federated Data Sources |
---|---|
Description: | Functions to automate downloading geospatial data available from several federated data sources (mainly sources maintained by the US Federal government). Currently, the package enables extraction from nine datasets: The National Elevation Dataset digital elevation models (1 and 1/3 arc-second; USGS); The National Hydrography Dataset (USGS); The Soil Survey Geographic (SSURGO) database from the National Cooperative Soil Survey (NCSS), which is led by the Natural Resources Conservation Service (NRCS) under the USDA; the Global Historical Climatology Network (GHCN), coordinated by National Climatic Data Center at NOAA; the Daymet gridded estimates of daily weather parameters for North America, version 4, available from the Oak Ridge National Laboratory's Distributed Active Archive Center (DAAC); the International Tree Ring Data Bank; the National Land Cover Database (NLCD); the Cropland Data Layer from the National Agricultural Statistics Service; and the PAD-US dataset of protected area boundaries from the USGS. |
Authors: | R. Kyle Bocinsky [aut, cre, cph]
|
Maintainer: | R. Kyle Bocinsky <[email protected]> |
License: | MIT + file LICENSE |
Version: | 4.0.1 |
Built: | 2024-08-29 22:58:41 UTC |
Source: | https://github.com/ropensci/FedData |
get_daymet
returns a SpatRaster
of weather data cropped to a given
template study area.
get_daymet( template, label, elements = c("dayl", "prcp", "srad", "swe", "tmax", "tmin", "vp"), years = 1980:(lubridate::year(Sys.time()) - 1), region = "na", tempo = "day", extraction.dir = file.path(tempdir(), "FedData", "extractions", "daymet", label), raster.options = c("COMPRESS=DEFLATE", "ZLEVEL=9", "INTERLEAVE=BAND"), force.redo = FALSE, progress = TRUE )
get_daymet( template, label, elements = c("dayl", "prcp", "srad", "swe", "tmax", "tmin", "vp"), years = 1980:(lubridate::year(Sys.time()) - 1), region = "na", tempo = "day", extraction.dir = file.path(tempdir(), "FedData", "extractions", "daymet", label), raster.options = c("COMPRESS=DEFLATE", "ZLEVEL=9", "INTERLEAVE=BAND"), force.redo = FALSE, progress = TRUE )
template |
An |
label |
A character string naming the study area. |
elements |
A character vector of elements to extract. |
years |
A numeric vector of years to extract. |
region |
The name of a region. The available regions are: |
tempo |
The frequency of the data. The available tempos are: |
extraction.dir |
A character string indicating where the extracted and cropped DEM should be put. Defaults to a temporary directory. |
raster.options |
a vector of GDAL options passed to terra::writeRaster. |
force.redo |
If an extraction for this template and label already exists in extraction.dir, should a new one be created? |
progress |
Draw a progress bar when downloading? |
A named list of SpatRaster
s of weather data cropped to the extent of the template.
## Not run: # Get the DAYMET (North America only) # Returns a list of raster bricks DAYMET <- get_daymet( template = FedData::meve, label = "meve", elements = c("prcp", "tmin", "tmax"), years = 1980:1985 ) # Plot with terra::plot plot(DAYMET$tmin$X1985.10.23) ## End(Not run)
## Not run: # Get the DAYMET (North America only) # Returns a list of raster bricks DAYMET <- get_daymet( template = FedData::meve, label = "meve", elements = c("prcp", "tmin", "tmax"), years = 1980:1985 ) # Plot with terra::plot plot(DAYMET$tmin$X1985.10.23) ## End(Not run)
get_ghcn_daily
returns a named list of length 2:
'spatial': A Simple Feature
of the locations of GHCN weather stations
in the template, and
'tabular': A named list of type data.frame()
with the daily weather data for each station.
The name of each list item is the station ID.
get_ghcn_daily( template = NULL, label = NULL, elements = NULL, years = NULL, raw.dir = file.path(tempdir(), "FedData", "raw", "ghcn"), extraction.dir = file.path(tempdir(), "FedData", "extractions", "ned", label), standardize = F, force.redo = F )
get_ghcn_daily( template = NULL, label = NULL, elements = NULL, years = NULL, raw.dir = file.path(tempdir(), "FedData", "raw", "ghcn"), extraction.dir = file.path(tempdir(), "FedData", "extractions", "ned", label), standardize = F, force.redo = F )
template |
An |
label |
A character string naming the study area. |
elements |
A character vector of elements to extract. ACMC = Average cloudiness midnight to midnight from 30-second
ceilometer data (percent) |
years |
A numeric vector indicating which years to get. |
raw.dir |
A character string indicating where raw downloaded files should be put. The directory will be created if missing. Defaults to './RAW/GHCN/'. |
extraction.dir |
A character string indicating where the extracted and cropped GHCN shapefiles should be put. The directory will be created if missing. Defaults to './EXTRACTIONS/GHCN/'. |
standardize |
Select only common year/month/day? Defaults to FALSE. |
force.redo |
If an extraction for this template and label already exists, should a new one be created? Defaults to FALSE. |
A named list containing the 'spatial' and 'tabular' data.
## Not run: # Get the daily GHCN data (GLOBAL) # Returns a list: the first element is the spatial locations of stations, # and the second is a list of the stations and their daily data GHCN.prcp <- get_ghcn_daily( template = FedData::meve, label = "meve", elements = c("prcp") ) # Plot the VEP polygon plot(meve$geometry) # Plot the spatial locations plot(GHCN.prcp$spatial, pch = 1, add = T) legend("bottomleft", pch = 1, legend = "GHCN Precipitation Records") # Elements for which you require the same data # (i.e., minimum and maximum temperature for the same days) # can be standardized using standardize==T GHCN.temp <- get_ghcn_daily( template = FedData::meve, label = "meve", elements = c("tmin", "tmax"), standardize = T ) # Plot the VEP polygon plot(meve$geometry) # Plot the spatial locations plot(GHCN.temp$spatial, pch = 1, add = T) legend("bottomleft", pch = 1, legend = "GHCN Temperature Records") ## End(Not run)
## Not run: # Get the daily GHCN data (GLOBAL) # Returns a list: the first element is the spatial locations of stations, # and the second is a list of the stations and their daily data GHCN.prcp <- get_ghcn_daily( template = FedData::meve, label = "meve", elements = c("prcp") ) # Plot the VEP polygon plot(meve$geometry) # Plot the spatial locations plot(GHCN.prcp$spatial, pch = 1, add = T) legend("bottomleft", pch = 1, legend = "GHCN Precipitation Records") # Elements for which you require the same data # (i.e., minimum and maximum temperature for the same days) # can be standardized using standardize==T GHCN.temp <- get_ghcn_daily( template = FedData::meve, label = "meve", elements = c("tmin", "tmax"), standardize = T ) # Plot the VEP polygon plot(meve$geometry) # Plot the spatial locations plot(GHCN.temp$spatial, pch = 1, add = T) legend("bottomleft", pch = 1, legend = "GHCN Temperature Records") ## End(Not run)
get_itrdb
returns a named list of length 3:
'metadata': A data frame or Simple Feature
(if makeSpatial==TRUE
) of the locations
and names of extracted ITRDB chronologies,
'widths': A matrix of tree-ring widths/densities given user selection, and
'depths': A matrix of tree-ring sample depths.
get_itrdb( template = NULL, label = NULL, recon.years = NULL, calib.years = NULL, species = NULL, measurement.type = NULL, chronology.type = NULL, raw.dir = paste0(tempdir(), "/FedData/raw/itrdb"), extraction.dir = ifelse(!is.null(label), paste0(tempdir(), "/FedData/extractions/itrdb/", label, "/"), paste0(tempdir(), "/FedData/extractions/itrdb")), force.redo = FALSE )
get_itrdb( template = NULL, label = NULL, recon.years = NULL, calib.years = NULL, species = NULL, measurement.type = NULL, chronology.type = NULL, raw.dir = paste0(tempdir(), "/FedData/raw/itrdb"), extraction.dir = ifelse(!is.null(label), paste0(tempdir(), "/FedData/extractions/itrdb/", label, "/"), paste0(tempdir(), "/FedData/extractions/itrdb")), force.redo = FALSE )
template |
An |
label |
A character string naming the study area. |
recon.years |
A numeric vector of years over which reconstructions are needed; if missing, the union of all years in the available chronologies are given. |
calib.years |
A numeric vector of all required years—chronologies without these years will be discarded; if missing, all available chronologies are given. |
species |
A character vector of 4-letter tree species identifiers; if missing, all available chronologies are given. |
measurement.type |
A character vector of measurement type identifiers. Options include:
if missing, all available chronologies are given. |
chronology.type |
A character vector of chronology type identifiers. Options include:
if missing, all available chronologies are given. |
raw.dir |
A character string indicating where raw downloaded files should be put. The directory will be created if missing. |
extraction.dir |
A character string indicating where the extracted and cropped ITRDB dataset should be put. The directory will be created if missing. |
force.redo |
If an extraction already exists, should a new one be created? Defaults to FALSE. |
A named list containing the 'metadata', 'widths', and 'depths' data.
## Not run: # Get the ITRDB records ITRDB <- get_itrdb(template = FedData::meve, label = "meve", makeSpatial = T) # Plot the VEP polygon plot(meve$geometry) # Map the locations of the tree ring chronologies plot(ITRDB$metadata, pch = 1, add = T) legend("bottomleft", pch = 1, legend = "ITRDB chronologies") ## End(Not run)
## Not run: # Get the ITRDB records ITRDB <- get_itrdb(template = FedData::meve, label = "meve", makeSpatial = T) # Plot the VEP polygon plot(meve$geometry) # Map the locations of the tree ring chronologies plot(ITRDB$metadata, pch = 1, add = T) legend("bottomleft", pch = 1, legend = "ITRDB chronologies") ## End(Not run)
get_nass_cdl
returns a SpatRaster
of NASS Cropland Data Layer cropped to a given
template study area.
get_nass_cdl( template, label, year = 2019, extraction.dir = paste0(tempdir(), "/FedData/"), raster.options = c("COMPRESS=DEFLATE", "ZLEVEL=9", "INTERLEAVE=BAND"), force.redo = FALSE, progress = TRUE ) get_nass(template, label, ...) get_cdl(template, label, ...) cdl_colors()
get_nass_cdl( template, label, year = 2019, extraction.dir = paste0(tempdir(), "/FedData/"), raster.options = c("COMPRESS=DEFLATE", "ZLEVEL=9", "INTERLEAVE=BAND"), force.redo = FALSE, progress = TRUE ) get_nass(template, label, ...) get_cdl(template, label, ...) cdl_colors()
template |
An |
label |
A character string naming the study area. |
year |
An integer representing the year of desired NASS Cropland Data Layer product. Acceptable values are 2007–the last year. |
extraction.dir |
A character string indicating where the extracted and cropped NASS data should be put. The directory will be created if missing. |
raster.options |
a vector of options for terra::writeRaster. |
force.redo |
If an extraction for this template and label already exists, should a new one be created? |
progress |
Draw a progress bar when downloading? |
... |
Other parameters passed on to get_nass_cdl. |
A SpatRaster
cropped to the bounding box of the template.
## Not run: # Extract data for the Mesa Verde National Park: # Get the NASS CDL (USA ONLY) # Returns a raster NASS <- get_nass_cdl( template = FedData::meve, label = "meve", year = 2011 ) # Plot with terra::plot plot(NASS) ## End(Not run)
## Not run: # Extract data for the Mesa Verde National Park: # Get the NASS CDL (USA ONLY) # Returns a raster NASS <- get_nass_cdl( template = FedData::meve, label = "meve", year = 2011 ) # Plot with terra::plot plot(NASS) ## End(Not run)
get_ned
returns a SpatRaster
of elevation data cropped to a given
template study area.
get_ned( template, label, res = "1", extraction.dir = file.path(tempdir(), "FedData", "extractions", "ned", label), raster.options = c("COMPRESS=DEFLATE", "ZLEVEL=9"), force.redo = FALSE )
get_ned( template, label, res = "1", extraction.dir = file.path(tempdir(), "FedData", "extractions", "ned", label), raster.options = c("COMPRESS=DEFLATE", "ZLEVEL=9"), force.redo = FALSE )
template |
An |
label |
A character string naming the study area. |
res |
A character string representing the desired resolution of the NED. '1' indicates the 1 arc-second NED (the default), while '13' indicates the 1/3 arc-second dataset. |
extraction.dir |
A character string indicating where the extracted and cropped DEM should be put. The directory will be created if missing. |
raster.options |
a vector of GDAL options passed to terra::writeRaster. |
force.redo |
If an extraction for this template and label already exists, should a new one be created? |
A SpatRaster
DEM cropped to the extent of the template.
## Not run: # Get the NED (USA ONLY) # Returns a `SpatRaster` NED <- get_ned( template = FedData::meve, label = "meve" ) # Plot with terra::plot plot(NED) ## End(Not run)
## Not run: # Get the NED (USA ONLY) # Returns a `SpatRaster` NED <- get_ned( template = FedData::meve, label = "meve" ) # Plot with terra::plot plot(NED) ## End(Not run)
get_nhd
returns a list of Simple Feature
objects extracted
from the National Hydrography Dataset.
get_nhd( template, label, nhdplus = FALSE, extraction.dir = file.path(tempdir(), "FedData", "extractions", "nhd", label), force.redo = FALSE )
get_nhd( template, label, nhdplus = FALSE, extraction.dir = file.path(tempdir(), "FedData", "extractions", "nhd", label), force.redo = FALSE )
template |
An |
label |
A character string naming the study area. |
nhdplus |
Extract data from the USGS NHDPlus High Resolution service (experimental) |
extraction.dir |
A character string indicating where the extracted and cropped NHD data should be put. |
force.redo |
If an extraction for this template and label already exists, should a new one be created? |
A list of sf
collections extracted from the National Hydrography Dataset.
## Not run: # Get the NHD (USA ONLY) NHD <- get_nhd( template = FedData::meve, label = "meve" ) NHD NHD %>% plot_nhd(template = FedData::meve) ## End(Not run)
## Not run: # Get the NHD (USA ONLY) NHD <- get_nhd( template = FedData::meve, label = "meve" ) NHD NHD %>% plot_nhd(template = FedData::meve) ## End(Not run)
get_nlcd
returns a SpatRaster
of NLCD data cropped to a given
template study area. nlcd_colors
and pal_nlcd
return the NLCD
legend and color palette, as available through the
MLRC website.
get_nlcd( template, label, year = 2021, dataset = "landcover", landmass = "L48", extraction.dir = file.path(tempdir(), "FedData", "extractions", "nlcd", label), raster.options = c("COMPRESS=DEFLATE", "ZLEVEL=9"), force.redo = FALSE ) nlcd_colors() pal_nlcd()
get_nlcd( template, label, year = 2021, dataset = "landcover", landmass = "L48", extraction.dir = file.path(tempdir(), "FedData", "extractions", "nlcd", label), raster.options = c("COMPRESS=DEFLATE", "ZLEVEL=9"), force.redo = FALSE ) nlcd_colors() pal_nlcd()
template |
An |
label |
A character string naming the study area. |
year |
An integer representing the year of desired NLCD product. Acceptable values are 2021 (default), 2019, 2016, 2011, 2008, 2006, 2004, and 2001. |
dataset |
A character string representing type of the NLCD product. Acceptable values are 'landcover' (default), 'impervious', and 'canopy'. |
landmass |
A character string representing the landmass to be extracted Acceptable values are 'L48' (lower 48 US states, the default), 'AK' (Alaska, 2011 and 2016 only), 'HI' (Hawaii, 2001 only), and 'PR' (Puerto Rico, 2001 only). |
extraction.dir |
A character string indicating where the extracted and cropped NLCD data should be put. The directory will be created if missing. |
raster.options |
a vector of GDAL options passed to terra::writeRaster. |
force.redo |
If an extraction for this template and label already exists, should a new one be created? |
A RasterLayer
cropped to the bounding box of the template.
## Not run: # Extract data for the Mesa Verde National Park: # Get the NLCD (USA ONLY) # Returns a raster NLCD <- get_nlcd( template = FedData::meve, label = "meve", year = 2016 ) # Plot with terra::plot plot(NLCD) ## End(Not run)
## Not run: # Extract data for the Mesa Verde National Park: # Get the NLCD (USA ONLY) # Returns a raster NLCD <- get_nlcd( template = FedData::meve, label = "meve", year = 2016 ) # Plot with terra::plot plot(NLCD) ## End(Not run)
get_padus
returns a list of sf
objects extracted
from the PAD-US Dataset. Data are retrieved directly from
PAD-US ArcGIS Web Services.
get_padus( template, label, layer = c("Manager_Name"), extraction.dir = file.path(tempdir(), "FedData", "extractions", "padus", label), force.redo = FALSE )
get_padus( template, label, layer = c("Manager_Name"), extraction.dir = file.path(tempdir(), "FedData", "extractions", "padus", label), force.redo = FALSE )
template |
An |
label |
A character string naming the study area. |
layer |
A character vector containing one or more PAD-US Layers. By default, the Manager_Name layer is downloaded.
|
extraction.dir |
A character string indicating where the extracted and cropped PAD-US data should be put. |
force.redo |
If an extraction for this template and label already exists, should a new one be created? |
PAD-US is America’s official national inventory of U.S. terrestrial and marine protected areas that are dedicated to the preservation of biological diversity and to other natural, recreation and cultural uses, managed for these purposes through legal or other effective means. PAD-US also includes the best available aggregation of federal land and marine areas provided directly by managing agencies, coordinated through the Federal Geographic Data Committee Federal Lands Working Group.
A list of sf::sf collections extracted from the PAD-US Dataset.
## Not run: # Get the PAD-US (USA ONLY) PADUS <- get_padus( template = FedData::meve, label = "meve" ) PADUS ## End(Not run)
## Not run: # Get the PAD-US (USA ONLY) PADUS <- get_padus( template = FedData::meve, label = "meve" ) PADUS ## End(Not run)
This is an efficient method for spatially merging several different soil survey areas as well as merging their tabular data.
get_ssurgo( template, label, raw.dir = paste0(tempdir(), "/FedData/raw/ssurgo"), extraction.dir = paste0(tempdir(), "/FedData/"), force.redo = FALSE )
get_ssurgo( template, label, raw.dir = paste0(tempdir(), "/FedData/raw/ssurgo"), extraction.dir = paste0(tempdir(), "/FedData/"), force.redo = FALSE )
template |
An |
label |
A character string naming the study area. |
raw.dir |
A character string indicating where raw downloaded files should be put. The directory will be created if missing. Defaults to './RAW/SSURGO/'. |
extraction.dir |
A character string indicating where the extracted and cropped SSURGO shapefiles should be put. The directory will be created if missing. Defaults to './EXTRACTIONS/SSURGO/'. |
force.redo |
If an extraction for this template and label already exists, should a new one be created? Defaults to FALSE. |
get_ssurgo
returns a named list of length 2:
'spatial': A Simple Feature
of soil mapunits
in the template, and
'tabular': A named list of data.frames
with the SSURGO tabular data.
A named list containing the 'spatial' and 'tabular' data.
## Not run: # Get the NRCS SSURGO data (USA ONLY) SSURGO.MEVE <- get_ssurgo(template = FedData::meve, label = "meve") # Plot the VEP polygon plot(meve$geometry) # Plot the SSURGO mapunit polygons plot(SSURGO.MEVE$spatial, lwd = 0.1, add = T) # Or, download by Soil Survey Area names SSURGO.areas <- get_ssurgo(template = c("CO670", "CO075"), label = "CO_TEST") # Let's just look at spatial data for CO675 SSURGO.areas.CO675 <- SSURGO.areas$spatial[SSURGO.areas$spatial$AREASYMBOL == "CO075", ] # And get the NED data under them for pretty plotting NED.CO675 <- get_ned(template = SSURGO.areas.CO675, label = "SSURGO_CO675") # Plot the SSURGO mapunit polygons, but only for CO675 plot(NED.CO675) plot(SSURGO.areas.CO675, lwd = 0.1, add = T) ## End(Not run)
## Not run: # Get the NRCS SSURGO data (USA ONLY) SSURGO.MEVE <- get_ssurgo(template = FedData::meve, label = "meve") # Plot the VEP polygon plot(meve$geometry) # Plot the SSURGO mapunit polygons plot(SSURGO.MEVE$spatial, lwd = 0.1, add = T) # Or, download by Soil Survey Area names SSURGO.areas <- get_ssurgo(template = c("CO670", "CO075"), label = "CO_TEST") # Let's just look at spatial data for CO675 SSURGO.areas.CO675 <- SSURGO.areas$spatial[SSURGO.areas$spatial$AREASYMBOL == "CO075", ] # And get the NED data under them for pretty plotting NED.CO675 <- get_ned(template = SSURGO.areas.CO675, label = "SSURGO_CO675") # Plot the SSURGO mapunit polygons, but only for CO675 plot(NED.CO675) plot(SSURGO.areas.CO675, lwd = 0.1, add = T) ## End(Not run)
get_wbd
returns an Simple Feature
collection of the HUC 12 regions within
the specified template
.
get_wbd( template, label, extraction.dir = file.path(tempdir(), "FedData", "extractions", "nhd", label), force.redo = FALSE )
get_wbd( template, label, extraction.dir = file.path(tempdir(), "FedData", "extractions", "nhd", label), force.redo = FALSE )
template |
An |
label |
A character string naming the study area. |
extraction.dir |
A character string indicating where the extracted and cropped NHD data should be put. |
force.redo |
If an extraction for this template and label already exists, should a new one be created? |
An sf
collection of the HUC 12 regions within
the specified template
.
A dataset containing the spatial polygon defining the boundary of Mesa Verde National Park in Montana.
meve
meve
Simple feature collection with 1 feature and a geometry field.
This is more of an example than anything
plot_nhd(x, template = NULL)
plot_nhd(x, template = NULL)
x |
The result of get_nhd. |
template |
An |
A ggplot2
panel of plots
## Not run: # Get the NHD (USA ONLY) NHD <- get_nhd( template = FedData::meve, label = "meve" ) NHD NHD %>% plot_nhd(template = FedData::meve) ## End(Not run)
## Not run: # Get the NHD (USA ONLY) NHD <- get_nhd( template = FedData::meve, label = "meve" ) NHD NHD %>% plot_nhd(template = FedData::meve) ## End(Not run)
Replace all the empty values in a list
replace_null(x)
replace_null(x)
x |
A list |
list(a = NULL, b = 1, c = list(foo = NULL, bar = NULL)) %>% replace_null()
list(a = NULL, b = 1, c = list(foo = NULL, bar = NULL)) %>% replace_null()