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
4bc24ebd
Commit
4bc24ebd
authored
Sep 07, 2021
by
Laura A DeCicco
Browse files
Fail more gracefully...
parent
f62b51b5
Changes
14
Hide whitespace changes
Inline
Side-by-side
R/findNLDI.R
View file @
4bc24ebd
...
@@ -230,12 +230,13 @@ valid_ask = function(all, type) {
...
@@ -230,12 +230,13 @@ valid_ask = function(all, type) {
#' # Find Features / Define origin features
#' # Find Features / Define origin features
#'
#'
#' ## Find feature by COMID
#' ## Find feature by COMID
#' if(!httr::http_error("https://labs.waterdata.usgs.gov/api/nldi/linked-data")){
#' findNLDI(comid = 101)
#' findNLDI(comid = 101)
#'
#'
#' ## Find feature by NWIS ID
#' ## Find feature by NWIS ID
#' findNLDI(nwis = '11120000')
#'
findNLDI(nwis = '11120000')
#'
#'
#' ## Find feature by WQP ID
#' ## Find feature by WQP ID
#' findNLDI(wqp = 'USGS-04024315')
#' findNLDI(wqp = 'USGS-04024315')
#'
#'
#' ## Find feature by LOCATION
#' ## Find feature by LOCATION
...
@@ -267,6 +268,7 @@ valid_ask = function(all, type) {
...
@@ -267,6 +268,7 @@ valid_ask = function(all, type) {
#' ## Limit search to 50 km
#' ## Limit search to 50 km
#' findNLDI(comid = 101, nav = "DM", find = c("nwis", "wqp", "flowlines"), distance_km = 50)
#' findNLDI(comid = 101, nav = "DM", find = c("nwis", "wqp", "flowlines"), distance_km = 50)
#'}
#'}
#'}
findNLDI
<-
function
(
comid
=
NULL
,
findNLDI
<-
function
(
comid
=
NULL
,
nwis
=
NULL
,
nwis
=
NULL
,
wqp
=
NULL
,
wqp
=
NULL
,
...
...
R/getWebServiceData.R
View file @
4bc24ebd
...
@@ -18,7 +18,9 @@
...
@@ -18,7 +18,9 @@
#' property <- '00060'
#' property <- '00060'
#' obs_url <- constructNWISURL(siteNumber,property,startDate,endDate,'dv')
#' obs_url <- constructNWISURL(siteNumber,property,startDate,endDate,'dv')
#' \donttest{
#' \donttest{
#' rawData <- getWebServiceData(obs_url)
#' if(!httr::http_error(obs_url)){
#' rawData <- getWebServiceData(obs_url)
#' }
#' }
#' }
getWebServiceData
<-
function
(
obs_url
,
...
){
getWebServiceData
<-
function
(
obs_url
,
...
){
...
...
R/importNGWMN_wml2.R
View file @
4bc24ebd
...
@@ -25,8 +25,9 @@
...
@@ -25,8 +25,9 @@
#' "observedProperty=urn:ogc:def:property:OGC:GroundWaterLevel",
#' "observedProperty=urn:ogc:def:property:OGC:GroundWaterLevel",
#' "responseFormat=text/xml",
#' "responseFormat=text/xml",
#' "featureOfInterest=VW_GWDP_GEOSERVER.USGS.403836085374401",sep="&")
#' "featureOfInterest=VW_GWDP_GEOSERVER.USGS.403836085374401",sep="&")
#' data <- importNGWMN(obs_url)
#' if(!httr::http_error(obs_url)){
#'
#' data_returned <- importNGWMN(obs_url)
#' }
#' }
#' }
#'
#'
importNGWMN
<-
function
(
input
,
asDateTime
=
FALSE
,
tz
=
"UTC"
){
importNGWMN
<-
function
(
input
,
asDateTime
=
FALSE
,
tz
=
"UTC"
){
...
@@ -141,8 +142,10 @@ importNGWMN <- function(input, asDateTime=FALSE, tz="UTC"){
...
@@ -141,8 +142,10 @@ importNGWMN <- function(input, asDateTime=FALSE, tz="UTC"){
#' "statCd=00003",
#' "statCd=00003",
#' "parameterCd=00060",sep="&")
#' "parameterCd=00060",sep="&")
#' \donttest{
#' \donttest{
#' timesereies <- importWaterML2(URL, asDateTime=TRUE, tz="UTC")
#' if(!httr::http_error(URL)){
#' timesereies <- importWaterML2(URL, asDateTime=TRUE, tz="UTC")
#' }
#' }
#' }
importWaterML2
<-
function
(
input
,
asDateTime
=
FALSE
,
tz
=
"UTC"
)
{
importWaterML2
<-
function
(
input
,
asDateTime
=
FALSE
,
tz
=
"UTC"
)
{
returnedDoc
<-
check_if_xml
(
input
)
returnedDoc
<-
check_if_xml
(
input
)
...
...
R/importRDB1.r
View file @
4bc24ebd
...
@@ -52,24 +52,34 @@
...
@@ -52,24 +52,34 @@
#' obs_url <- constructNWISURL(site_id,property,
#' obs_url <- constructNWISURL(site_id,property,
#' startDate,endDate,"dv",format="tsv")
#' startDate,endDate,"dv",format="tsv")
#' \donttest{
#' \donttest{
#' data <- importRDB1(obs_url)
#' if(!httr::http_error(obs_url)){
#' data <- importRDB1(obs_url)
#' }
#'
#'
#' urlMultiPcodes <- constructNWISURL("04085427",c("00060","00010"),
#' urlMultiPcodes <- constructNWISURL("04085427",c("00060","00010"),
#' startDate,endDate,"dv",statCd=c("00003","00001"),"tsv")
#' startDate,endDate,"dv",statCd=c("00003","00001"),"tsv")
#' multiData <- importRDB1(urlMultiPcodes)
#' if(!httr::http_error(urlMultiPcodes)){
#' multiData <- importRDB1(urlMultiPcodes)
#' }
#' unitDataURL <- constructNWISURL(site_id,property,
#' unitDataURL <- constructNWISURL(site_id,property,
#' "2020-10-30","2020-11-01","uv",format="tsv") #includes timezone switch
#' "2020-10-30","2020-11-01","uv",format="tsv") #includes timezone switch
#' unitData <- importRDB1(unitDataURL, asDateTime=TRUE)
#' if(!httr::http_error(unitDataURL)){
#' unitData <- importRDB1(unitDataURL, asDateTime=TRUE)
#' }
#' qwURL <- constructNWISURL(c('04024430','04024000'),
#' qwURL <- constructNWISURL(c('04024430','04024000'),
#' c('34247','30234','32104','34220'),
#' c('34247','30234','32104','34220'),
#' "2010-11-03","","qw",format="rdb")
#' "2010-11-03","","qw",format="rdb")
#' qwData <- importRDB1(qwURL, asDateTime=TRUE, tz="America/Chicago")
#' if(!httr::http_error(qwURL)){
#' qwData <- importRDB1(qwURL, asDateTime=TRUE, tz="America/Chicago")
#' }
#' iceSite <- '04024000'
#' iceSite <- '04024000'
#' start <- "2015-11-09"
#' start <- "2015-11-09"
#' end <- "2015-11-24"
#' end <- "2015-11-24"
#' urlIce <- constructNWISURL(iceSite,"00060",start, end,"uv",format="tsv")
#' urlIce <- constructNWISURL(iceSite,"00060",start, end,"uv",format="tsv")
#' ice <- importRDB1(urlIce, asDateTime=TRUE)
#' if(!httr::http_error(urlIce)){
#' iceNoConvert <- importRDB1(urlIce, convertType=FALSE)
#' ice <- importRDB1(urlIce, asDateTime=TRUE)
#' iceNoConvert <- importRDB1(urlIce, convertType=FALSE)
#' }
#' }
#' }
#' # User file:
#' # User file:
#' filePath <- system.file("extdata", package="dataRetrieval")
#' filePath <- system.file("extdata", package="dataRetrieval")
...
...
R/importWQP.R
View file @
4bc24ebd
...
@@ -22,13 +22,19 @@
...
@@ -22,13 +22,19 @@
#' \donttest{
#' \donttest{
#' rawSampleURL <- constructWQPURL('USGS-01594440','01075', '', '')
#' rawSampleURL <- constructWQPURL('USGS-01594440','01075', '', '')
#'
#'
#' rawSample <- importWQP(rawSampleURL)
#' if(!httr::http_error(rawSampleURL)){
#' rawSample <- importWQP(rawSampleURL)
#' }
#'
#'
#' rawSampleURL_NoZip <- constructWQPURL('USGS-01594440','01075', '', '', zip=FALSE)
#' rawSampleURL_NoZip <- constructWQPURL('USGS-01594440','01075', '', '', zip=FALSE)
#' rawSample2 <- importWQP(rawSampleURL_NoZip, zip=FALSE)
#' if(!httr::http_error(rawSampleURL_NoZip)){
#'
#' rawSample2 <- importWQP(rawSampleURL_NoZip, zip=FALSE)
#' }
#' #'
#' STORETex <- constructWQPURL('WIDNR_WQX-10032762','Specific conductance', '', '')
#' STORETex <- constructWQPURL('WIDNR_WQX-10032762','Specific conductance', '', '')
#' STORETdata <- importWQP(STORETex)
#' if(!httr::http_error(STORETex)){
#' STORETdata <- importWQP(STORETex)
#' }
#' }
#' }
importWQP
<-
function
(
obs_url
,
zip
=
TRUE
,
tz
=
"UTC"
,
importWQP
<-
function
(
obs_url
,
zip
=
TRUE
,
tz
=
"UTC"
,
csv
=
FALSE
){
csv
=
FALSE
){
...
...
R/importWaterML1.r
View file @
4bc24ebd
...
@@ -115,7 +115,7 @@ importWaterML1 <- function(obs_url,asDateTime=FALSE, tz="UTC"){
...
@@ -115,7 +115,7 @@ importWaterML1 <- function(obs_url,asDateTime=FALSE, tz="UTC"){
timeSeries
<-
xml_find_all
(
returnedDoc
,
".//ns1:timeSeries"
)
#each parameter/site combo
timeSeries
<-
xml_find_all
(
returnedDoc
,
".//ns1:timeSeries"
)
#each parameter/site combo
#some intial attributes
#some in
i
tial attributes
queryNodes
<-
xml_children
(
xml_find_all
(
returnedDoc
,
".//ns1:queryInfo"
))
queryNodes
<-
xml_children
(
xml_find_all
(
returnedDoc
,
".//ns1:queryInfo"
))
notes
<-
queryNodes
[
xml_name
(
queryNodes
)
==
"note"
]
notes
<-
queryNodes
[
xml_name
(
queryNodes
)
==
"note"
]
noteTitles
<-
xml_attrs
(
notes
)
noteTitles
<-
xml_attrs
(
notes
)
...
@@ -124,7 +124,10 @@ importWaterML1 <- function(obs_url,asDateTime=FALSE, tz="UTC"){
...
@@ -124,7 +124,10 @@ importWaterML1 <- function(obs_url,asDateTime=FALSE, tz="UTC"){
names
(
noteList
)
<-
noteTitles
names
(
noteList
)
<-
noteTitles
if
(
0
==
length
(
timeSeries
)){
if
(
0
==
length
(
timeSeries
)){
df
<-
data.frame
()
df
<-
data.frame
(
agency_cd
=
character
(),
site_no
=
character
(),
dateTime
=
as.POSIXct
(
character
()),
tz_cd
=
character
())
attr
(
df
,
"queryInfo"
)
<-
noteList
attr
(
df
,
"queryInfo"
)
<-
noteList
if
(
!
raw
){
if
(
!
raw
){
attr
(
df
,
"url"
)
<-
obs_url
attr
(
df
,
"url"
)
<-
obs_url
...
...
R/readNGWMNdata.R
View file @
4bc24ebd
...
@@ -153,13 +153,17 @@ readNGWMNlevels <- function(siteNumbers, asDateTime = TRUE, tz = "UTC"){
...
@@ -153,13 +153,17 @@ readNGWMNlevels <- function(siteNumbers, asDateTime = TRUE, tz = "UTC"){
#' @examples
#' @examples
#' \donttest{
#' \donttest{
#' #one site
#' #one site
#' site <- "USGS.430427089284901"
#' if(!httr::http_error("https://cida.usgs.gov/ngwmn_cache")){
#' oneSite <- readNGWMNsites(siteNumbers = site)
#' site <- "USGS.430427089284901"
#' oneSite <- readNGWMNsites(siteNumbers = site)
#' }
#'
#'
#'
#' #non-USGS site
#' #non-USGS site
#' site <- "MBMG.103306"
#' if(!httr::http_error("https://cida.usgs.gov/ngwmn_cache")){
#' siteInfo <- readNGWMNsites(siteNumbers = site)
#' site <- "MBMG.103306"
#'
#' siteInfo <- readNGWMNsites(siteNumbers = site)
#' }
#' }
#' }
readNGWMNsites
<-
function
(
siteNumbers
){
readNGWMNsites
<-
function
(
siteNumbers
){
sites
<-
readNGWMNdata
(
siteNumbers
=
siteNumbers
,
service
=
"featureOfInterest"
)
sites
<-
readNGWMNdata
(
siteNumbers
=
siteNumbers
,
service
=
"featureOfInterest"
)
...
...
man/findNLDI.Rd
View file @
4bc24ebd
...
@@ -69,12 +69,13 @@ arguments: comid, nwis, huc12, wqp, location, and start.
...
@@ -69,12 +69,13 @@ arguments: comid, nwis, huc12, wqp, location, and start.
# Find Features / Define origin features
# Find Features / Define origin features
## Find feature by COMID
## Find feature by COMID
if(!httr::http_error("https://labs.waterdata.usgs.gov/api/nldi/linked-data")){
findNLDI(comid = 101)
findNLDI(comid = 101)
## Find feature by NWIS ID
## Find feature by NWIS ID
findNLDI(nwis = '11120000')
findNLDI(nwis = '11120000')
## Find feature by WQP ID
## Find feature by WQP ID
findNLDI(wqp = 'USGS-04024315')
findNLDI(wqp = 'USGS-04024315')
## Find feature by LOCATION
## Find feature by LOCATION
...
@@ -107,4 +108,5 @@ arguments: comid, nwis, huc12, wqp, location, and start.
...
@@ -107,4 +108,5 @@ arguments: comid, nwis, huc12, wqp, location, and start.
findNLDI(comid = 101, nav = "DM", find = c("nwis", "wqp", "flowlines"), distance_km = 50)
findNLDI(comid = 101, nav = "DM", find = c("nwis", "wqp", "flowlines"), distance_km = 50)
}
}
}
}
}
\keyword{nldi}
\keyword{nldi}
man/getWebServiceData.Rd
View file @
4bc24ebd
...
@@ -26,6 +26,8 @@ offering <- '00003'
...
@@ -26,6 +26,8 @@ offering <- '00003'
property <- '00060'
property <- '00060'
obs_url <- constructNWISURL(siteNumber,property,startDate,endDate,'dv')
obs_url <- constructNWISURL(siteNumber,property,startDate,endDate,'dv')
\donttest{
\donttest{
rawData <- getWebServiceData(obs_url)
if(!httr::http_error(obs_url)){
rawData <- getWebServiceData(obs_url)
}
}
}
}
}
man/importNGWMN.Rd
View file @
4bc24ebd
...
@@ -32,8 +32,9 @@ obs_url <- paste("https://cida.usgs.gov/ngwmn_cache/sos?request=GetObservation",
...
@@ -32,8 +32,9 @@ obs_url <- paste("https://cida.usgs.gov/ngwmn_cache/sos?request=GetObservation",
"observedProperty=urn:ogc:def:property:OGC:GroundWaterLevel",
"observedProperty=urn:ogc:def:property:OGC:GroundWaterLevel",
"responseFormat=text/xml",
"responseFormat=text/xml",
"featureOfInterest=VW_GWDP_GEOSERVER.USGS.403836085374401",sep="&")
"featureOfInterest=VW_GWDP_GEOSERVER.USGS.403836085374401",sep="&")
data <- importNGWMN(obs_url)
if(!httr::http_error(obs_url)){
data_returned <- importNGWMN(obs_url)
}
}
}
}
}
man/importRDB1.Rd
View file @
4bc24ebd
...
@@ -64,24 +64,34 @@ property <- "00060"
...
@@ -64,24 +64,34 @@ property <- "00060"
obs_url <- constructNWISURL(site_id,property,
obs_url <- constructNWISURL(site_id,property,
startDate,endDate,"dv",format="tsv")
startDate,endDate,"dv",format="tsv")
\donttest{
\donttest{
data <- importRDB1(obs_url)
if(!httr::http_error(obs_url)){
data <- importRDB1(obs_url)
}
urlMultiPcodes <- constructNWISURL("04085427",c("00060","00010"),
urlMultiPcodes <- constructNWISURL("04085427",c("00060","00010"),
startDate,endDate,"dv",statCd=c("00003","00001"),"tsv")
startDate,endDate,"dv",statCd=c("00003","00001"),"tsv")
multiData <- importRDB1(urlMultiPcodes)
if(!httr::http_error(urlMultiPcodes)){
multiData <- importRDB1(urlMultiPcodes)
}
unitDataURL <- constructNWISURL(site_id,property,
unitDataURL <- constructNWISURL(site_id,property,
"2020-10-30","2020-11-01","uv",format="tsv") #includes timezone switch
"2020-10-30","2020-11-01","uv",format="tsv") #includes timezone switch
unitData <- importRDB1(unitDataURL, asDateTime=TRUE)
if(!httr::http_error(unitDataURL)){
unitData <- importRDB1(unitDataURL, asDateTime=TRUE)
}
qwURL <- constructNWISURL(c('04024430','04024000'),
qwURL <- constructNWISURL(c('04024430','04024000'),
c('34247','30234','32104','34220'),
c('34247','30234','32104','34220'),
"2010-11-03","","qw",format="rdb")
"2010-11-03","","qw",format="rdb")
qwData <- importRDB1(qwURL, asDateTime=TRUE, tz="America/Chicago")
if(!httr::http_error(qwURL)){
qwData <- importRDB1(qwURL, asDateTime=TRUE, tz="America/Chicago")
}
iceSite <- '04024000'
iceSite <- '04024000'
start <- "2015-11-09"
start <- "2015-11-09"
end <- "2015-11-24"
end <- "2015-11-24"
urlIce <- constructNWISURL(iceSite,"00060",start, end,"uv",format="tsv")
urlIce <- constructNWISURL(iceSite,"00060",start, end,"uv",format="tsv")
ice <- importRDB1(urlIce, asDateTime=TRUE)
if(!httr::http_error(urlIce)){
iceNoConvert <- importRDB1(urlIce, convertType=FALSE)
ice <- importRDB1(urlIce, asDateTime=TRUE)
iceNoConvert <- importRDB1(urlIce, convertType=FALSE)
}
}
}
# User file:
# User file:
filePath <- system.file("extdata", package="dataRetrieval")
filePath <- system.file("extdata", package="dataRetrieval")
...
...
man/importWQP.Rd
View file @
4bc24ebd
...
@@ -32,13 +32,19 @@ Imports data from the Water Quality Portal based on a specified url.
...
@@ -32,13 +32,19 @@ Imports data from the Water Quality Portal based on a specified url.
\donttest{
\donttest{
rawSampleURL <- constructWQPURL('USGS-01594440','01075', '', '')
rawSampleURL <- constructWQPURL('USGS-01594440','01075', '', '')
rawSample <- importWQP(rawSampleURL)
if(!httr::http_error(rawSampleURL)){
rawSample <- importWQP(rawSampleURL)
}
rawSampleURL_NoZip <- constructWQPURL('USGS-01594440','01075', '', '', zip=FALSE)
rawSampleURL_NoZip <- constructWQPURL('USGS-01594440','01075', '', '', zip=FALSE)
rawSample2 <- importWQP(rawSampleURL_NoZip, zip=FALSE)
if(!httr::http_error(rawSampleURL_NoZip)){
rawSample2 <- importWQP(rawSampleURL_NoZip, zip=FALSE)
}
#'
STORETex <- constructWQPURL('WIDNR_WQX-10032762','Specific conductance', '', '')
STORETex <- constructWQPURL('WIDNR_WQX-10032762','Specific conductance', '', '')
STORETdata <- importWQP(STORETex)
if(!httr::http_error(STORETex)){
STORETdata <- importWQP(STORETex)
}
}
}
}
}
\seealso{
\seealso{
...
...
man/importWaterML2.Rd
View file @
4bc24ebd
...
@@ -28,6 +28,8 @@ URL <- paste(baseURL, "sites=01646500",
...
@@ -28,6 +28,8 @@ URL <- paste(baseURL, "sites=01646500",
"statCd=00003",
"statCd=00003",
"parameterCd=00060",sep="&")
"parameterCd=00060",sep="&")
\donttest{
\donttest{
timesereies <- importWaterML2(URL, asDateTime=TRUE, tz="UTC")
if(!httr::http_error(URL)){
timesereies <- importWaterML2(URL, asDateTime=TRUE, tz="UTC")
}
}
}
}
}
man/readNGWMNsites.Rd
View file @
4bc24ebd
...
@@ -25,12 +25,16 @@ Retrieve site data from the National Ground Water Monitoring Network \url{https:
...
@@ -25,12 +25,16 @@ Retrieve site data from the National Ground Water Monitoring Network \url{https:
\examples{
\examples{
\donttest{
\donttest{
#one site
#one site
site <- "USGS.430427089284901"
if(!httr::http_error("https://cida.usgs.gov/ngwmn_cache")){
oneSite <- readNGWMNsites(siteNumbers = site)
site <- "USGS.430427089284901"
oneSite <- readNGWMNsites(siteNumbers = site)
}
#non-USGS site
#non-USGS site
site <- "MBMG.103306"
if(!httr::http_error("https://cida.usgs.gov/ngwmn_cache")){
siteInfo <- readNGWMNsites(siteNumbers = site)
site <- "MBMG.103306"
siteInfo <- readNGWMNsites(siteNumbers = site)
}
}
}
}
}
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