Learn R Programming

⚠️There's a newer version (4.3.0) of this package.Take me there.

FedData

FedData is an R package implementing functions to automate downloading geospatial data available from several federated data sources (mainly sources maintained by the US Federal government). Currently, the package allows for retrieval of five datasets:

Additional data sources are in the works, including global DEM resources (ETOPO1, STRM), global soils (HWSD), MODIS satellite data products, the National Atlas (US only), Natural Earth, PRISM, and WorldClim.

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 sp, raster, and rgdal packages.

This package has been built and tested on a source (Homebrew) install of R on Mac OS 10.11 (El Capitan), and has been successfully run on an Ubuntu Linux cluster, and binary installs of R on Mac OS 10.11 and Windows 7.

Development

Contributors

Install FedData

  • CRAN:
install.packages('FedData')
  • Development version from GitHub:
install.packages("devtools")
library(devtools)
install_github("bocinsky/FedData")
library(FedData)

Some OS X systems have trouble installing the rgdal package from source. If your install fails, and you've installed the Homebrew version of GDAL and R, try the following command (from within R):

install.packages("rgdal", configure.args="--with-proj-include=/usr/local/include --with-proj-lib=/usr/local/lib")

# Then try the FedData install again
install.packages('FedData')

Demonstration

This demo script is available in the /inst folder at the location of the installed package.

Load FedData and define a study area

# Load FedData
library(FedData)

# Set a directory for testing
testDir <- "~/FedData Test"
# and create it if necessary
dir.create(testDir, showWarnings=F, recursive=T)
setwd(testDir)

# Extract data for the Village Ecodynamics Project "VEPIIN" study area:
# http://village.anth.wsu.edu
vepPolygon <- polygon_from_extent(raster::extent(672800,740000,4102000,4170000),
                                  proj4string="+proj=utm +datum=NAD83 +zone=12")

Get and plot the National Elevation Dataset for the study area

# Get the NED (USA ONLY)
# Returns a raster object
NED <- get_ned(template=vepPolygon,
               label="VEPIIN")

# Plot with raster::plot
raster::plot(NED)

Get and plot the daily GHCN precipitation data for the study area

# 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=vepPolygon, 
                            label="VEPIIN",
                            elements=c('prcp'))
# Plot the spatial locations of stations with precipitation data
plot(GHCN.prcp$spatial, pch=1, add=T)
legend('bottomleft', pch=1, legend="GHCN Precipitation Records")

Get and plot the daily GHCN temperature data for the study area

# Elements for which you require the same data
# (i.e., minimum and maximum temperature for the same days)
# can be standardized using standardize==T
# which ensures that stations have both tmin and tmax data
GHCN.temp <- get_ghcn_daily(template=vepPolygon, 
                            label="VEPIIN", 
                            elements=c('tmin','tmax'), 
                            standardize=T)
# Plot the NED again
raster::plot(NED)
# Plot the spatial locations
plot(GHCN.temp$spatial, add=T, pch=1)
legend('bottomleft', pch=1, legend="GHCN Temperature Records")

Get and plot the National Hydrography Dataset for the study area

# Get the NHD (USA ONLY)
NHD <- get_nhd(template=vepPolygon, 
               label="VEPIIN")
# Plot the NED again
raster::plot(NED)
# Plot the NHD data
plot(NHD$NHDFlowline, add=T)
plot(NHD$NHDLine, add=T)
plot(NHD$NHDArea, col='black', add=T)
plot(NHD$NHDWaterbody, col='black', add=T)

Get and plot the NRCS SSURGO data for the study area

# Get the NRCS SSURGO data (USA ONLY)
SSURGO.VEPIIN <- get_ssurgo(template=vepPolygon, 
                            label="VEPIIN")
# Plot the NED again
raster::plot(NED)
# Plot the SSURGO mapunit polygons
plot(SSURGO.VEPIIN$spatial,
     lwd=0.1,
     add=T)

Get and plot the NRCS SSURGO data for particular soil survey areas

# 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)

Get and plot the ITRDB chronology locations in the study area

# Get the ITRDB records
ITRDB <- get_itrdb(template=vepPolygon,
                   label="VEPIIN",
                   makeSpatial=T)
                   
# Plot the NED again
raster::plot(NED)
# Map the locations of the tree ring chronologies
plot(ITRDB$metadata, pch=1, add=T)
legend('bottomleft', pch=1, legend="ITRDB chronologies")

Acknowledgements

This package is a product of SKOPE (Synthesized Knowledge of Past Environments) and the Village Ecodynamics Project. This software is licensed under the MIT license.

Copy Link

Version

Install

install.packages('FedData')

Monthly Downloads

895

Version

2.0.8

License

MIT + file LICENSE

Maintainer

R. Bocinsky

Last Published

March 10th, 2016

Functions in FedData (2.0.8)

get_ghcn_daily_station

Download and extract the daily data for a GHCN weather station.
download_ghcn_daily_station

Download the daily data for a GHCN weather station.
get_ghcn_daily

Download and crop the Global Historical Climate Network-Daily data.
download_ned_tile

Download a zipped tile from the 1 (~30 meter) or 1/3 (~10 meter) arc-second National Elevation Dataset.
download_ssurgo_inventory

Download a zipped directory containing a shapefile of the SSURGO study areas.
extract_ssurgo_data

Extract data from a SSURGO databse pertaining to a set of mapunits.
spdf_from_polygon

Turn an SpatialPolygons object into a SpatialPolygonsDataFrame.
read_crn_metadata

Read metadata from a Tucson-format chronology file.
polygon_from_extent

Turn an extent object into a polygon
station_to_data_frame

Convert a list of station data to a single data frame.
download_huc4

Download a zipped directory containing a shapefile of the HUC4 subregions of the NHD.
get_ssurgo

Download and crop data from the NRCS SSURGO soils database.
download_ssurgo_study_area

Download a zipped directory containing the spatial and tabular data for a SSURGO study area.
FedData-package

Scripts to automate downloading geospatial data available from the several federated data sources
get_huc4

Download and crop a shapefile of the HUC4 regions of the National Hydrography Dataset.
download_nhd_subregion

Download a zipped NHD HUC4 subregion.
get_ssurgo_inventory

Download and crop a shapefile of the SSURGO study areas.
unwrap_rows

Unwraps a matrix and only keep the first n elements.
get_nhd_subregion

Download and crop data from a zipped HUC4 subregion of the National Hydrography Dataset.
substr_right

Get the rightmost "n" characters of a character string.
read_crn

Read a Tucson-format chronology file.
get_ned

Download and crop the 1 (~30 meter) or 1/3 (~10 meter) arc-second National Elevation Dataset.
get_ghcn_inventory

Download and crop the inventory of GHCN stations.
get_ssurgo_study_area

Download and crop the spatial and tabular data for a SSURGO study area.
read_crn_data

Read chronology data from a Tucson-format chronology file.
sequential_duplicated

Get a logical vector of which elements in a vector are sequentially duplicated.
get_ned_tile

Download and crop tile from the 1 (~30 meter) or 1/3 (~10 meter) arc-second National Elevation Dataset.
download_data

Use curl to download a file.
download_itrdb

Download the latest version of the ITRDB.
get_nhd

Download and crop the National Hydrography Dataset.
pkg_test

Install and load a package.
get_itrdb

Download the latest version of the ITRDB, and extract given parameters.