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
d4457fff
Commit
d4457fff
authored
10 years ago
by
Laura A DeCicco
Browse files
Options
Downloads
Patches
Plain Diff
Added new site finding function for NWIS.
parent
362b2488
No related branches found
No related tags found
1 merge request
!3
Added site finder for NWIS (similar to site finder for WQP).
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
R/getNWISSites.R
+28
-0
28 additions, 0 deletions
R/getNWISSites.R
R/getRDB1Data.r
+11
-7
11 additions, 7 deletions
R/getRDB1Data.r
with
39 additions
and
7 deletions
R/getNWISSites.R
0 → 100644
+
28
−
0
View file @
d4457fff
#' Site Data Import from NWIS
#'
#' Returns a list of sites from the NWIS web service. This function gets the data from: \url{http://waterservices.usgs.gov/rest/Site-Test-Tool.html}.
#' Arguments to the function should be based on \url{http://waterservices.usgs.gov/rest/Site-Service.html#Service}
#'
#' @param \dots see \url{http://waterservices.usgs.gov/rest/Site-Service.html#Service} for a complete list of options
#' @keywords data import NWIS web service
#' @return retval dataframe
#' @export
#' @examples
#' siteListPhos <- getNWISSites(stateCd="OH",parameterCd="00665")
getNWISSites
<-
function
(
...
){
matchReturn
<-
match.call
()
values
<-
sapply
(
matchReturn
[
-1
],
function
(
x
)
URLencode
(
as.character
(
paste
(
x
,
collapse
=
""
,
sep
=
""
))))
urlCall
<-
paste
(
paste
(
names
(
values
),
values
,
sep
=
"="
),
collapse
=
"&"
)
baseURL
<-
"http://waterservices.usgs.gov/nwis/site/?format=rdb&siteOutput=expanded&"
urlCall
<-
paste
(
baseURL
,
urlCall
,
sep
=
""
)
retval
<-
getRDB1Data
(
urlCall
)
return
(
retval
)
}
This diff is collapsed.
Click to expand it.
R/getRDB1Data.r
+
11
−
7
View file @
d4457fff
...
...
@@ -31,15 +31,19 @@ getRDB1Data <- function(obs_url,asDateTime=FALSE){
dataType
<-
tmp
[
1
,]
data
<-
tmp
[
-1
,]
if
(
asDateTime
){
data
[,
regexpr
(
'd$'
,
dataType
)
>
0
]
<-
as.POSIXct
(
strptime
(
data
[,
regexpr
(
'd$'
,
dataType
)
>
0
],
"%Y-%m-%d %H:%M"
))
}
else
{
data
[,
regexpr
(
'd$'
,
dataType
)
>
0
]
<-
as.Date
(
data
[,
regexpr
(
'd$'
,
dataType
)
>
0
])
if
(
sum
(
regexpr
(
'd$'
,
dataType
)
>
0
)
>
0
){
if
(
asDateTime
){
data
[,
regexpr
(
'd$'
,
dataType
)
>
0
]
<-
as.POSIXct
(
strptime
(
data
[,
regexpr
(
'd$'
,
dataType
)
>
0
],
"%Y-%m-%d %H:%M"
))
}
else
{
data
[,
regexpr
(
'd$'
,
dataType
)
>
0
]
<-
as.Date
(
data
[,
regexpr
(
'd$'
,
dataType
)
>
0
])
}
}
tempDF
<-
data
[,
which
(
regexpr
(
'n$'
,
dataType
)
>
0
)]
tempDF
<-
suppressWarnings
(
sapply
(
tempDF
,
function
(
x
)
as.numeric
(
x
)))
data
[,
which
(
regexpr
(
'n$'
,
dataType
)
>
0
)]
<-
tempDF
if
(
sum
(
regexpr
(
'n$'
,
dataType
)
>
0
)
>
0
){
tempDF
<-
data
[,
which
(
regexpr
(
'n$'
,
dataType
)
>
0
)]
tempDF
<-
suppressWarnings
(
sapply
(
tempDF
,
function
(
x
)
as.numeric
(
x
)))
data
[,
which
(
regexpr
(
'n$'
,
dataType
)
>
0
)]
<-
tempDF
}
row.names
(
data
)
<-
NULL
return
(
data
)
}
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