Hydrology
Upstream catchments and land-cover summaries for monitoring stations
- Connector software
- Free and open source
- Service credentials
- Not needed
- Query Farm hosting
- Available · $10/month organization minimum
Use with an agent
Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.
npx skills add Query-farm/vgi-skills --skill orchard
Copy this request into your coding agent to get started.
Use https://query.farm/products/orchard/connectors/hydrology/index.md to help me query Hydrology with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.
Trace a watershed from an outlet location
Uses the connector’s bundled synthetic terrain and a sample outlet location.
Example output · captured
- Connector release
- v0.3.0
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
SELECT station_id, cell_count, area_m2
FROM hydrology.main.catchments((SELECT * FROM (VALUES ('outlet', 500035.0, 4100005.0)) AS gauges(station_id, x, y)))
ORDER BY station_id
| station_id | cell_count | area_m2 |
|---|---|---|
| outlet | 49 | 4900 |
Quick start
Choose where to run Hydrology, then follow the steps below.
The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.
1. Install the vgi extension
Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
2. Attach the connector
Attach with uvx
Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.
ATTACH 'hydrology' AS hydrology (
TYPE vgi,
LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-hydrology-worker'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'hydrology' AS hydrology (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-hydrology:0.3.0'
);
3. Run a query
SELECT station_id, cell_count, area_m2
FROM hydrology.main.catchments((SELECT * FROM (VALUES ('outlet', 500035.0, 4100005.0)) AS gauges(station_id, x, y)))
ORDER BY station_id
Run the connector on a server you manage. You operate the service and choose who can connect.
1. Deploy the connector on your server
Follow the connector’s deployment instructions. Use its supported HTTP transport, or launch it remotely over SSH. The connection guide explains both options.
2. Install the vgi extension
Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach the connector
For an HTTP deployment, replace the example URL with your endpoint. Add the authentication options your deployment requires. For SSH, use the SSH connection instructions.
ATTACH 'hydrology' AS hydrology
(TYPE vgi, LOCATION 'https://your-connector.example.com');
4. Run a query
SELECT station_id, cell_count, area_m2
FROM hydrology.main.catchments((SELECT * FROM (VALUES ('outlet', 500035.0, 4100005.0)) AS gauges(station_id, x, y)))
ORDER BY station_id
Query Farm operates Hydrology for your team. Hosting has a $10 monthly minimum per organization; usage counts toward it. From $2.97 per instance-month ($10 monthly minimum).
1. Create your hosted connector
Open the console, choose your organization and deployment size, and add any service credentials there.
2. Install the vgi extension
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach your deployment
Copy the ATTACH statement from your deployment in the console and run it in DuckDB or Haybarn. Use hydrology as the catalog alias for the query below.
4. Run a query
SELECT station_id, cell_count, area_m2
FROM hydrology.main.catchments((SELECT * FROM (VALUES ('outlet', 500035.0, 4100005.0)) AS gauges(station_id, x, y)))
ORDER BY station_id
Technical details
- Verified connector release
- v0.3.0
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
- Verified on
- December 1, 2026
Pin a version for production
When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.
Attach with uvx
Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.
ATTACH 'hydrology' AS hydrology (
TYPE vgi,
LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-hydrology-worker'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'hydrology' AS hydrology (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-hydrology:0.3.0'
);
Overview
Watershed analysis over digital elevation models: upstream catchments for river gauges and monitoring stations from D8 flow routing, and the land cover inside each catchment. Drainage analysis only, not a flood model. Sample rasters are included.
GIS analysis
Delineate DEM-derived upstream catchments for monitoring-station rows, then summarize categorical land cover and spatially join facilities with the returned WKB polygons. Flow uses PyFlwDir's depression-filled D8 network. Catchments reaching the DEM boundary or nodata are flagged as potentially incomplete. Projected metre DEMs and explicit input coordinate systems are required. This is drainage analysis, not a flood model.
SQL workflow
Pass query results to the main schema functions, retaining IDs for joins. Use bundled synthetic data to try the executable examples without network access. CRS, coverage, inference limits and resource bounds are explicit function parameters.
Sources and references
- PyFlwDir: the Deltares flow-direction library; pyflwdir.from_dem fills depressions and derives the D8 network used for catchments.
- Rasterio: reads the DEM and land-cover rasters and polygonizes catchment masks.
- Shapely and pyproj: geometry handling and the coordinate transforms between station, DEM and land-cover CRSs.
Catalog
Everything hydrology exposes once attached — read straight from the worker's
released build.
main 2 functions
Spatial functions for hydrology analysis.
Schema examples (4)
Delineate the known synthetic valley
SELECT station_id, cell_count, area_m2
FROM hydrology.main.catchments((SELECT * FROM (VALUES ('outlet', 500035.0, 4100005.0)) AS gauges(station_id, x, y)))
ORDER BY station_id;
| station_id | cell_count | area_m2 |
|---|---|---|
| outlet | 49 | 4900 |
Dominant upstream land-cover class for four gauges on the synthetic valley: the two single-cell side gauges are pure class 10 (west) and class 20 (east), while the nested mid-valley gauge and the outlet are both mostly class 20
WITH basins AS (SELECT station_id, area_m2, geometry_wkb FROM hydrology.main.catchments((SELECT * FROM (VALUES ('west', 500015.0, 4100035.0), ('mid', 500035.0, 4100035.0), ('east', 500055.0, 4100035.0), ('outlet', 500035.0, 4100005.0)) AS gauges(station_id, x, y))) WHERE status = 'ok') SELECT b.station_id, b.area_m2, arg_max(l.class_code, l.area_m2) AS dominant_class, max(l.fraction_of_valid) AS dominant_share
FROM basins AS b
JOIN hydrology.main.landcover((SELECT station_id, geometry_wkb FROM basins)) AS l ON l.station_id = b.station_id
GROUP BY b.station_id, b.area_m2
ORDER BY b.station_id;
Confirm the entire synthetic upstream area has classified land cover
SELECT sum(area_m2), min(coverage_fraction)
FROM hydrology.main.landcover((SELECT station_id, geometry_wkb FROM hydrology.main.catchments((SELECT * FROM (VALUES ('outlet', 500035.0, 4100005.0)) AS gauges(station_id, x, y))) WHERE status='ok'));
Land cover of the intervening drainage between a mid-valley gauge and the valley outlet: per class, outlet catchment area minus the nested upstream gauge's catchment area (1,500 m2 of class 10 and 1,800 m2 of class 20)
WITH gauges AS (SELECT * FROM (VALUES ('outlet', 500035.0, 4100005.0), ('mid', 500035.0, 4100035.0)) AS g(station_id, x, y)), cover AS (SELECT station_id, class_code, area_m2 FROM hydrology.main.landcover((SELECT station_id, geometry_wkb FROM hydrology.main.catchments((SELECT * FROM gauges)) WHERE status = 'ok'))) SELECT class_code, sum(area_m2) FILTER (WHERE station_id = 'outlet') AS outlet_area_m2, sum(area_m2) FILTER (WHERE station_id = 'mid') AS upstream_gauge_area_m2, outlet_area_m2 - upstream_gauge_area_m2 AS intervening_area_m2
FROM cover
GROUP BY class_code
ORDER BY class_code;
catchments (data TABLE, dem := VARCHAR, input_crs := VARCHAR, max_cells := BIGINT, min_stream_area_m2 := DOUBLE, snap_radius_m := DOUBLE)
Delineate upstream D8 catchments for monitoring stations
Delineate the known synthetic valley
SELECT station_id, cell_count, area_m2
FROM hydrology.main.catchments((SELECT * FROM (VALUES ('outlet', 500035.0, 4100005.0)) AS gauges(station_id, x, y)))
ORDER BY station_id;
| station_id | cell_count | area_m2 |
|---|---|---|
| outlet | 49 | 4900 |
Dominant upstream land-cover class for four gauges on the synthetic valley: the two single-cell side gauges are pure class 10 (west) and class 20 (east), while the nested mid-valley gauge and the outlet are both mostly class 20
WITH basins AS (SELECT station_id, area_m2, geometry_wkb FROM hydrology.main.catchments((SELECT * FROM (VALUES ('west', 500015.0, 4100035.0), ('mid', 500035.0, 4100035.0), ('east', 500055.0, 4100035.0), ('outlet', 500035.0, 4100005.0)) AS gauges(station_id, x, y))) WHERE status = 'ok') SELECT b.station_id, b.area_m2, arg_max(l.class_code, l.area_m2) AS dominant_class, max(l.fraction_of_valid) AS dominant_share
FROM basins AS b
JOIN hydrology.main.landcover((SELECT station_id, geometry_wkb FROM basins)) AS l ON l.station_id = b.station_id
GROUP BY b.station_id, b.area_m2
ORDER BY b.station_id;
landcover (data TABLE, geometry_crs := VARCHAR, max_pixels := BIGINT, raster := VARCHAR)
Summarize categorical land cover inside upstream catchment polygons
Confirm the entire synthetic upstream area has classified land cover
SELECT sum(area_m2), min(coverage_fraction)
FROM hydrology.main.landcover((SELECT station_id, geometry_wkb FROM hydrology.main.catchments((SELECT * FROM (VALUES ('outlet', 500035.0, 4100005.0)) AS gauges(station_id, x, y))) WHERE status='ok'));
Land cover of the intervening drainage between a mid-valley gauge and the valley outlet: per class, outlet catchment area minus the nested upstream gauge's catchment area (1,500 m2 of class 10 and 1,800 m2 of class 20)
WITH gauges AS (SELECT * FROM (VALUES ('outlet', 500035.0, 4100005.0), ('mid', 500035.0, 4100035.0)) AS g(station_id, x, y)), cover AS (SELECT station_id, class_code, area_m2 FROM hydrology.main.landcover((SELECT station_id, geometry_wkb FROM hydrology.main.catchments((SELECT * FROM gauges)) WHERE status = 'ok'))) SELECT class_code, sum(area_m2) FILTER (WHERE station_id = 'outlet') AS outlet_area_m2, sum(area_m2) FILTER (WHERE station_id = 'mid') AS upstream_gauge_area_m2, outlet_area_m2 - upstream_gauge_area_m2 AS intervening_area_m2
FROM cover
GROUP BY class_code
ORDER BY class_code;
Try these queries
Dominant upstream land-cover class for four gauges on the synthetic valley: the two single-cell side gauges are pure class 10 (west) and class 20 (east), while the nested mid-valley gauge and the outlet are both mostly class 20
WITH basins AS (SELECT station_id, area_m2, geometry_wkb FROM hydrology.main.catchments((SELECT * FROM (VALUES ('west', 500015.0, 4100035.0), ('mid', 500035.0, 4100035.0), ('east', 500055.0, 4100035.0), ('outlet', 500035.0, 4100005.0)) AS gauges(station_id, x, y))) WHERE status = 'ok') SELECT b.station_id, b.area_m2, arg_max(l.class_code, l.area_m2) AS dominant_class, max(l.fraction_of_valid) AS dominant_share
FROM basins AS b
JOIN hydrology.main.landcover((SELECT station_id, geometry_wkb FROM basins)) AS l ON l.station_id = b.station_id
GROUP BY b.station_id, b.area_m2
ORDER BY b.station_id
Uses catchmentslandcover
Confirm the entire synthetic upstream area has classified land cover
SELECT sum(area_m2), min(coverage_fraction)
FROM hydrology.main.landcover((SELECT station_id, geometry_wkb FROM hydrology.main.catchments((SELECT * FROM (VALUES ('outlet', 500035.0, 4100005.0)) AS gauges(station_id, x, y))) WHERE status='ok'))
Uses landcovercatchments
Land cover of the intervening drainage between a mid-valley gauge and the valley outlet: per class, outlet catchment area minus the nested upstream gauge's catchment area (1,500 m2 of class 10 and 1,800 m2 of class 20)
WITH gauges AS (SELECT * FROM (VALUES ('outlet', 500035.0, 4100005.0), ('mid', 500035.0, 4100035.0)) AS g(station_id, x, y)), cover AS (SELECT station_id, class_code, area_m2 FROM hydrology.main.landcover((SELECT station_id, geometry_wkb FROM hydrology.main.catchments((SELECT * FROM gauges)) WHERE status = 'ok'))) SELECT class_code, sum(area_m2) FILTER (WHERE station_id = 'outlet') AS outlet_area_m2, sum(area_m2) FILTER (WHERE station_id = 'mid') AS upstream_gauge_area_m2, outlet_area_m2 - upstream_gauge_area_m2 AS intervening_area_m2
FROM cover
GROUP BY class_code
ORDER BY class_code
Uses landcovercatchments
Hydrology is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.
Related workers
Earth observation
Weather, ocean & earth
Optical index and calibrated radar histories for geospatial SQL queries
Earthquakes
Weather, ocean & earth
Live & historical USGS earthquake catalog as SQL tables in DuckDB — runs on Cloudflare Workers
NWS
Weather, ocean & earth
Explore US weather alerts, observations, forecast grids, bulletins, and river conditions