Retrieves water use data from USGS Water Use Data for the Nation. See https://waterdata.usgs.gov/nwis/wu for more information. All available use categories for the supplied arguments are retrieved.
Usage
readNWISuse(
stateCd,
countyCd,
years = "ALL",
categories = "ALL",
convertType = TRUE,
transform = FALSE
)
Arguments
- stateCd
could be character (full name, abbreviation, id), or numeric (id). Only one is accepted per query.
- countyCd
could be character (name, with or without "County", or "ALL"), numeric (id), or
NULL
, which will return state or national data depending on the stateCd argument. "ALL" may also be supplied, which will return data for every county in a state. Can be a vector of counties in the same state.- years
integer Years for data retrieval. Must be years ending in 0 or 5. Default is all available years.
- categories
character categories of water use. Defaults to "ALL". Specific categories must be supplied as two- letter abbreviations as seen in the URL when using the NWIS water use web interface. Note that there are different codes for national and state level data.
- convertType
logical defaults to
TRUE
. IfTRUE
, the function will convert the data to numerics based on a standard algorithm. Years, months, and days (if appliccable) are also returned as numerics in separate columns. If convertType is false, everything is returned as a character.- transform
logical only intended for use with national data. Defaults to
FALSE
, with data being returned as presented by the web service. IfTRUE
, data will be transformed and returned with column names, which will reformat national data to be similar to state data.
Value
A data frame with at least the year of record, and all available statistics for the given geographic parameters. County and state fields will be included as appropriate.
Examples
# \donttest{
# All data for a county
allegheny <- readNWISuse(stateCd = "Pennsylvania", countyCd = "Allegheny")
#> GET: https://waterdata.usgs.gov/PA/nwis/water_use?format=rdb&rdb_compression=value&wu_area=county&wu_county=003&wu_year=ALL&wu_category=ALL
# Data for an entire state for certain years
ohio <- readNWISuse(years = c(2000, 2005, 2010), stateCd = "OH", countyCd = NULL)
#> GET: https://waterdata.usgs.gov/OH/nwis/water_use?format=rdb&rdb_compression=value&wu_area=State%20Total&wu_year=2000%2C2005%2C2010&wu_category=ALL
# Data for an entire state, county by county
pr <- readNWISuse(years = c(2000, 2005, 2010), stateCd = "PR", countyCd = "ALL")
#> GET: https://waterdata.usgs.gov/PR/nwis/water_use?format=rdb&rdb_compression=value&wu_area=county&wu_county=&wu_year=2000%2C2005%2C2010&wu_category=ALL
# All national-scale data, transforming data frame to named columns from named rows
national <- readNWISuse(stateCd = NULL, countyCd = NULL, transform = TRUE)
#> GET: https://waterdata.usgs.gov/nwis/water_use?format=rdb&rdb_compression=value&wu_year=ALL&wu_category=ALL
# Washington, DC data
dc <- readNWISuse(stateCd = "DC", countyCd = NULL)
#> GET: https://waterdata.usgs.gov/DC/nwis/water_use?format=rdb&rdb_compression=value&wu_area=State%20Total&wu_year=ALL&wu_category=ALL
# data for multiple counties, with different input formatting
paData <- readNWISuse(stateCd = "42", countyCd = c("Allegheny County", "BUTLER", 1, "031"))
#> GET: https://waterdata.usgs.gov/PA/nwis/water_use?format=rdb&rdb_compression=value&wu_area=county&wu_county=003%2C019%2C001%2C031&wu_year=ALL&wu_category=ALL
# retrieving two specific categories for an entire state
ks <- readNWISuse(stateCd = "KS", countyCd = NULL, categories = c("IT", "LI"))
#> GET: https://waterdata.usgs.gov/KS/nwis/water_use?format=rdb&rdb_compression=value&wu_area=State%20Total&wu_year=ALL&wu_category=IT%2CLI
# }