| Title: | Scripted Downloads from the TCEQ CRP Water Quality Portal |
|---|---|
| Description: | Programmatic access to the Texas Commission on Environmental Quality (TCEQ) Clean Rivers Program (CRP) public data portal. Handles JSF session state, basin/station selection, and download of tab-delimited water quality data files. |
| Authors: | Michael Schramm [aut, cre] |
| Maintainer: | Michael Schramm <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-10-10 14:12:18 UTC |
| Source: | https://github.com/mps9506/tceqcrp |
CRP river basin codes
crp_basins()crp_basins()
A tibble mapping basin numbers to basin names.
CRP data type codes
crp_data_types()crp_data_types()
A tibble mapping menu values to data type labels.
Download CRP water quality data
crp_download( form, startdate, enddate, data_type, basin, format = "14", segment_rows, param_code = "", path = tempfile(fileext = ".txt"), quiet = FALSE )crp_download( form, startdate, enddate, data_type, basin, format = "14", segment_rows, param_code = "", path = tempfile(fileext = ".txt"), quiet = FALSE )
form |
A |
startdate, enddate
|
Date strings in |
data_type |
Data type code. See |
basin |
Basin number. See |
format |
Output format code (default |
segment_rows |
Integer vector of table rows. See
|
param_code |
Optional parameter code filter. |
path |
File path to write the downloaded data to. |
quiet |
Suppress progress messages. |
Invisibly, a list with path, post_resp, and stream_resp.
## Not run: form <- crp_get_form() form2 <- crp_select_basin(form, 12) st <- crp_stations(form2) rows <- crp_rows_for_ids(st, c("1201", "1202")) crp_download(form2, "01/01/2020", "12/31/2020", data_type = 1, basin = 12, station_rows = rows, path = "brazos.txt") ## End(Not run)## Not run: form <- crp_get_form() form2 <- crp_select_basin(form, 12) st <- crp_stations(form2) rows <- crp_rows_for_ids(st, c("1201", "1202")) crp_download(form2, "01/01/2020", "12/31/2020", data_type = 1, basin = 12, station_rows = rows, path = "brazos.txt") ## End(Not run)
CRP output format codes
crp_formats()crp_formats()
A tibble mapping menu values to output-format labels.
Fetches the CRP query page, establishes a session, and captures the JSF ViewState token needed for subsequent requests.
crp_get_form()crp_get_form()
An object of class crp_form.
## Not run: form <- crp_get_form() ## End(Not run)## Not run: form <- crp_get_form() ## End(Not run)
List segments available in a basin
crp_list_segments(basin)crp_list_segments(basin)
basin |
Basin number (1-25). See |
A tibble with row, segment_id, segment_desc.
Download CRP data in a single call
crp_query( basin, startdate, enddate, data_type, segment_ids, format = "14", param_code = "", path = tempfile(fileext = ".txt"), read = TRUE, clean_names = FALSE, quiet = FALSE )crp_query( basin, startdate, enddate, data_type, segment_ids, format = "14", param_code = "", path = tempfile(fileext = ".txt"), read = TRUE, clean_names = FALSE, quiet = FALSE )
basin |
Basin number (1-25). See |
startdate, enddate
|
Date strings |
data_type |
Data type code. See |
segment_ids |
Character vector of segment IDs. |
format |
Output format code (default combined). |
param_code |
Optional parameter code filter. |
path |
File path to write to. |
read |
If |
clean_names |
If |
quiet |
Suppress messages. |
A tibble (if read = TRUE) or the file path (invisibly).
## Not run: brazos <- crp_query( basin = 12, startdate = "01/01/2020", enddate = "12/31/2020", data_type = 1, segment_ids = "1202", clean_names = TRUE ) ## End(Not run)## Not run: brazos <- crp_query( basin = 12, startdate = "01/01/2020", enddate = "12/31/2020", data_type = 1, segment_ids = "1202", clean_names = TRUE ) ## End(Not run)
Read a downloaded CRP data file
crp_read(path, clean_names = FALSE, ...)crp_read(path, clean_names = FALSE, ...)
path |
Path to a file written by |
clean_names |
If |
... |
Passed on to |
A tibble.
Find segment table rows by segment ID
crp_rows_for_segments(segments, ids)crp_rows_for_segments(segments, ids)
segments |
A tibble from |
ids |
Character vector of segment IDs (e.g. |
Integer vector of row values for crp_download().
Extract the segment table for the selected basin
crp_segments(form)crp_segments(form)
form |
A |
A tibble with columns row, segment_id, segment_desc.
Select a river basin and retrieve its segment list
crp_select_basin(form, basin)crp_select_basin(form, basin)
form |
A |
basin |
Basin number (1-25). See |
A new crp_form with the segment table populated and a fresh
ViewState. Pass this to crp_segments() and crp_download().