Site Service Details
Site Web Service
You can use this service to retrieve information about the millions of hydrologic sites with data served by the USGS. This service provides USGS water data in the legacy RDB (tab-delimited) format that are currently available from the USGS Water Data for the Nation site External Link, as well as in a Google Maps and Google Earth friendly formats. More media types will follow after technical issues are resolved.
How the service works
- This is a REST-friendly service, which means it is URL accessible and can be run from a browser
- The service can return information about one or more sites in one request
- Data for historical, as well as currently active sites are available, including period of record information that describes the kinds of data collected at the site and date ranges when these data were collected.
With hundreds of thousands of sites across the nation, the amount of data available is very large. No one user is allowed to download all of the data with a single call. The service has consequently been designed and engineered to facilitate common mass queries, defaulting to returning a narrower set of data. You are encouraged to make your queries efficient too, mindful that many others need access to the data at the same time. Always specify the minimum amount of data you need in your request, using built in filters and date ranges to the maximum extent possible.
Testing the service
Probably the best way to learn how to use the service is to try it out!
The USGS provides this tool that allows you to generate syntactically correct calls to the service. You can even run the query live in your browser. The XML output may look somewhat strange if you are new to XML. When you have perfected your query you can copy and paste the URL into your application to get the precise data you need.
Enabling gzip compression
Typically data is downloaded as plain text via Hypertext Transfer Protocol (HTTP). However, gzip compression
is supported by this service. Use of gzip compression may markedly speed up acquisition of data, particularly on large queries. It also is a more efficient use of USGS servers, so we appreciate when you are thoughtful enough to use it. Whether you can receive the data in gzip compressed formats depends on the capabilities of your client. Web browsers support gzip compression natively, but most regular users will use specialized utility programs like wget
and curl
to acquire data. If you can handle gzip compression, please place the following string into your HTTP request headers: Accept-Encoding: gzip, compress
curl and wget are typically used to download data. They may be configured to use gzip compression if the server will accept it. You may also explicitly have to tell it to use gzip compression. If so these tips should work:
- curl: try adding the argument:
-H 'Accept-Encoding: gzip,deflate'
- wget: try adding the argument:
--header="Accept-Encoding: gzip"
gzip files are typically returned as a file with a .gz file suffix unless you instruct your program to uncompress it. See the gzip man page for instructions on uncompressing .gz files.
Output
A web feature service is planned.
The most “data rich” format that is currently supported is the legacy USGS RDB (tab-delimited) format. The RDB format is documented here , and consists of a number of header comments that include column description information, followed by the relevant data. Fields are separated by invisible tab characters; records are separated with new line characters.
# US Geological Survey
#
# The Site File stores location and general information about ground water,
# surface water, and meteorological sites for sites in USA.
#
# File-format description: http://waterdata.usgs.gov/nwis/?tab_delimited_format_info
# Automated-retrieval info: http://waterdata.usgs.gov/nwis/?automated_retrieval_info
#
# Contact: gs-w_waterdata_support@usgs.gov
# retrieved: 2011-01-13 10:27:06 EST (nwisvatestws01)
#
# The following selected fields are included in this output:
# agency_cd -- Agency
# site_no -- Site identification number
# station_nm -- Site name
# site_tp_cd -- Site type
# dec_lat_va -- Decimal latitude
# dec_long_va -- Decimal longitude
# coord_acy_cd -- Latitude-longitude accuracy
# dec_coord_datum_cd -- Decimal Latitude-longitude datum
# alt_va -- Altitude of Gage/land surface
# alt_acy_va -- Altitude accuracy
# alt_datum_cd -- Altitude datum
#
agency_cd site_no station_nm site_tp_cd dec_lat_va dec_long_va coord_acy_cd dec_coord_datum_cd alt_va alt_acy_va alt_datum_cd 5s 15s 50s 7s 16s 16s 1s 10s 8s 3s 10s
USGS 01646500 POTOMAC RIVER NEAR WASH, DC LITTLE FALLS PUMP STA ST 38.94977778 -77.12763889 S NAD83 37.95 .01 NGVD29
Figure 1. Example of RDB output
The service also outputs in formats compatible with Google Earth and Google Maps by returning data in Keyhole Markup Language (KML) optimized for these mapping services. This allows you to show USGS sites on these and similar mapping products.
The Mapper format is a legacy XML format used by the USGS to support its National Water Information System Mapper product. However, these output formats contain minimal information about a site.
Many output formats from this service are straightforward and easy to understand. Google Map and Google Earth formats, for example, display minimal information for a site because they are intended to be used to show sites on a map. The RDB format can offer voluminous information that can be hard to understand and interpret.
Understanding site-level data
To interpret the RDB formats, you have to understand the meaning of the column headers in the output. Understanding basic site data is generally straightforward. In RDB, the column headers are described in comment lines that begin with a #.
- The first non comment line is a header line, followed by a line that describes the kind of data and the maximum size of data in that field (5s for a 5-character string, for example)
- The line after the header line are data lines. station_nm for example is POTOMAC RIVER NEAR WASH, DC LITTLE FALLS PUMP STA ST. This can be inferred because it is the third tab-delimited column in the header line, and the first data line contains this text in the third tab-position. If you don’t understand what station_nm is, the comments near the top of the file explain it should be interpreted as Site Name.
- In some outputs you will see repetition of comment and header lines after various data lines. Each of these blocks describes data immediately below it.
Understanding period of record output
Period of record information can be especially confusing. Period of record information describes what data was collected at a site for what time periods. Consider this partial output for this query . The data is tab-delimited and will line up by column if imported into a spreadsheet, but it hard to show on a web page. Items below have been bolded to show associations between headers and their data:
# end_date -- End date
# count_nu -- Record count
#
agency_cd site_no station_nm site_tp_cd dec_lat_va dec_long_va coord_acy_cd dec_coord_datum_cd alt_va alt_acy_va alt_datum_cd data_type_cd parm_cd stat_cd loc_nm medium_grp_cd parm_grp_cd srs_id access_cd begin_date end_date count_nu
5s 15s 50s 7s 16s 16s 1s 10s 8s 3s 10s 2s 5s 5s 30s 3s 3s 5n 4n 20d 20d 5n
USGS 01646500 POTOMAC RIVER NEAR WASH, DC LITTLE FALLS PUMP STA ST 38.94977778 -77.12763889 S NAD83 37.95 .01 NGVD29 dv 00010 00003 wat 1645597 0 1988-10-01 2011-04-08 7856
Figure 2. Period of Record output
There is a story here. Looked at the bolded text in the example:
- data_type_cd is associated with a value of “dv”. “dv” stands for daily values. So this site collects or collected daily values.
- parm_cd is the USGS parameter code defined here . 00010 corresponds to water temperature in degrees Celsius. So now we know this site this site collects daily values for water temperature.
- stat_cd stands for statistics code defined here . 00003 corresponds to mean, so now we know this site collects daily values for water temperature published as a mean (average) value for the day.
- begin_date means the date that this information started to be collected, which was October 1, 1988.
- end_date means end date and is April 8, 2011. If the site is active, this date will usually be the last full day. In short, mean water temperature is still being collected, so there is a continuous record for this kind of data since October 1, 1988 through April 8, 2011.
- count_nu is count number, or the number of mean daily values that are available for water temperature for this site, which is 7856, presumably one for each day from October 1, 1988 through April 8, 2011.
Starting late February 2024, the Site Service will stop retrieving new water quality samples/results data or updates to existing data for queries using hasDataTypeCd=qw.
Based on this information, an application might want to programatically start another application to fetch the daily value data using the Daily Values web service.
When GML is available as an output format, data will be encapsulated in XML tags but have similar names, so similar logic will apply.
Where to find USGS code information
- Most codes used by the service are documented on the USGS Water Data for the Nation Help site on the codes page .
- USGS Parameters (parm_cd) can be found here
- Certain definitions like site number and lat/long can be found here
Error codes
Since this system uses Hypertext Transfer Protocol (HTTP), any application errors are reported in the HTTP headers. This means that when writing applications, it is important to first examine the HTTP status code that is returned in the HTTP response. The application server will return the error code along with a message describing the error in the event there is a problem. Programmers should always check the HTTP response code and if not a 200 handle the response as an exception. Among the status codes you may see:
HTTP Error Code | HTTP Error Code Description | Explanation |
---|---|---|
200 | OK | The request was successfully executed and some data should have been returned. |
304 | Not_Modified | This indicates your request was redirected using the proper URL. This may occur if the "path" of your URL is not fully qualified. Ideally a / is placed before the ? in the URL. Adding in this slash may make this go away. However, the request should still be processed. If this becomes annoying, you may also be able to tell your client program to automatically follow redirects. |
400 | Bad_Request | This often occurs if the URL arguments are inconsistent. An accompanying error should describe why the request was bad. Reasons include:
|
403 | Access_Forbidden | This should only occur if for some reason the USGS has blocked your Internet Protocol (IP) address from using the service. This can happen if we believe that your use of the service is so excessive that it is seriously impacting others using the service. To get unblocked, send us the URL you are using along with your client's IP using this form. We may require changes to your query and frequency of use in order to give you access to the service again. |
404 | Not_Found | Returned if and only if the query expresses a combination of elements where data do not exist. For multi-site queries, if any data are found, it is returned for those site/parameters/date ranges where there are data. Conditions that would return a 404 Not Found include:
|
500 | Internal_Server_Error | If you see this, it means there is a problem with the web service itself. It usually means the application server is down unexpectedly. This could be caused by a host of conditions but changing your query will not solve this problem. The application support team has to fix it. Most of these errors are quickly detected and the support team is notified if they occur. |
503 | Service_Unavailable | The server is currently unable to handle the request due to a temporary overloading or maintenance of the server. The implication is that this is a temporary condition which will be alleviated after some delay. |
Using the Web Service with Adobe Flex or the Flex API
Adobe Flex requires our server have a crossdomain.xml file indicating those domains that can access our web service using Adobe Flex. We are adding these on a case by case basis. If you need to access the service using Adobe Flex or the Flex API, please contact us using this form and indicate the domain of the server that will access the service.
CORS Support
This service supports the Cross-Origin Resource Sharing (CORS) specification. CORS permits browser-based asynchronous access to the service even though content originates from a server different than the one serving the web page. Otherwise the browser’s security controls would not allow content to come from USGS servers. Most, but not all browsers, support CORS. Some frameworks, like jQuery through the Ajax crossDomain setting, support CORS automatically.
URL Format
The URL must always be in this format:
https://waterservices.usgs.gov/nwis/site/?<arguments>
where <arguments>
are one or more HTTP GET parameter names and values based on the information below.
Specifying the URL Arguments
You specify the arguments that go in <arguments>
.
- Each URL argument name is followed by an equal sign followed by one or more values for that argument. Where multiple values are allowed for the same argument, you can separate values with commas.
- URL arguments are separated by ampersands (&)
- The order of the URL arguments does not matter
- If a URL argument name does not match one of the names below, a HTTP 400 error is triggered.
Here is an example of a valid URL that should return data:
URL argument names and URL argument values can be in upper, lower or mixed case. They will all be handled correctly. All of the following will yield the same result:
- https://waterservices.usgs.gov/nwis/site/?stateCd=ny
- https://waterservices.usgs.gov/nwis/site/?statecd=ny
- https://waterservices.usgs.gov/nwis/site/?STATECD=ny
- https://waterservices.usgs.gov/nwis/site/?stateCd=NY
- https://waterservices.usgs.gov/nwis/site/?STATECD=NY
- https://waterservices.usgs.gov/nwis/site/?stateCd=Ny
URL argument conventions
The following conventions are used below to document URL argument values:
arg1=[ a {,x | ,y} | b | c,d,...]
- square brackets
[]
are used to show a set of possible choices, with the pipe symbol|
delineating exclusive choices. You must select one and only one of these choices. - curved brackets
{}
are used to show optional elements. They also may be delineated with|
indicating exclusive choices. If used, you may select one and only one of these choices. ...
indicates more than item may be specified if items are delineated by commas. Note the limitation on the maximum number of argument values allowed below.
In the above example, these would be the allowed legal values:
arg1=a
arg1=a,x
arg1=a,y
arg1=b
arg1=c
arg1=c,d,e,f
arg1=e,f
Major Filters
Single Site Queries
Want to only query one site? Use site (or sites) as your major filter, and put only one site number in the list! Example:
Multiple Site Queries
- Every multiple site query requires a major filter. Pick the major filter (sites, stateCd, huc, bBox or counties) that best retrieves the data for the sites that you are interested in.
- You can have more than one major filter per query. However, you cannot replicate a particular major filter in the query. The effect is an AND, reducing the results returned. Ex: &stateCd=nh&huc=01060003 returns sites in New Hampshire for Piscataqua-Salmon Falls.
- Further refine the query with minor filters, if needed.
Major Filter (select one of the following) | Meaning | Minimum Number of Argument Values | Maximum Number of Argument Values | Examples |
---|---|---|---|---|
sites(aliases: site, location) | A list of site numbers. You can specify unlimited sites, up to any limit imposed by the application server or your client. Sites are comma separated. Sites may be prefixed with an optional agency code followed by a colon. If you don't know the site numbers you need, you can find relevant sites with the NWIS Mapper or on the USGS Water Data for the Nation site. | 1 | Unlimited (see caveat) | &site=01646500 &sites=USGS:01646500 &sites=01646500,06306300 |
stateCd (alias: stateCds) | U.S. postal service (2-digit) state code. USPS List of State Codes. | 1 | 1 | &stateCd=NY |
huc (alias: hucs) | A list of hydrologic unit codes (HUC) or aggregated watersheds. Only 1 major HUC can be specified per request. A major HUC has two digits. Minor HUCs must be eight digits in length. Not all sites are associated with a HUC. List of HUCs. | 1 | 1 Major, 10 Minor | &huc=01,02070010 |
bBox | A contiguous range of decimal latitude and longitude, starting with the west longitude, then the south latitude, then the east longitude, and then the north latitude with each value separated by a comma. The product of the range of latitude and longitude cannot exceed 25 degrees. Whole or decimal degrees must be specified, up to six digits of precision. Minutes and seconds are not allowed. Remember: western longitude (which includes almost all of the United States) is specified in negative degrees. Caution: many sites outside the continental US do not have latitude and longitude referenced to NAD83 and therefore can not be found using these arguments. Certain sites are not associated with latitude and longitude due to homeland security concerns and cannot be found using this filter. | 1 | 1 | &bBox=-83,36.5,-81,38.5 |
countyCd (alias: countyCds) | A list of county numbers, in a 5 digit numeric format. The first two digits of a county's code are the FIPS State Code. List of county codes. Some updates were made to the FIPS code standards in 2021. NIST has provided replacement standards. | 1 | 20 | &countyCd=51059,51061 |
Outputs
Format (format)
URL Argument Name | format |
---|---|
Description | Used to specify the output format of the data returned.
|
Syntax | format=[rdb{,1.0} | gm{,1.0) | ge{,1.0} | mapper{,1.0}] |
Default | rdb (This will change to gml when GML output is ready) |
Minimum argument values required | 1 |
Maximum argument values allowed | 1 |
Examples |
|
Show expanded Site Output (siteOutput)
URL Argument Name | siteOutput (alias: site_output) |
---|---|
Description | Indicates the richness of metadata you want for site attributes. Note that for visually oriented formats like Google Map format, this argument has no meaning. Note: for performance reasons, siteOutput=expanded cannot be used if seriesCatalogOutput=true or with any values for outputDataTypeCd.
|
Syntax | siteOutput=[basic | expanded] |
Default | basic |
Minimum argument values required | 1 |
Maximum argument values allowed | 1 |
Examples |
|
Show Period of Record (seriesCatalogOutput)
URL Argument Name | seriesCatalogOutput (alias: seriesCatalog) |
---|---|
Description | A switch that provides detailed period of record information for certain output formats. The period of record indicates date ranges for a certain kind of information about a site, for example the start and end dates for a site's daily mean streamflow. Note that for visually oriented formats like the Google Maps format, this argument has no meaning. When true, this is behaves the same as outputDataTypeCd=all. Note: for performance reasons, siteOutput=expanded cannot be used if seriesCatalogOutput=true. |
Syntax | seriesCatalogOutput=true|false |
Default | false |
Minimum argument values required | 0 |
Maximum argument values allowed | 1 |
Examples |
|
Show one or more data types (outputDataTypeCd)
URL Argument Name | outputDataTypeCd (alias: outputDataType) |
---|---|
Description | This allows you to specify that you want to output specific kinds of period of record data. The default is all. Note that for visually oriented formats like Google Map format, this argument has no meaning. For example, if you set this argument to just "iv" you will see only period of record information for instantaneous values (time-series data) like stage and discharge time-series measurements. Note: for performance reasons, siteOutput=expanded cannot be used with any values for outputDataTypeCd.
|
Syntax | outputDataTypeCd=[ all | { [iv | uv | rt], dv, pk, sv, gw, qw, id, aw, ad} ] |
Default | No period of record output shows, unless seriesCatalogOutput=true |
Minimum argument values required | 0 |
Maximum argument values allowed | 9 |
Examples |
|
Minor Filters
Minor filters further reduce the set of expected results and are applied after data is first filtered by the major filter you specified. You are encouraged to use minor filters to minimize the amount of data sent.
Date Filters
Start Date (startDt)
URL Argument Name | startDt |
---|---|
Description |
|
Syntax | startDt=[ISO-8601-Calendar-Date] |
Default | startDt is ignored. If endDt is present but startDt is not, sites through endDt are included |
Minimum argument values required | 1 |
Maximum argument values allowed | 1 |
Examples |
|
End Date (endDt)
URL Argument Name | endDt |
---|---|
Description |
|
Syntax | endDt=[ISO-8601-Calendar-Date] |
Default | endDt is ignored. If startDt is present but endDt is not, sites from the startDt to the present are included |
Minimum argument values required | 1 |
Maximum argument values allowed | 1 |
Examples |
|
Period (period)
URL Argument Name | period |
---|---|
Description |
|
Syntax | period=[ISO-8601-Duration] |
Default | period is ignored. |
Minimum argument values required | 1 |
Maximum argument values allowed | 1 |
Examples |
|
Site was modified since (modifiedSince)
URL Argument Name | modifiedSince |
---|---|
Description |
|
Syntax | modifiedSince=[ISO-8601-Duration] |
Default | None |
Minimum argument values required | 1 |
Maximum argument values allowed | 1 |
Examples |
|
Site Name (siteName)
URL Argument Name | siteName (aliases: siteNm, stationName, stationNm) |
---|---|
Description | This filter allows you to find a site by its name, using either the exact site name or a partial site name. Note that a major filter is still required. String matches are case insensitive, so if you specify "Boulder" you will retrieve site names with "Boulder", "boulder", "BOULDER" as well as many other variants. To embed a space, you can substitute %20. |
Syntax | siteName=string |
Default | None. If used, a string must be supplied or an error will occur. |
Minimum argument values required | 1 |
Maximum argument values allowed | 1 |
Examples |
|
Site Name Match Operator (siteNameMatchOperator)
URL Argument Name | siteNameMatchOperator (aliases: siteNameMatch, siteNmMatch, stationNameMatch, stationNmMatch) |
---|---|
Description | If used, this must be used with siteName. It determines how the pattern matching for site name behaves. Matches are case insensitive. The options are:
|
Syntax | siteNameMatchOperator=[ start | any | exact ] |
Default | start |
Minimum argument values required | 1 |
Maximum argument values allowed | 1 |
Examples |
|
Site Status (siteStatus)
URL Argument Name | siteStatus |
---|---|
Description |
|
Syntax | siteStatus=[ all | active | inactive ] |
Default | all - sites of any activity status are returned |
Minimum argument values required | 1 |
Maximum argument values allowed | 1 |
Examples |
|
Site Type (siteType)
URL Argument Name | siteType (aliases: siteTypes, siteTypeCd, siteTypeCds) |
---|---|
Description |
|
Syntax | siteType={siteType1,siteType2,...} |
Default | All site types are returned |
Minimum argument values required | 1 |
Maximum argument values allowed | No limit |
Examples |
|
Has one or more data types (hasDataTypeCd)
URL Argument Name | hasDataTypeCd (aliases: hasDataType, dataTypeCd, dataType) |
---|---|
Description | Restricts results to those sites that collect certain kinds of data. Allowed values are:
The service distinguishes between selecting sites with one or more data types and actually showing those data types in the output. hasDataTypeCd is used for selection. Since the default is to output all data types, this is normally not an issue, but it is possible to use hasDataTypeCd with outputDataTypeCd for unusual types of filters. See the examples below. |
Syntax | hasDataTypeCd=[ all | { [iv | uv | rt], dv, pk, sv, gw, qw, id, aw, ad } ] |
Default | all |
Minimum argument values required | 1 |
Maximum argument values allowed | 9 |
Examples |
|
Parameter Code (parameterCd)
URL Argument Name | parameterCd (aliases: variable, parameterCds, variables, var, vars, parmCd) |
---|---|
Description |
|
Syntax | parameterCd|variable={parameterCd1,parameterCd2,...} |
Default | returns all regular time-series parameters for the requested sites |
Minimum argument values required | 1 |
Maximum argument values allowed | 100 |
Examples |
|
Agency Code (agencyCd)
URL Argument Name | agencyCd |
---|---|
Description |
|
Syntax | agencyCd=agencyCd1 |
Default | All sites regardless of agency code are retrieved |
Minimum argument values required | 1 |
Maximum argument values allowed | 1 |
Examples |
|
Altitude (altMin and altMax)
URL Argument Name |
|
---|---|
Description |
|
Syntax |
|
Default | All sites are retrieved, regardless of their altitude |
Minimum argument values required | 1 |
Maximum argument values allowed | 1 |
Examples |
|
Surface water filters
Drainage Area (drainAreaMin and drainAreaMax)
URL Argument Names |
|
---|---|
Description |
|
Syntax |
|
Default | All sites are retrieved, regardless of their drainage area |
Minimum argument values required | 1 |
Maximum argument values allowed | 1 |
Examples |
|
Groundwater Filters
Aquifer Code (aquiferCd)
URL Argument Names |
|
---|---|
Description |
|
Syntax |
|
Default | all |
Minimum argument values required | 0 |
Maximum argument values allowed | 1000 |
Examples |
|
Local Aquifer Code (localAquiferCd)
URL Argument Names |
|
---|---|
Description |
|
Syntax |
|
Default | all |
Minimum argument values required | 0 |
Maximum argument values allowed | 1000 |
Examples |
|
Well Depth (wellDepthMin and wellDepthMax)
URL Argument Names |
|
---|---|
Description |
|
Syntax |
|
Default | All sites are retrieved, regardless of their well depth |
Minimum argument values required | 1 |
Maximum argument values allowed | 1 |
Examples |
|
Hole Depth (holeDepthMin and holeDepthMax)
URL Argument Names |
|
---|---|
Description |
|
Syntax |
|
Default | All sites are retrieved, regardless of their hole depth |
Minimum argument values required | 1 |
Maximum argument values allowed | 1 |
Examples |
|
Feedback
Please provide any feedback you have on this service using this form .