qdgc
qdgc : Encode, decode, navigate, and fill Extended Quarter Degree Grid Cell codes in pure SQL.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 1700 | qdgc
|
qdgc
|
0.1.0 |
GIS
|
Apache-2.0
|
SQL
|
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
----dtr
|
No
|
No
|
No
|
Yes
|
yes
|
yes
|
| Relationships | |
|---|---|
| Need By | qdgc_postgis
|
| See Also | h3
pgrouting
pg_geohash
q3c
postgis_topology
pg_polyline
pg_eviltransform
mobilitydb
earthdistance
pointcloud
|
| Siblings | qdgc_postgis
|
PGXN distribution qdgc also ships qdgc_postgis; the GitHub v0.1.0 tag belongs to qdgc-py and is not this PGXN release.
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PIGSTY
|
0.1.0 |
18
17
16
15
14
|
qdgc |
- |
| RPM | PIGSTY
|
0.1.0 |
18
17
16
15
14
|
qdgc_$v |
- |
| DEB | PIGSTY
|
0.1.0 |
18
17
16
15
14
|
postgresql-$v-qdgc |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64
|
PIGSTY 0.1.0
|
PIGSTY 0.1.0
|
PIGSTY 0.1.0
|
PIGSTY 0.1.0
|
PIGSTY 0.1.0
|
el8.aarch64
|
PIGSTY 0.1.0
|
PIGSTY 0.1.0
|
PIGSTY 0.1.0
|
PIGSTY 0.1.0
|
PIGSTY 0.1.0
|
el9.x86_64
|
PIGSTY 0.1.0
|
PIGSTY 0.1.0
|
PIGSTY 0.1.0
|
PIGSTY 0.1.0
|
PIGSTY 0.1.0
|
el9.aarch64
|
PIGSTY 0.1.0
|
PIGSTY 0.1.0
|
PIGSTY 0.1.0
|
PIGSTY 0.1.0
|
PIGSTY 0.1.0
|
el10.x86_64
|
PIGSTY 0.1.0
|
PIGSTY 0.1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Y repo available:
pig repo add pgsql -u # add both repo and update cacheInstall this extension with pig:
pig install qdgc; # install via package name, for the active PG version
pig install qdgc -v 18; # install for PG 18
pig install qdgc -v 17; # install for PG 17
pig install qdgc -v 16; # install for PG 16
pig install qdgc -v 15; # install for PG 15
pig install qdgc -v 14; # install for PG 14Create this extension with:
CREATE EXTENSION qdgc;Usage
Sources:
- PGXN qdgc 0.1.0 release
- Official 0.1.0 README
- Official qdgc control file
- Official qdgc 0.1.0 extension SQL
qdgc 0.1.0 is the trusted, relocatable, pure-SQL core of the QDGC extension family. It encodes longitude and latitude as Extended Quarter Degree Grid Cell codes, decodes their bounds, navigates the prefix hierarchy, reports level metrics, and fills longitude/latitude bounding boxes. It has no PostGIS or compiled-library dependency; geometry, geography, and polygon-fill operations belong to the companion qdgc_postgis extension.
Core Workflow
CREATE EXTENSION qdgc;
-- qdgc_encode uses (longitude, latitude, level).
SELECT qdgc_encode(31.4, 2.7, 5);
-- E031N02ADBAC
-- The h3-style alias reverses the coordinate arguments.
SELECT qdgc_latlng_to_cell(2.7, 31.4, 5);
SELECT *
FROM qdgc_cell_to_bounds('E031N02ADBAC');
SELECT qdgc_cell_to_parent('E031N02ADBAC', 3);
SELECT * FROM qdgc_cell_to_children('E031N02AD', 5);QDGC hierarchy is encoded directly in the text: a child code begins with its parent code. That makes prefix filtering useful for rollups and descendant lookups:
CREATE TABLE observations (
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
qdgc_code text NOT NULL
);
CREATE INDEX observations_qdgc_idx ON observations (qdgc_code);
SELECT qdgc_cell_to_parent(qdgc_code, 3) AS level_3_cell,
count(*)
FROM observations
GROUP BY 1;
SELECT *
FROM observations
WHERE qdgc_code LIKE 'E031N02AB%';Bounding Boxes and Level Metrics
The core extension can enumerate rectangular coverage without PostGIS. Pass min_lon > max_lon for a box that crosses the antimeridian.
SELECT qdgc_bbox_cell_count(30.0, 1.0, 32.0, 3.0, 7);
SELECT *
FROM qdgc_bbox_to_cells(30.0, 1.0, 32.0, 3.0, 7);
SELECT qdgc_level_degrees(7);
SELECT qdgc_get_num_cells(7);
SELECT qdgc_average_cell_area(7, 2.0, 'km^2');
SELECT qdgc_version();qdgc_average_cell_area is a spherical estimate. Use qdgc_cell_area_km2 from qdgc_postgis when a cell-specific WGS84 spheroid measurement is required.
Important Objects
qdgc_encode(lon, lat, level)andqdgc_latlng_to_cell(lat, lng, level)create codes; the argument order is intentionally different.qdgc_is_valid_cell,qdgc_get_level,qdgc_cell_to_bounds,qdgc_cell_to_lonlat, andqdgc_cell_to_latlnginspect or decode a code.qdgc_cell_to_parentandqdgc_cell_to_childrennavigate the four-way prefix hierarchy.qdgc_bbox_to_cellsenumerates cells meeting a bounding box, whileqdgc_bbox_cell_countcalculates the count without materializing the set.qdgc_level_degrees,qdgc_get_num_cells, andqdgc_average_cell_areareport grid-level metrics.
Operational Notes
- Upstream requires PostgreSQL 13 or newer and tests PostgreSQL 13 through 17. PostgreSQL 18 is not part of the published 0.1.0 test matrix.
- The control file sets
trusted = trueandrelocatable = true. Noshared_preload_libraries,LOAD, server restart, or native library is required. - Relocatable functions call one another by unqualified name. Install
qdgcinto a schema on the activesearch_path; the defaultpublicschema satisfies this boundary. - Coordinates are longitude/latitude degrees.
qdgc_encodetakes longitude first, whileqdgc_latlng_to_celltakes latitude first. - Result cardinality grows by four for every additional child level. Count a bounding-box fill before materializing it, and avoid requesting deep descendants without a deliberate result-size bound.