readWQP | R Documentation |
This function extracts water quality data from EPA's Water Quality Portal based on user argument inputs. Note that connections to the WQP occassionally time out during download. This function tries to download requested files up to 10 times before exiting. All arguments except type are optional, but at least one should be provided to limit download size and prevent errors connecting to WQP. Note that some, but not all, special characters in characteristic names have been accounted for. If in doubt, use the WQP web interface to determine the appropriate sytax for odd characteristic names. This function coerces non-numeric values in ResultMeasureValue column (for result & narrowresult type queries). This may generate NA values with a warning for special characters.
readWQP(
type = "result",
...,
print = FALSE,
coerce_num = FALSE,
url_only = FALSE,
auid = NULL
)
type |
Data type to read. One of "result", "narrowresult", "sites", "activity", "detquantlim", or "project". |
... |
additional arguments to be passed to WQP query path. See https://www.waterqualitydata.us/portal/ for optional arguments. |
print |
Logical. Print summary table of sites & characteristics (only for result or narrowresult types). |
coerce_num |
Logical. If TRUE the ResultMeasureValue column in result and narrowresult type reads is coerced to numeric values. This will generate NAs in the ResultMeasureValue column for non-numeric values. Defaults to FALSE. |
url_only |
Logical. If FALSE (default) read and return data. If TRUE, return just the query url. |
auid |
Optional. A vector of Utah DWQ assessment unit identifiers for which to query data. Note that siteid is ignored if auid is specified. |
start_date |
Query start date in "mm/dd/yyyy" format. |
end_date |
Query end date in "mm/dd/yyyy" format. |
A data frame of WQP data
# Read some data from Mantua Reservoir (2016-2018)
nr=readWQP(type="narrowresult", siteid=c("UTAHDWQ_WQX-4900440","UTAHDWQ_WQX-4900460"),
start_date="01/01/2016", end_date="12/31/2018")
# Read just Arsenic, Cadmium, and DO, all dates
nr=readWQP(type="narrowresult",
siteid=c("UTAHDWQ_WQX-4900440","UTAHDWQ_WQX-4900460"),
characteristicName=c("Arsenic","Cadmium","Dissolved oxygen (DO)"))
# Read all Total dissolved solids statewide (2016-2018) (& note statecode for Utah)
tds_sw=readWQP(type="result",
statecode="US:49",
characteristicName="Total dissolved solids",
start_date="01/01/2016", end_date="12/31/2018",
print=F)
# Read data by assessment unit identifiers
utah_lake_nr=readWQP(type="narrowresult",
auid=c('UT-L-16020201-004_01', 'UT-L-16020201-004_02'),
start_date="01/01/2016", end_date="12/31/2018",
siteType=c("Lake, Reservoir, Impoundment","Stream"),
print=F)
utah_lake_sites=readWQP(type="sites",
auid=c('UT-L-16020201-004_01', 'UT-L-16020201-004_02'),
siteType=c("Lake, Reservoir, Impoundment","Stream"),
print=F)
buildMap(sites=utah_lake_sites)
# Read DWQ's sites
sites=readWQP(type="sites", statecode="US:49", organization="UTAHDWQ_WQX", siteType=c("Lake, Reservoir, Impoundment","Stream"))
plot(LatitudeMeasure~LongitudeMeasure, sites[sites$LatitudeMeasure>0 & sites$LongitudeMeasure<0,])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.