Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
dataRetrieval
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Water
dataRetrieval
Commits
faeffcbf
Commit
faeffcbf
authored
10 years ago
by
Laura A DeCicco
Browse files
Options
Downloads
Patches
Plain Diff
Added a date checker and allowed for user to use vector of numbers for bBox.
parent
257f6073
No related branches found
No related tags found
1 merge request
!63
More error handling, specifically WQP.
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
R/readWQPdata.R
+31
-10
31 additions, 10 deletions
R/readWQPdata.R
with
31 additions
and
10 deletions
R/readWQPdata.R
+
31
−
10
View file @
faeffcbf
...
@@ -90,22 +90,43 @@
...
@@ -90,22 +90,43 @@
#' nameToUse <- "pH"
#' nameToUse <- "pH"
#' pHData <- readWQPdata(siteid="USGS-04024315",characteristicName=nameToUse)
#' pHData <- readWQPdata(siteid="USGS-04024315",characteristicName=nameToUse)
#' pHDataExpanded <- readWQPdata(bBox="-90.10,42.67,-88.64,43.35",characteristicName=nameToUse)
#' pHDataExpanded <- readWQPdata(bBox="-90.10,42.67,-88.64,43.35",characteristicName=nameToUse)
#' pHDataExpanded2 <- readWQPdata(bBox=c(-90.10,42.67,-88.64,43.35),characteristicName=nameToUse)
#' startDate <- as.Date("2008-01-01")
#' nutrientPysical <- readWQPdata(statecode="US:55",siteType="Stream",
#' samplMedia="Water",startDateLo=startDate,
#' characteristicType=c("Nutrient","Physical))
#' }
#' }
readWQPdata
<-
function
(
...
){
readWQPdata
<-
function
(
...
){
matchReturn
<-
list
(
...
)
matchReturn
<-
list
(
...
)
# WQP does a better job of this in the header return:
values
<-
sapply
(
matchReturn
,
function
(
x
)
URLencode
(
as.character
(
paste
(
eval
(
x
),
collapse
=
";"
,
sep
=
""
))))
# options <- c("bBox","lat","long","within","countrycode","statecode","countycode","siteType","organization",
# "siteid","huc","sampleMedia","characteristicType","characteristicName","pCode","activityId",
# "startDateLo","startDateHi","mimeType","Zip","providers")
#
# if(!all(names(matchReturn) %in% options)) warning(names(matchReturn)[!(names(matchReturn) %in% options)]," is not a valid query parameter to the Water Quality Portal")
values
<-
sapply
(
matchReturn
,
function
(
x
)
URLencode
(
as.character
(
paste
(
eval
(
x
),
collapse
=
""
,
sep
=
""
))))
values
<-
gsub
(
","
,
"%2C"
,
values
)
values
<-
gsub
(
","
,
"%2C"
,
values
)
values
<-
gsub
(
"%20"
,
"+"
,
values
)
values
<-
gsub
(
"%20"
,
"+"
,
values
)
values
<-
gsub
(
":"
,
"%3A"
,
values
)
if
(
"bBox"
%in%
names
(
values
)){
values
[
'bBox'
]
<-
gsub
(
pattern
=
";"
,
replacement
=
","
,
x
=
values
[
'bBox'
])
}
dateNames
<-
c
(
"startDateLo"
,
"startDateHi"
,
"startDate"
,
"endDate"
)
if
(
any
(
names
(
values
)
%in%
dateNames
)){
index
<-
which
(
names
(
values
)
%in%
dateNames
)
# If a valid R date was put in, the format needs to be changed to mm-dd-yyyy for the WQP:
if
(
all
(
is.Date
(
as.Date
(
values
[
index
])))){
dates
<-
as.Date
(
values
[
index
])
dates
<-
format
(
as.Date
(
dates
),
format
=
"%m-%d-%Y"
)
values
[
index
]
<-
dates
}
else
if
(
!
all
(
is.Date
(
as.Date
(
values
[
index
],
format
=
"%m-%d-%Y"
)))){
warning
(
"Please check the date format for the arguments: "
,
paste
(
names
(
values
)[
index
],
collapse
=
", "
))
}
names
(
values
)[
names
(
values
)
==
'beginDate'
]
<-
'startDateLo'
names
(
values
)[
names
(
values
)
==
'endDate'
]
<-
'startDateHi'
}
urlCall
<-
paste
(
paste
(
names
(
values
),
values
,
sep
=
"="
),
collapse
=
"&"
)
urlCall
<-
paste
(
paste
(
names
(
values
),
values
,
sep
=
"="
),
collapse
=
"&"
)
...
@@ -114,7 +135,7 @@ readWQPdata <- function(...){
...
@@ -114,7 +135,7 @@ readWQPdata <- function(...){
urlCall
<-
paste0
(
baseURL
,
urlCall
<-
paste0
(
baseURL
,
urlCall
,
urlCall
,
"&mimeType=tsv"
)
"&mimeType=tsv"
)
retval
<-
importWQP
(
urlCall
,
FALSE
)
retval
<-
importWQP
(
urlCall
,
FALSE
)
if
(
!
all
(
is.na
(
retval
))){
if
(
!
all
(
is.na
(
retval
))){
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment