header_tag.html

Skip to contents

Imports data from the Water Quality Portal. This function gets the data from here: https://www.waterqualitydata.us. There are four required input arguments: siteNumbers, parameterCd, startDate, and endDate. parameterCd can either be a USGS 5-digit code, or a characteristic name. The sites can be either USGS, or other Water Quality Portal offered sites. It is required to use the 'full' site name, such as 'USGS-01234567'.

Usage

readWQPqw(
  siteNumbers,
  parameterCd,
  startDate = "",
  endDate = "",
  tz = "UTC",
  legacy = TRUE,
  querySummary = FALSE,
  ignore_attributes = FALSE,
  convertType = TRUE
)

Arguments

siteNumbers

character site number. This needs to include the full agency code prefix.

parameterCd

vector of USGS 5-digit parameter code or characteristicNames. Leaving this blank will return all of the measured values during the specified time period.

startDate

character starting date for data retrieval in the form YYYY-MM-DD. Default is "" which indicates retrieval for the earliest possible record. Date arguments are always specified in local time.

endDate

character ending date for data retrieval in the form YYYY-MM-DD. Default is "" which indicates retrieval for the latest possible record. Date arguments are always specified in local time.

tz

character to set timezone attribute of dateTime. Default is "UTC", and converts the date times to UTC, properly accounting for daylight savings times based on the data provided tz_cd column. Possible values to provide are "America/New_York","America/Chicago", "America/Denver","America/Los_Angeles", "America/Anchorage", as well as the following which do not use daylight savings time: "America/Honolulu", "America/Jamaica","America/Managua","America/Phoenix", and "America/Metlakatla". See also OlsonNames() for more information on time zones.

legacy

Logical. If TRUE, uses legacy WQP services. Default is TRUE. Setting legacy = FALSE uses WQX3.0 WQP services, which are in-development, use with caution.

querySummary

logical to look at number of records and unique sites that will be returned from this query.

ignore_attributes

logical to choose to ignore fetching site and parameter attributes. Default is FALSE.

convertType

logical, defaults to TRUE. If TRUE, the function will convert the data to dates, datetimes, numerics based on a standard algorithm. If false, everything is returned as a character.

Value

A data frame derived from the default data profile.

There are also several useful attributes attached to the data frame:

NameTypeDescription
urlcharacterThe url used to generate the data
siteInfodata.frameA data frame containing information on the requested sites
variableInfodata.frameA data frame containing information on the requested parameters
queryTimePOSIXctThe time the data was returned

Examples

# \donttest{
rawPcode <- readWQPqw("USGS-01594440", "01075", "", "")
#> GET: https://www.waterqualitydata.us/data/Result/search?siteid=USGS-01594440&pCode=01075&mimeType=csv
#> NEWS: Data does not include USGS data newer than March 11, 2024. More details:
#> https://doi-usgs.github.io/dataRetrieval/articles/Status.html

attr(rawPcode, "siteInfo")
#> # A tibble: 1 × 37
#>   OrganizationIdentifier OrganizationFormalName           MonitoringLocationId…¹
#>   <chr>                  <chr>                            <chr>                 
#> 1 USGS-MD                USGS Maryland Water Science Cen… USGS-01594440         
#> # ℹ abbreviated name: ¹​MonitoringLocationIdentifier
#> # ℹ 34 more variables: MonitoringLocationName <chr>,
#> #   MonitoringLocationTypeName <chr>, MonitoringLocationDescriptionText <chr>,
#> #   HUCEightDigitCode <chr>, DrainageAreaMeasure.MeasureValue <dbl>,
#> #   DrainageAreaMeasure.MeasureUnitCode <chr>,
#> #   ContributingDrainageAreaMeasure.MeasureValue <dbl>,
#> #   ContributingDrainageAreaMeasure.MeasureUnitCode <chr>, …
attr(rawPcode, "queryTime")
#> [1] "2024-10-25 18:59:09 UTC"


rawCharacteristicName <- readWQPqw("WIDNR_WQX-10032762", "Specific conductance", "", "")
#> GET: https://www.waterqualitydata.us/data/Result/search?siteid=WIDNR_WQX-10032762&characteristicName=Specific%20conductance&mimeType=csv
#> NEWS: Data does not include USGS data newer than March 11, 2024. More details:
#> https://doi-usgs.github.io/dataRetrieval/articles/Status.html
rawPHsites <- readWQPqw(c("USGS-05406450", "USGS-05427949", "WIDNR_WQX-133040"), "pH", "", "")
#> GET: https://www.waterqualitydata.us/data/Result/search?siteid=USGS-05406450;USGS-05427949;WIDNR_WQX-133040&characteristicName=pH&mimeType=csv
#> NEWS: Data does not include USGS data newer than March 11, 2024. More details:
#> https://doi-usgs.github.io/dataRetrieval/articles/Status.html
nwisEx <- readWQPqw("USGS-04024000", c("34247", "30234", "32104", "34220"), "", "2022-12-20")
#> GET: https://www.waterqualitydata.us/data/Result/search?siteid=USGS-04024000&pCode=34247;30234;32104;34220&startDateHi=12-20-2022&mimeType=csv
#> NEWS: Data does not include USGS data newer than March 11, 2024. More details:
#> https://doi-usgs.github.io/dataRetrieval/articles/Status.html

SC <- readWQPqw(siteNumbers = "USGS-05288705", parameterCd = "00300", convertType = FALSE)
#> GET: https://www.waterqualitydata.us/data/Result/search?siteid=USGS-05288705&pCode=00300&mimeType=csv
#> NEWS: Data does not include USGS data newer than March 11, 2024. More details:
#> https://doi-usgs.github.io/dataRetrieval/articles/Status.html
# }