qdgc_postgis
为 QDGC 增加 PostGIS geometry/geography 绑定与区域到网格单元的填充能力。
仓库
https://pgxn.org/dist/qdgc/0.1.0/
https://pgxn.org/dist/qdgc/0.1.0/
源码
qdgc-0.1.0.tar.gz
qdgc-0.1.0.tar.gz
概览
| 扩展包名 | 版本 | 分类 | 许可证 | 语言 |
|---|---|---|---|---|
qdgc | 0.1.0 | GIS | Apache-2.0 | SQL |
| ID | 扩展名 | Bin | Lib | Load | Create | Trust | Reloc | 模式 |
|---|---|---|---|---|---|---|---|---|
| 1700 | qdgc | 否 | 否 | 否 | 是 | 是 | 是 | - |
| 1710 | qdgc_postgis | 否 | 否 | 否 | 是 | 否 | 是 | - |
| 相关扩展 | qdgc postgis postgis h3 pg_geohash pgrouting q3c pg_polyline pg_eviltransform earthdistance mobilitydb |
|---|
版本
| 类型 | 仓库 | 版本 | PG 大版本 | 包名 | 依赖 |
|---|---|---|---|---|---|
| EXT | PIGSTY | 0.1.0 | 1817161514 | qdgc | qdgc, postgis |
| RPM | PIGSTY | 0.1.0 | 1817161514 | qdgc_$v | - |
| DEB | PIGSTY | 0.1.0 | 1817161514 | postgresql-$v-qdgc | - |
| OS / 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.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
| el10.aarch64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
| d12.x86_64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
| d12.aarch64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
| d13.x86_64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
| d13.aarch64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
| u22.x86_64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
| u22.aarch64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
| u24.x86_64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
| u24.aarch64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
| u26.x86_64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
| u26.aarch64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
构建
您可以使用 pig build 命令构建 qdgc 扩展的 RPM / DEB 包:
pig build pkg qdgc # 构建 RPM / DEB 包
安装
您可以直接安装 qdgc 扩展包的预置二进制包,首先确保 PGDG 和 PIGSTY 仓库已经添加并启用:
pig repo add pgsql -u # 添加仓库并更新缓存
使用 pig 或者是 apt/yum/dnf 安装扩展:
pig install qdgc; # 当前活跃 PG 版本安装
pig ext install -y qdgc -v 18 # PG 18
pig ext install -y qdgc -v 17 # PG 17
pig ext install -y qdgc -v 16 # PG 16
pig ext install -y qdgc -v 15 # PG 15
pig ext install -y qdgc -v 14 # PG 14
dnf install -y qdgc_18 # PG 18
dnf install -y qdgc_17 # PG 17
dnf install -y qdgc_16 # PG 16
dnf install -y qdgc_15 # PG 15
dnf install -y qdgc_14 # PG 14
apt install -y postgresql-18-qdgc # PG 18
apt install -y postgresql-17-qdgc # PG 17
apt install -y postgresql-16-qdgc # PG 16
apt install -y postgresql-15-qdgc # PG 15
apt install -y postgresql-14-qdgc # PG 14
创建扩展:
CREATE EXTENSION qdgc_postgis CASCADE; -- 依赖: qdgc, postgis
用法
来源:
qdgc_postgis 0.1.0 是纯 SQL 核心扩展 qdgc 的 PostGIS 伴生扩展。它可以在 QDGC 单元与 PostGIS 点、多边形之间转换,按 WGS84 椭球计算单元面积,并用 QDGC 单元填充任意 geometry。该扩展同时依赖 qdgc 与 postgis,不能替代其中任何一个。
核心流程
CREATE EXTENSION postgis;
CREATE EXTENSION qdgc;
CREATE EXTENSION qdgc_postgis;
SELECT qdgc_latlng_to_cell(
ST_SetSRID(ST_MakePoint(31.4, 2.7), 4326),
5
);
SELECT qdgc_cell_to_geometry('E031N02ADBAC');
SELECT qdgc_cell_to_boundary_geometry('E031N02ADBAC');
SELECT qdgc_cell_area_km2('E031N02ADBAC');
点 geometry 重载会把非零且非 4326 的 SRID 转换到 EPSG:4326;SRID 为零时,则假定输入已经是经纬度坐标。
填充关注区域
执行深层级填充前,应先估算结果规模:
WITH area AS (
SELECT ST_GeomFromText(
'POLYGON((31.0 2.0, 31.5 2.0, 31.5 2.5, 31.0 2.5, 31.0 2.0))',
4326
) AS geom
)
SELECT qdgc_estimate_cell_count(geom, 7)
FROM area;
WITH area AS (
SELECT ST_GeomFromText(
'POLYGON((31.0 2.0, 31.5 2.0, 31.5 2.5, 31.0 2.5, 31.0 2.0))',
4326
) AS geom
)
SELECT cell
FROM area
CROSS JOIN LATERAL qdgc_polygon_to_cells(
geom,
7,
'intersects'
) AS cell;
谓词可选值如下:
intersects是默认值,返回与输入 geometry 相交的单元;centroid返回中心点位于输入 geometry 内的单元;contains返回完全位于输入 geometry 内的单元。
实现采用可剪枝四叉树逐层下降,而不是测试 geometry 完整包围盒中的每个单元。多部件 geometry 会按部件分别填充,再合并单元集合。
重要对象
qdgc_latlng_to_cell(geometry, level)及其geography重载用于编码 PostGIS 点。qdgc_cell_to_geometry与qdgc_cell_to_geography返回单元中心点。qdgc_cell_to_boundary_geometry与qdgc_cell_to_boundary_geography返回矩形单元边界。qdgc_cell_area_km2在 WGS84 椭球上测量单元边界对应的 geography 面积。qdgc_polygon_to_cells按三种已记录谓词之一填充区域。qdgc_estimate_cell_count在真正生成填充结果前提供受包围盒上限约束的低成本估算。
运维说明
qdgc_postgis.control声明了requires = 'qdgc,postgis'与relocatable = true。应先由具备相应权限的角色安装 PostGIS,再把伴生扩展的使用交给普通用户。- 不需要
shared_preload_libraries、LOAD或重启。该扩展自身只有 SQL,但其 PostGIS 依赖包含本地代码。 qdgc、qdgc_postgis及其被调用依赖应安装到当前search_path可见的模式中,因为这些可迁移 SQL 函数使用未限定名称调用彼此。- 上游测试了 PostgreSQL 13–17;不能因为该扩展没有编译代码就推断 PostgreSQL 18 已获支持。
- 即使采用剪枝,深层级区域填充仍可能生成巨量结果。应把
qdgc_estimate_cell_count作为运维保护,并在调用qdgc_polygon_to_cells前施加应用侧规模限制。