Learn R Programming

dataRetrieval (version 2.5.1)

constructNWISURL: Construct NWIS url for data retrieval

Description

Imports data from NWIS web service. This function gets the data from here: http://nwis.waterdata.usgs.gov/nwis/qwdata A list of parameter codes can be found here: http://nwis.waterdata.usgs.gov/nwis/pmcodes/ A list of statistic codes can be found here: http://nwis.waterdata.usgs.gov/nwis/help/?read_file=stat&format=table

Usage

constructNWISURL(siteNumber, parameterCd = "00060", startDate = "", endDate = "", service, statCd = "00003", format = "xml", expanded = TRUE, ratingType = "base")

Arguments

siteNumber
string or vector of strings USGS site number. This is usually an 8 digit number
parameterCd
string or vector of USGS parameter code. This is usually an 5 digit number.
startDate
character starting date for data retrieval in the form YYYY-MM-DD. Default is "" which indicates retrieval for the earliest possible record.
endDate
character ending date for data retrieval in the form YYYY-MM-DD. Default is "" which indicates retrieval for the latest possible record.
service
string USGS service to call. Possible values are "dv" (daily values), "uv" (unit/instantaneous values), "qw" (water quality data), "gwlevels" (groundwater),and "rating" (rating curve), "peak", "meas" (discrete streamflow measurements).
statCd
string or vector USGS statistic code only used for daily value service. This is usually 5 digits. Daily mean (00003) is the default.
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, but the user must carefully check the results to see if the data returns matches what is expected. The default is therefore "xml".
expanded
logical defaults to TRUE. If TRUE, retrieves additional information, only applicable for qw data.
ratingType
can be "base", "corr", or "exsa". Only applies to rating curve data.

Value

url string

Examples

Run this code
siteNumber <- '01594440'
startDate <- '1985-01-01'
endDate <- ''
pCode <- c("00060","00010")
url_daily <- constructNWISURL(siteNumber,pCode,
           startDate,endDate,'dv',statCd=c("00003","00001"))
url_unit <- constructNWISURL(siteNumber,pCode,"2012-06-28","2012-06-30",'iv')

url_qw_single <- constructNWISURL(siteNumber,"01075",startDate,endDate,'qw')
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")
url_rating <- constructNWISURL(siteNumber,service="rating",ratingType="base")
url_peak <- constructNWISURL(siteNumber, service="peak")
url_meas <- constructNWISURL(siteNumber, service="meas")
urlQW <- constructNWISURL("450456092225801","70300",startDate="",endDate="","qw",expanded=TRUE)

Run the code above in your browser using DataLab