Skip to main content

Finding hydrologically related features

One of Geoconnex's main use cases is to support the discovery of hydrologically related monitoring locations. That's why one of the key uses of the Geoconnex API is to serve relationships between key hydrometric locations like dams, streamgages, and mainstem rivers. Both the dams and gages collections include the attributes:

  • mainstem_uri that allows one to find all such features that are on a given mainstem.
  • subjectof that directs to the URL of a source data system's record about the dam or streamgage.

Below we demonstrate finding all dams and gages on the Animas River:

# Animas River mainstem URI
animas_uri <- "https://geoconnex.us/ref/mainstems/35394"
# Function to query features by mainstem URI
query_by_mainstem <- function(collection, mainstem_uri) {
query <- URLencode(sprintf("mainstem_uri = '%s'", mainstem_uri))
url <- paste0(base_url, "/collections/", collection, "/items?f=json&filter=", query)
st_read(url, quiet = TRUE)
}
# Query dams and gages
animas_dams <- query_by_mainstem("dams", animas_uri)
animas_gages <- query_by_mainstem("gages", animas_uri)
# Function to create a hyperlink in HTML
create_link <- function(url) {
ifelse(!is.na(url) & url != "",
sprintf('<a href="%s" target="_blank">Link</a>', url),
"N/A")
}
# Create interactive tables
animas_dams <- animas_dams |>
mutate(subjectof = sapply(subjectof, create_link))
datatable(animas_dams, options = list(pageLength = 5, scrollX = TRUE),
caption = "Dams on the Animas River",
escape = FALSE) # Allow HTML in the table
animas_gages <- animas_gages |>
select(uri, name, subjectof) |>
mutate(subjectof = sapply(subjectof, create_link))
datatable(animas_gages,options = list(pageLength = 5, scrollX = TRUE),
caption = "Gages on the Animas River",
escape = FALSE) # Allow HTML in the table
# Fetch the Animas River geometry
animas_river <- st_read(animas_uri, quiet = TRUE)
# Create a map view of the results
mapview(animas_river, color = "blue", layer.name = "Animas River") +
mapview(animas_dams, col.regions = "red", layer.name = "Dams") +
mapview(animas_gages, col.regions = "green", layer.name = "Gages")