Learn R Programming

dataRetrieval (version 2.0.1)

importWaterML1: Function to return data from the NWISWeb WaterML1.1 service

Description

This function accepts a url parameter that already contains the desired NWIS site, parameter code, statistic, startdate and enddate.

Usage

importWaterML1(obs_url, asDateTime = FALSE, tz = "")

Arguments

obs_url
character containing the url for the retrieval
asDateTime
logical, if TRUE returns date and time as POSIXct, if FALSE, Date
tz
character to set timezone attribute of datetime. Default is an empty quote, which converts the datetimes to UTC (properly accounting for daylight savings times based on the data's provided tz_cd column). Possible values to provide are "America/New_York"

Value

  • A data frame with the following columns: lll{ Name Type Description agency_cd character The NWIS code for the agency reporting the data site_no character The USGS site number datetime POSIXct The date and time of the value converted to UTC (if asDateTime = TRUE), character or raw character string (if asDateTime = FALSE) tz_cd character The time zone code for datetime code character Any codes that qualify the corresponding value value numeric The numeric value for the parameter } Note that code and value are repeated for the parameters requested. The names are of the form X_D_P_S, where X is literal, D is an option description of the parameter, P is the parameter code, and S is the statistic code (if applicable). There are also several useful attributes attached to the data frame: lll{ Name Type Description url character The url used to generate the data siteInfo data.frame A data frame containing information on the requested sites variableInfo data.frame A data frame containing information on the requested parameters statisticInfo data.frame A data frame containing information on the requested statistics on the data queryTime POSIXct The time the data was returned }

See Also

renameNWISColumns

Examples

Run this code
siteNumber <- "02177000"
startDate <- "2012-09-01"
endDate <- "2012-10-01"
offering <- '00003'
property <- '00060'
obs_url <- constructNWISURL(siteNumber,property,startDate,endDate,'dv')

data <- importWaterML1(obs_url,TRUE)

groundWaterSite <- "431049071324301"
startGW <- "2013-10-01"
endGW <- "2014-06-30"
groundwaterExampleURL <- constructNWISURL(groundWaterSite, NA,
          startGW,endGW, service="gwlevels")
groundWater <- importWaterML1(groundwaterExampleURL)

unitDataURL <- constructNWISURL(siteNumber,property,
         "2013-11-03","2013-11-03",'uv')
unitData <- importWaterML1(unitDataURL,TRUE)

filePath <- system.file("extdata", package="dataRetrieval")
fileName <- "WaterML1Example.xml"
fullPath <- file.path(filePath, fileName)
importUserWM1 <- importWaterML1(fullPath,TRUE)

# Two sites, two pcodes, one site has two data descriptors:
siteNumber <- c('01480015',"04085427")
obs_url <- constructNWISURL(siteNumber,c("00060","00010"),startDate,endDate,'dv')
data <- importWaterML1(obs_url)
data$dateTime <- as.Date(data$dateTime)
data <- renameNWISColumns(data)
names(attributes(data))
attr(data, "url")
attr(data, "disclaimer")

inactiveSite <- "05212700"
inactiveSite <- constructNWISURL(inactiveSite, "00060", "2014-01-01", "2014-01-10",'dv')
inactiveSite <- importWaterML1(inactiveSite)

inactiveAndAcitive <- c("07334200","05212700")
inactiveAndAcitive <- constructNWISURL(inactiveAndAcitive, "00060", "2014-01-01", "2014-01-10",'dv')
inactiveAndAcitive <- importWaterML1(inactiveAndAcitive)

Run the code above in your browser using DataLab