FedData version 3.0 has been released to CRAN! There are several breaking changes in the FedData API from version 2.x. Please see [NEWS.md] for a list of changes.
FedData is an R package implementing functions
to automate downloading geospatial data available from several federated
data sources.
Currently, the package enables extraction from seven datasets:
This package is designed with the large-scale geographic information system (GIS) use-case in mind: cases where the use of dynamic web-services is impractical due to the scale (spatial and/or temporal) of analysis. It functions primarily as a means of downloading tiled or otherwise spatially-defined datasets; additionally, it can preprocess those datasets by extracting data within an area of interest (AoI), defined spatially. It relies heavily on the sf and terra packages.
FedDatainstall.packages("FedData")install.packages("devtools")
devtools::install_github("ropensci/FedData")sf available
at https://r-spatial.github.io/sf/.This demonstration script is available as an R Markdown document in the GitHub repository: https://github.com/ropensci/FedData.
FedData
and define a study area# FedData Tester
library(FedData)
library(magrittr)
# FedData comes loaded with the boundary of Mesa Verde National Park, for testing
FedData::meve# Get the NED (USA ONLY)
# Returns a raster
NED <- get_ned(
template = FedData::meve,
label = "meve"
)
# Plot with raster::plot
raster::plot(NED)
# Get the DAYMET (North America only)
# Returns a raster
DAYMET <- get_daymet(
template = FedData::meve,
label = "meve",
elements = c("prcp", "tmax"),
years = 1980:1985
)
# Plot with raster::plot
raster::plot(DAYMET$tmax$X1985.10.23)
# 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")
)
#> Warning: `select_()` was deprecated in dplyr 0.7.0.
#> ℹ Please use `select()` instead.
#> ℹ The deprecated feature was likely used in the dplyr package.
#> Please report the issue at <]8;;https://github.com/tidyverse/dplyr/issueshttps://github.com/tidyverse/dplyr/issues]8;;>.
#> Warning in CPL_write_ogr(obj, dsn, layer, driver,
#> as.character(dataset_options), : GDAL Error 1: /private/var/folders/ys/
#> 7l0z3wlx7z14qxn9v0m9ckhw0000gq/T/RtmpcJyagw/FedData/extractions/ghcn/meve/
#> meve_GHCN_stations.shp does not appear to be a file or directory.
#> Warning: `filter_()` was deprecated in dplyr 0.7.0.
#> ℹ Please use `filter()` instead.
#> ℹ See vignette('programming') for more help
#> ℹ The deprecated feature was likely used in the dplyr package.
#> Please report the issue at <]8;;https://github.com/tidyverse/dplyr/issueshttps://github.com/tidyverse/dplyr/issues]8;;>.
#> Warning: `funs_()` was deprecated in dplyr 0.7.0.
#> ℹ Please use `funs()` instead.
#> ℹ See vignette('programming') for more help
#> ℹ The deprecated feature was likely used in the dplyr package.
#> Please report the issue at <]8;;https://github.com/tidyverse/dplyr/issueshttps://github.com/tidyverse/dplyr/issues]8;;>.
#> Warning: `funs()` was deprecated in dplyr 0.8.0.
#> ℹ Please use a list of either functions or lambdas:
#>
#> # Simple named list: list(mean = mean, median = median)
#>
#> # Auto named with `tibble::lst()`: tibble::lst(mean, median)
#>
#> # Using lambdas list(~ mean(., trim = .2), ~ median(., na.rm = TRUE))
#> ℹ The deprecated feature was likely used in the dplyr package.
#> Please report the issue at <]8;;https://github.com/tidyverse/dplyr/issueshttps://github.com/tidyverse/dplyr/issues]8;;>.
# Plot the NED again
raster::plot(NED)
# Plot the spatial locations
sp::plot(GHCN.prcp$spatial,
pch = 1,
add = TRUE
)
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"),
years = 1980:1985,
standardize = TRUE
)
#> Warning: `arrange_()` was deprecated in dplyr 0.7.0.
#> ℹ Please use `arrange()` instead.
#> ℹ See vignette('programming') for more help
#> ℹ The deprecated feature was likely used in the dplyr package.
#> Please report the issue at <]8;;https://github.com/tidyverse/dplyr/issueshttps://github.com/tidyverse/dplyr/issues]8;;>.
# Plot the NED again
raster::plot(NED)
# Plot the spatial locations
sp::plot(GHCN.temp$spatial,
add = TRUE,
pch = 1
)
legend("bottomleft",
pch = 1,
legend = "GHCN Temperature Records"
)
# Get the NHD (USA ONLY)
get_nhd(
template = FedData::meve,
label = "meve"
) %>%
plot_nhd(template = FedData::meve)
# Get the NRCS SSURGO data (USA ONLY)
SSURGO.MEVE <- get_ssurgo(
template = FedData::meve,
label = "meve"
)
# Plot the NED again
raster::plot(NED)
# Plot the SSURGO mapunit polygons
plot(SSURGO.MEVE$spatial$geom,
lwd = 0.1,
add = TRUE
)
# 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 %>%
dplyr::filter(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
raster::plot(NED.CO675)
plot(SSURGO.areas.CO675$geom,
lwd = 0.1,
add = TRUE
)
# Get the ITRDB records
# Buffer MEVE, because there aren't any chronologies in the Park
ITRDB <- get_itrdb(
template = FedData::meve %>%
sf::st_buffer(50000),
label = "meve",
measurement.type = "Ring Width",
chronology.type = "Standard"
)
#> Warning in eval(jsub, SDenv, parent.frame()): NAs introduced by coercion
#> Warning: attribute variables are assumed to be spatially constant throughout all
#> geometries
# Plot the MEVE buffer
plot(
FedData::meve %>%
sf::st_buffer(50000) %>%
sf::st_transform(4326)
)
# Map the locations of the tree ring chronologies
plot(ITRDB$metadata$geometry,
pch = 1,
add = TRUE
)
legend("bottomleft",
pch = 1,
legend = "ITRDB chronologies"
)
# Get the NLCD (USA ONLY)
# Returns a raster
NLCD <- get_nlcd(
template = FedData::meve,
year = 2011,
label = "meve"
)
# Plot with raster::plot
raster::plot(NLCD)
# Get the NASS (USA ONLY)
# Returns a raster
NASS_CDL <- get_nass_cdl(
template = FedData::meve,
year = 2016,
label = "meve"
)
# Plot with raster::plot
raster::plot(NASS_CDL)
# Get the NASS CDL classification table
raster::levels(NASS_CDL)[[1]]
#> NULL
# Also, a convenience function loading the NASS CDL categories and hex colors
cdl_colors()
#> # A tibble: 256 × 3
#> ID `Land Cover` Color
#> <int> <fct> <chr>
#> 1 0 Background #00000000
#> 2 1 Corn #FFD300FF
#> 3 2 Cotton #FF2626FF
#> 4 3 Rice #00A8E4FF
#> 5 4 Sorghum #FF9E0BFF
#> 6 5 Soybeans #267000FF
#> 7 6 Sunflower #FFFF00FF
#> 8 7 <NA> #000000FF
#> 9 8 <NA> #000000FF
#> 10 9 <NA> #000000FF
#> # … with 246 more rowsThis package is a product of SKOPE (Synthesizing Knowledge of Past Environments) and the Village Ecodynamics Project through grants awarded to the Crow Canyon Archaeological Center and Washington State University by the National Science Foundation. This software is licensed under the MIT license. Continuing development is supported by the Montana Climate Office.
FedData was reviewed for rOpenSci by @jooolia, and was greatly improved as a result. rOpenSci on-boarding was coordinated by @sckott.