pgh_consistency

Pfafstetter consistency checks for PgHydro

Overview

PackageVersionCategoryLicenseLanguage
pghydro6.6GISGPL-2.0SQL
IDExtensionBinLibLoadCreateTrustRelocSchema
1600pghydroNoNoNoYesNoNopghydro
1601pgh_rasterNoNoNoYesNoNopgh_raster
1602pgh_hgmNoNoNoYesNoNopgh_hgm
1603pgh_outputNoNoNoYesNoNopgh_output
1604pgh_output_en_auNoNoNoYesNoNopgh_output_en_au
1605pgh_output_pt_brNoNoNoYesNoNopgh_output_pt_br
1606pgh_consistencyNoNoNoYesNoNopgh_consistency
Relatedplpgsql postgis pghydro

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY6.61817161514pghydroplpgsql, postgis, pghydro
RPMPIGSTY6.61817161514pghydro_$vpostgis36_$v
DEBPIGSTY6.61817161514postgresql-$v-pghydropostgresql-$v-postgis-3
OS / PGPG18PG17PG16PG15PG14
el8.x86_64PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6
el8.aarch64PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6
el9.x86_64PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6
el9.aarch64PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6
el10.x86_64PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6
el10.aarch64PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6
d12.x86_64PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6
d12.aarch64PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6
d13.x86_64PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6
d13.aarch64PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6
u22.x86_64PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6
u22.aarch64PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6
u24.x86_64PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6
u24.aarch64PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6
u26.x86_64PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6
u26.aarch64PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6PIGSTY 6.6

Build

You can build the RPM / DEB packages for pghydro using pig build:

pig build pkg pghydro         # build RPM / DEB packages

Install

You can install pghydro directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:

pig repo add pgsql -u          # Add repo and update cache

Install the extension using pig or apt/yum/dnf:

pig install pghydro;          # Install for current active PG version
pig ext install -y pghydro -v 18  # PG 18
pig ext install -y pghydro -v 17  # PG 17
pig ext install -y pghydro -v 16  # PG 16
pig ext install -y pghydro -v 15  # PG 15
pig ext install -y pghydro -v 14  # PG 14
dnf install -y pghydro_18       # PG 18
dnf install -y pghydro_17       # PG 17
dnf install -y pghydro_16       # PG 16
dnf install -y pghydro_15       # PG 15
dnf install -y pghydro_14       # PG 14
apt install -y postgresql-18-pghydro   # PG 18
apt install -y postgresql-17-pghydro   # PG 17
apt install -y postgresql-16-pghydro   # PG 16
apt install -y postgresql-15-pghydro   # PG 15
apt install -y postgresql-14-pghydro   # PG 14

Create Extension:

CREATE EXTENSION pgh_consistency CASCADE;  -- requires: plpgsql, postgis, pghydro

Usage

Sources: PGHydro README, pgh_consistency SQL

pgh_consistency is a PgHydro companion extension for checking and cleaning hydrographic network data. It creates the pgh_consistency schema with quality-control tables and functions for drainage-line and drainage-area geometry, topology, and Pfafstetter consistency checks.

Enable

Install it after PostGIS and the core pghydro extension:

CREATE EXTENSION postgis;
CREATE EXTENSION pghydro;
CREATE EXTENSION pgh_consistency;

Inspect Check Tables

The extension stores findings in tables named after the issue being detected:

SELECT tablename
FROM pg_tables
WHERE schemaname = 'pgh_consistency'
ORDER BY tablename;

Examples include pghft_drainagelineisdisconnected, pghft_drainagelineisnotvalid, pghft_drainageareaisnotvalid, pghft_drainageareaoverlapdrainagearea, pghft_pointvalencevalue2, and pghft_pointdivergent.

Main Workflows

Use the functions in pgh_consistency to prepare and validate the drainage network before running analytical PgHydro routines. The SQL objects include helpers to split drainage lines at multipoints, snap drainage lines to a grid, remove repeated points, create drainage-line vertex intersections, break drainage lines, and detect invalid, non-simple, disconnected, overlapping, looping, or misclassified drainage features.

SELECT nspname, proname
FROM pg_proc p
JOIN pg_namespace n ON n.oid = p.pronamespace
WHERE nspname = 'pgh_consistency'
ORDER BY proname;

Notes

The extension assumes PgHydro’s base drainage tables are already populated. Run consistency checks before exporting or calculating higher-level hydrological products so invalid geometries and broken network links are visible early.


Last Modified 2026-07-02: extension update 2026-07-02 (f9f0d13)