Repository navigation
Releases
Releases · Query-farm/vgi-hydrology
v0.3.0
Full Changelog: v0.2.2...v0.3.0
v0.2.2
v0.2.1
v0.2.0
v0.1.0
First release of vgi-hydrology, a Python VGI worker that delineates upstream catchments from a DEM and summarizes their land cover, directly from SQL (DuckDB 2.0 / Haybarn with the vgi extension).
Functions
hydrology.main.catchments((SELECT station_id, x, y FROM stations), dem := ..., input_crs := ..., snap_radius_m := ..., min_stream_area_m2 := ...)— independently delineated upstream catchment polygons (WKB) per station from a depression-filled D8 network (PyFlwDir), with area, selected outlet and edge/missing-data completeness flags. Optional Euclidean stream-cell outlet snapping.hydrology.main.landcover((SELECT station_id, geometry_wkb FROM catchments), raster := ..., geometry_crs := ...)— categorical land-cover class counts, areas and coverage fractions per polygon (pixel-centre inclusion, no interpolation of classes).hydrology.main.demo_input— one demo monitoring station; a synthetic DEM and land-cover raster ship inside the wheel, so the demo needs no data or credentials.
Composed examples
- Dominant upstream class per nested gauge (on
catchments): delineate four gauges, feed the polygons tolandcover, join back andarg_maxby area — class 10 atwest, class 20 ateast,midandoutlet. - Intervening drainage land cover (on
landcover): add a mid-valley gauge todemo_input, delineate both nested catchments, and subtract per class to get the area draining only to the outlet (1,500 m² class 10, 1,800 m² class 20).
Install / quick start
Requires Python 3.13+ and uv.
git clone --branch v0.1.0 https://github.com/Query-farm/vgi-hydrology.git
cd vgi-hydrology
uv sync --locked
make demoSET 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;
ATTACH 'hydrology' (TYPE vgi,
LOCATION '/absolute/path/to/vgi-hydrology/.venv/bin/vgi-hydrology-worker');
SELECT * FROM hydrology.main.catchments((SELECT * FROM hydrology.main.demo_input));The signed wheel and sdist (cosign bundles, build provenance) are attached below. Not published to PyPI.
Known limits
- DEM must be north-up, projected, metre units; land cover must be a north-up categorical raster in a projected metre CRS. Pass
dem_crsfromcatchmentsasgeometry_crstolandcover. - Default window limits of 2 million cells for DEM and land cover.
- Upstream drainage analysis only — not flood inundation, hydraulic routing, discharge prediction or pollutant transport. DEM conditioning and local validation are dataset-specific.
- Outlet snapping is Euclidean; inspect snapped outlets in ambiguous valleys. Catchments touching the DEM edge or nodata are flagged as potentially incomplete.
- The first routing call in a fresh worker process pays a few seconds of Numba JIT compile.