constructNWISURL.Rd 4.31 KB
Newer Older
Laura A DeCicco's avatar
Laura A DeCicco committed
1
% Generated by roxygen2: do not edit by hand
2
% Please edit documentation in R/constructNWISURL.r
3
4
5
6
\name{constructNWISURL}
\alias{constructNWISURL}
\title{Construct NWIS url for data retrieval}
\usage{
Laura A DeCicco's avatar
Laura A DeCicco committed
7
8
constructNWISURL(siteNumber, parameterCd = "00060", startDate = "",
  endDate = "", service, statCd = "00003", format = "xml",
9
10
  expanded = TRUE, ratingType = "base", statReportType = "daily",
  statType = "mean")
11
12
}
\arguments{
Laura A DeCicco's avatar
Laura A DeCicco committed
13
\item{siteNumber}{string or vector of strings USGS site number.  This is usually an 8 digit number}
14

Laura A DeCicco's avatar
Laura A DeCicco committed
15
\item{parameterCd}{string or vector of USGS parameter code.  This is usually an 5 digit number.}
16

17
18
\item{startDate}{character starting date for data retrieval in the form YYYY-MM-DD. Default is "" which indicates
retrieval for the earliest possible record.}
19

20
21
\item{endDate}{character ending date for data retrieval in the form YYYY-MM-DD. Default is "" which indicates
retrieval for the latest possible record.}
22

Laura A DeCicco's avatar
Laura A DeCicco committed
23
\item{service}{string USGS service to call. Possible values are "dv" (daily values), "uv" (unit/instantaneous values), 
24
25
"qw" (water quality data), "gwlevels" (groundwater),and "rating" (rating curve), "peak", "meas" (discrete streamflow measurements),
"stat" (statistics web service BETA).}
Laura A DeCicco's avatar
Laura A DeCicco committed
26

Laura A DeCicco's avatar
Laura A DeCicco committed
27
28
\item{statCd}{string or vector USGS statistic code only used for daily value service. This is usually 5 digits.  Daily mean (00003) is the default.}

Laura A DeCicco's avatar
Laura A DeCicco committed
29
30
\item{format}{string, can be "tsv" or "xml", and is only applicable for daily and unit value requests.  "tsv" returns results faster, but there is a possiblitiy that an incomplete file is returned without warning. XML is slower, 
but will offer a warning if the file was incomplete (for example, if there was a momentary problem with the internet connection). It is possible to safely use the "tsv" option, 
Laura A DeCicco's avatar
Laura A DeCicco committed
31
but the user must carefully check the results to see if the data returns matches what is expected. The default is therefore "xml".}
Laura A DeCicco's avatar
Laura A DeCicco committed
32

Laura A DeCicco's avatar
Laura A DeCicco committed
33
\item{expanded}{logical defaults to \code{TRUE}. If \code{TRUE}, retrieves additional information, only applicable for qw data.}
34
35

\item{ratingType}{can be "base", "corr", or "exsa". Only applies to rating curve data.}
David Watkins's avatar
David Watkins committed
36
37
38
39
40

\item{statReportType}{character Only used for statistics service requests.  Time division for statistics: daily, monthly, or annual.  Default is daily.
Note that daily provides statistics for each calendar day over the specified range of water years, i.e. no more than 366
data points will be returned for each site/parameter.  Use readNWISdata or readNWISdv for daily averages. 
Also note that 'annual' returns statistics for the calendar year.  Use readNWISdata for water years. Monthly and yearly 
41
provide statistics for each month and year within the range individually.}
David Watkins's avatar
David Watkins committed
42
43
44

\item{statType}{character Only used for statistics service requests. Type(s) of statistics to output for daily values.  Default is mean, which is the only
option for monthly and yearly report types. See the statistics service documentation 
Laura A DeCicco's avatar
Laura A DeCicco committed
45
at \url{https://waterservices.usgs.gov/rest/Statistics-Service.html#statType} for a full list of codes.}
46
47
}
\value{
Laura A DeCicco's avatar
Laura A DeCicco committed
48
url string
49
50
}
\description{
Laura A DeCicco's avatar
Laura A DeCicco committed
51
52
53
Imports data from NWIS web service. This function gets the data from here: \url{https://nwis.waterdata.usgs.gov/nwis/qwdata}
A list of parameter codes can be found here: \url{https://nwis.waterdata.usgs.gov/nwis/pmcodes/}
A list of statistic codes can be found here: \url{https://nwis.waterdata.usgs.gov/nwis/help/?read_file=stat&format=table}
54
55
}
\examples{
Laura A DeCicco's avatar
Laura A DeCicco committed
56
57
58
siteNumber <- '01594440'
startDate <- '1985-01-01'
endDate <- ''
59
pCode <- c("00060","00010")
Laura A DeCicco's avatar
Laura A DeCicco committed
60
61
url_daily <- constructNWISURL(siteNumber,pCode,
           startDate,endDate,'dv',statCd=c("00003","00001"))
Laura A DeCicco's avatar
Laura A DeCicco committed
62
63
url_unit <- constructNWISURL(siteNumber,pCode,"2012-06-28","2012-06-30",'iv')

Laura A DeCicco's avatar
Laura A DeCicco committed
64
url_qw_single <- constructNWISURL(siteNumber,"01075",startDate,endDate,'qw')
Laura A DeCicco's avatar
Laura A DeCicco committed
65
66
67
68
url_qw <- constructNWISURL(siteNumber,c('01075','00029','00453'),
           startDate,endDate,'qw')
url_daily_tsv <- constructNWISURL(siteNumber,pCode,startDate,endDate,'dv',
           statCd=c("00003","00001"),format="tsv")
69
70
71
url_rating <- constructNWISURL(siteNumber,service="rating",ratingType="base")
url_peak <- constructNWISURL(siteNumber, service="peak")
url_meas <- constructNWISURL(siteNumber, service="meas")
Laura A DeCicco's avatar
Laura A DeCicco committed
72
urlQW <- constructNWISURL("450456092225801","70300",startDate="",endDate="","qw",expanded=TRUE)
73
}
74
\keyword{USGS}
75
76
77
78
79
\keyword{data}
\keyword{import}
\keyword{service}
\keyword{web}