Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Water
dataRetrieval
Commits
14abb5b5
Commit
14abb5b5
authored
Dec 01, 2021
by
Laura A DeCicco
Browse files
Initial framework for new WQP summary function.
parent
6c5efaba
Changes
4
Hide whitespace changes
Inline
Side-by-side
NAMESPACE
View file @
14abb5b5
...
...
@@ -43,6 +43,7 @@ export(stateCdLookup)
export(whatNWISdata)
export(whatNWISsites)
export(whatWQPdata)
export(whatWQPdata2)
export(whatWQPmetrics)
export(whatWQPsamples)
export(whatWQPsites)
...
...
R/whatWQPdata2.R
0 → 100644
View file @
14abb5b5
#' Data Available from Water Quality Portal
#'
#' Returns a list of sites from the Water Quality Portal web service. This
#' function gets the data from: \url{https://www.waterqualitydata.us}.
#' Arguments to the function should be based on
#' \url{https://www.waterqualitydata.us/webservices_documentation}.
#' The information returned from this function describes the
#' available data at the WQP sites, and some metadata on the sites themselves.
#'
#' @param \dots see \url{https://www.waterqualitydata.us/webservices_documentation}
#' for a complete list of options. A list of arguments can also be supplied.
#' @return A data frame with at least the following columns:
#' \tabular{lll}{
#' Name \tab Type \tab Description \cr
#' "Provider" \tab character \tab Providing database. \cr
#' "MonitoringLocationIdentifier" \tab character \tab A designator used to
#' describe the unique name, number, or code assigned to identify
#' the monitoring location.\cr
#' "YearSummarized" \tab numeric \tab The year of the summary \cr
#' "CharacteristicType" \tab character \tab CharacteristicType \cr
#' "CharacteristicName" \tab character \tab The object, property, or substance
#' which is evaluated or enumerated by either a direct field measurement,
#' a direct field observation, or by laboratory analysis of material
#' collected in the field.\cr
#' "ActivityCount" \tab numeric \tab The number of times the location was sampled \cr
#' "ResultCount" \tab numeric \tab The number of individual data results. \cr
#' "LastResultSubmittedDate" \tab Date \tab Date when data was last submitted. \cr
#' "OrganizationIdentifier" \tab character \tab A designator used to uniquely
#' identify a unique business establishment within a context.\cr
#' "OrganizationFormalName" \tab character \tab The legal designator
#' (i.e. formal name) of an organization.\cr
#' "MonitoringLocationName \tab character \tab MonitoringLocationName \cr
#' "MonitoringLocationTypeName" \tab character \tab MonitoringLocationTypeName \cr
#' "ResolvedMonitoringLocationTypeName" \tab character \tab \cr
#' "HUCEightDigitCode" \tab character \tab 8-digit HUC id. \cr
#' "MonitoringLocationUrl" \tab character \tab URL to monitoring location. \cr
#' "CountyName" \tab character \tab County of sampling location. \cr
#' "StateName" \tab character \tab State of sampling location. \cr
#' "MonitoringLocationLatitude" \tab numeric \tab latitude of sampling
#' location. \cr
#' "MonitoringLocationLongitude" \tab numeric \tab longitude of sampling
#' location. \cr
#' }
#' @export
#' @examplesIf is_dataRetrieval_user()
#' \donttest{
#' dane_county_data <- whatWQPdata2(countycode = "US:55:025",
#' summaryYears = 5,
#' siteType = "Stream")
#'
#'
#' lake_sites <- whatWQPdata2(siteType = "Lake, Reservoir, Impoundment",
#' CharacteristicName = "Temperature, water",
#' countycode = "US:55:025")
#' # Compare with the the results of whatWQPdata:
#' lake_sites2 <- whatWQPdata(siteType = "Lake, Reservoir, Impoundment",
#' CharacteristicName = "Temperature, water",
#' countycode = "US:55:025")
#'
#' }
whatWQPdata2
<-
function
(
...
){
values
<-
readWQPdots
(
...
,
zip
=
"no"
)
values
<-
values
$
values
if
(
"service"
%in%
names
(
values
)){
values
<-
values
[
!
(
names
(
values
)
%in%
"service"
)]
}
if
(
!
"dataProfile"
%in%
names
(
values
)){
values
[[
"dataProfile"
]]
<-
"periodOfRecord"
}
if
(
"CharacteristicName"
%in%
names
(
values
)){
CharacteristicName
<-
values
[[
"CharacteristicName"
]]
values
<-
values
[
names
(
values
)
!=
"CharacteristicName"
]
}
else
{
CharacteristicName
<-
"all"
}
values
<-
sapply
(
values
,
function
(
x
)
URLencode
(
x
,
reserved
=
TRUE
))
baseURL
<-
drURL
(
"SiteSummary"
,
arg.list
=
values
)
baseURL
<-
appendDrURL
(
baseURL
,
mimeType
=
"csv"
)
withCallingHandlers
({
retval
<-
importWQP
(
baseURL
,
zip
=
FALSE
,
csv
=
TRUE
)
},
warning
=
function
(
w
)
{
if
(
any
(
grepl
(
"Number of rows returned not matched in header"
,
w
)))
invokeRestart
(
"muffleWarning"
)
})
if
(
!
(
"all"
%in%
CharacteristicName
)){
retval
<-
retval
[
retval
$
CharacteristicName
%in%
CharacteristicName
,]
}
attr
(
retval
,
"queryTime"
)
<-
Sys.time
()
attr
(
retval
,
"url"
)
<-
baseURL
return
(
retval
)
}
man/whatWQPdata2.Rd
0 → 100644
View file @
14abb5b5
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/whatWQPdata2.R
\name{whatWQPdata2}
\alias{whatWQPdata2}
\title{Data Available from Water Quality Portal}
\usage{
whatWQPdata2(...)
}
\arguments{
\item{\dots}{see \url{https://www.waterqualitydata.us/webservices_documentation}
for a complete list of options. A list of arguments can also be supplied.}
}
\value{
A data frame with at least the following columns:
\tabular{lll}{
Name \tab Type \tab Description \cr
"Provider" \tab character \tab Providing database. \cr
"MonitoringLocationIdentifier" \tab character \tab A designator used to
describe the unique name, number, or code assigned to identify
the monitoring location.\cr
"YearSummarized" \tab numeric \tab The year of the summary \cr
"CharacteristicType" \tab character \tab CharacteristicType \cr
"CharacteristicName" \tab character \tab The object, property, or substance
which is evaluated or enumerated by either a direct field measurement,
a direct field observation, or by laboratory analysis of material
collected in the field.\cr
"ActivityCount" \tab numeric \tab The number of times the location was sampled \cr
"ResultCount" \tab numeric \tab The number of individual data results. \cr
"LastResultSubmittedDate" \tab Date \tab Date when data was last submitted. \cr
"OrganizationIdentifier" \tab character \tab A designator used to uniquely
identify a unique business establishment within a context.\cr
"OrganizationFormalName" \tab character \tab The legal designator
(i.e. formal name) of an organization.\cr
"MonitoringLocationName \tab character \tab MonitoringLocationName \cr
"MonitoringLocationTypeName" \tab character \tab MonitoringLocationTypeName \cr
"ResolvedMonitoringLocationTypeName" \tab character \tab \cr
"HUCEightDigitCode" \tab character \tab 8-digit HUC id. \cr
"MonitoringLocationUrl" \tab character \tab URL to monitoring location. \cr
"CountyName" \tab character \tab County of sampling location. \cr
"StateName" \tab character \tab State of sampling location. \cr
"MonitoringLocationLatitude" \tab numeric \tab latitude of sampling
location. \cr
"MonitoringLocationLongitude" \tab numeric \tab longitude of sampling
location. \cr
}
}
\description{
Returns a list of sites from the Water Quality Portal web service. This
function gets the data from: \url{https://www.waterqualitydata.us}.
Arguments to the function should be based on
\url{https://www.waterqualitydata.us/webservices_documentation}.
The information returned from this function describes the
available data at the WQP sites, and some metadata on the sites themselves.
}
\examples{
\dontshow{if (is_dataRetrieval_user()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}
\donttest{
dane_county_data <- whatWQPdata2(countycode = "US:55:025",
summaryYears = 5,
siteType = "Stream")
lake_sites <- whatWQPdata2(siteType = "Lake, Reservoir, Impoundment",
CharacteristicName = "Temperature, water",
countycode = "US:55:025")
# Compare with the the results of whatWQPdata:
lake_sites2 <- whatWQPdata(siteType = "Lake, Reservoir, Impoundment",
CharacteristicName = "Temperature, water",
countycode = "US:55:025")
}
\dontshow{\}) # examplesIf}
}
tests/testthat/tests_general.R
View file @
14abb5b5
...
...
@@ -418,3 +418,41 @@ test_that("internal functions",{
})
test_that
(
"whatWQPdata2"
,
{
testthat
::
skip_on_cran
()
dane_county_data
<-
whatWQPdata2
(
countycode
=
"US:55:025"
,
summaryYears
=
5
,
siteType
=
"Stream"
)
summary_names
<-
c
(
"Provider"
,
"MonitoringLocationIdentifier"
,
"YearSummarized"
,
"CharacteristicType"
,
"CharacteristicName"
,
"ActivityCount"
,
"ResultCount"
,
"LastResultSubmittedDate"
,
"OrganizationIdentifier"
,
"OrganizationFormalName"
,
"MonitoringLocationName"
,
"MonitoringLocationTypeName"
,
"ResolvedMonitoringLocationTypeName"
,
"HUCEightDigitCode"
,
"MonitoringLocationUrl"
,
"CountyName"
,
"StateName"
,
"MonitoringLocationLatitude"
,
"MonitoringLocationLongitude"
)
expect_true
(
all
(
summary_names
%in%
names
(
dane_county_data
)))
expect_true
(
diff
(
range
(
dane_county_data
$
YearSummarized
))
<=
5
)
lake_sites
<-
whatWQPdata2
(
siteType
=
"Lake, Reservoir, Impoundment"
,
CharacteristicName
=
"Temperature, water"
,
countycode
=
"US:55:025"
)
expect_true
(
all
(
summary_names
%in%
names
(
lake_sites
)))
expect_true
(
diff
(
range
(
lake_sites
$
YearSummarized
))
>=
5
)
})
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment