postgis_sfcgal

PostGIS SFCGAL 函数

概览

扩展包名版本分类许可证语言
postgis3.6.4GISGPL-2.0C
ID扩展名BinLibLoadCreateTrustReloc模式
1500postgis-
1501postgis_topologytopology
1502postgis_raster-
1503postgis_sfcgal-
1504postgis_tiger_geocodertiger
1505address_standardizer-
1506address_standardizer_data_us-

版本

类型仓库版本PG 大版本包名依赖
EXTPGDG3.6.41817161514postgispostgis
RPMPGDG3.6.31817161514postgis36_$v-
DEBPGDG3.6.41817161514postgresql-$v-postgis-3-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64PGDG 3.6.3PGDG 3.6.3PGDG 3.6.3PGDG 3.6.3PGDG 3.6.3
el8.aarch64PGDG 3.6.3PGDG 3.6.3PGDG 3.6.3PGDG 3.6.3PGDG 3.6.3
el9.x86_64PGDG 3.6.3PGDG 3.6.3PGDG 3.6.3PGDG 3.6.3PGDG 3.6.3
el9.aarch64PGDG 3.6.3PGDG 3.6.3PGDG 3.6.3PGDG 3.6.3PGDG 3.6.3
el10.x86_64PGDG 3.6.3PGDG 3.6.3PGDG 3.6.3PGDG 3.6.3PGDG 3.6.3
el10.aarch64PGDG 3.6.3PGDG 3.6.3PGDG 3.6.3PGDG 3.6.3PGDG 3.6.3
d12.x86_64PGDG 3.6.4PGDG 3.6.4PGDG 3.6.4PGDG 3.6.4PGDG 3.6.4
d12.aarch64PGDG 3.6.4PGDG 3.6.4PGDG 3.6.4PGDG 3.6.4PGDG 3.6.4
d13.x86_64PGDG 3.6.4PGDG 3.6.4PGDG 3.6.4PGDG 3.6.4PGDG 3.6.4
d13.aarch64PGDG 3.6.4PGDG 3.6.4PGDG 3.6.4PGDG 3.6.4PGDG 3.6.4
u22.x86_64PGDG 3.6.4PGDG 3.6.4PGDG 3.6.4PGDG 3.6.4PGDG 3.6.4
u22.aarch64PGDG 3.6.4PGDG 3.6.4PGDG 3.6.4PGDG 3.6.4PGDG 3.6.4
u24.x86_64PGDG 3.6.4PGDG 3.6.4PGDG 3.6.4PGDG 3.6.4PGDG 3.6.4
u24.aarch64PGDG 3.6.4PGDG 3.6.4PGDG 3.6.4PGDG 3.6.4PGDG 3.6.4
u26.x86_64PGDG 3.6.4PGDG 3.6.4PGDG 3.6.4PGDG 3.6.4PGDG 3.6.4
u26.aarch64PGDG 3.6.4PGDG 3.6.4PGDG 3.6.4PGDG 3.6.4PGDG 3.6.4

安装

您可以直接安装 postgis 扩展包的预置二进制包,首先确保 PGDG 仓库已经添加并启用:

BASH
pig repo add pgdg -u          # 添加 PGDG 仓库并更新缓存

使用 pig 或者是 apt/yum/dnf 安装扩展:

安装
BASH
pig install postgis;          # 当前活跃 PG 版本安装
pig
BASH
pig ext install -y postgis -v 18  # PG 18
pig ext install -y postgis -v 17  # PG 17
pig ext install -y postgis -v 16  # PG 16
pig ext install -y postgis -v 15  # PG 15
pig ext install -y postgis -v 14  # PG 14
dnf
BASH
dnf install -y postgis36_18       # PG 18
dnf install -y postgis36_17       # PG 17
dnf install -y postgis36_16       # PG 16
dnf install -y postgis36_15       # PG 15
dnf install -y postgis36_14       # PG 14
apt
BASH
apt install -y postgresql-18-postgis-3   # PG 18
apt install -y postgresql-17-postgis-3   # PG 17
apt install -y postgresql-16-postgis-3   # PG 16
apt install -y postgresql-15-postgis-3   # PG 15
apt install -y postgresql-14-postgis-3   # PG 14

创建扩展

SQL
CREATE EXTENSION postgis_sfcgal CASCADE;  -- 依赖: postgis

用法

PostGIS SFCGAL:基于 SFCGAL 的三维几何与高级操作

PostGIS SFCGAL 通过封装 SFCGAL 库,提供高级的二维和三维空间操作。它增加了对三维几何运算、体积计算、拉伸、三角剖分等核心 PostGIS GEOS 后端不支持的功能。

安装

SQL
CREATE EXTENSION postgis_sfcgal;

三维操作

三维交集与差集

SQL
-- 两个实体的三维交集
SELECT ST_3DIntersection(
    ST_GeomFromText('POLYHEDRALSURFACE Z(((0 0 0,1 0 0,1 1 0,0 1 0,0 0 0)),((0 0 1,1 0 1,1 1 1,0 1 1,0 0 1)),((0 0 0,0 1 0,0 1 1,0 0 1,0 0 0)),((1 0 0,1 1 0,1 1 1,1 0 1,1 0 0)),((0 0 0,1 0 0,1 0 1,0 0 1,0 0 0)),((0 1 0,1 1 0,1 1 1,0 1 1,0 1 0)))'),
    ST_GeomFromText('POLYHEDRALSURFACE Z(((0.5 0.5 0.5,1.5 0.5 0.5,1.5 1.5 0.5,0.5 1.5 0.5,0.5 0.5 0.5)),((0.5 0.5 1.5,1.5 0.5 1.5,1.5 1.5 1.5,0.5 1.5 1.5,0.5 0.5 1.5)),((0.5 0.5 0.5,0.5 1.5 0.5,0.5 1.5 1.5,0.5 0.5 1.5,0.5 0.5 0.5)),((1.5 0.5 0.5,1.5 1.5 0.5,1.5 1.5 1.5,1.5 0.5 1.5,1.5 0.5 0.5)),((0.5 0.5 0.5,1.5 0.5 0.5,1.5 0.5 1.5,0.5 0.5 1.5,0.5 0.5 0.5)),((0.5 1.5 0.5,1.5 1.5 0.5,1.5 1.5 1.5,0.5 1.5 1.5,0.5 1.5 0.5)))')
);

-- 三维差集
SELECT ST_3DDifference(solid_a, solid_b) FROM solids;

-- 三维并集
SELECT ST_3DUnion(solid_a, solid_b) FROM solids;

三维度量

SQL
-- 曲面的三维面积
SELECT ST_3DArea(geom) FROM surfaces;

-- 实体的体积
SELECT ST_Volume(geom) FROM solids;

拉伸

SQL
-- 将二维多边形拉伸为三维实体
SELECT ST_Extrude(
    ST_GeomFromText('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))'),
    0, 0, 10  -- dx, dy, dz
);

细分与三角剖分

SQL
-- 将多边形细分为三角形
SELECT ST_Tesselate(
    ST_GeomFromText('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))')
);

-- 约束 Delaunay 三角剖分
SELECT ST_ConstrainedDelaunayTriangles(
    ST_GeomFromText('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))')
);

其他函数

SQL
-- 多边形的直骨架
SELECT ST_StraightSkeleton(
    ST_GeomFromText('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))')
);

-- 近似中轴线
SELECT ST_ApproximateMedialAxis(
    ST_GeomFromText('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))')
);

-- 闵可夫斯基和
SELECT ST_MinkowskiSum(
    ST_GeomFromText('LINESTRING(0 0, 4 0)'),
    ST_GeomFromText('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))')
);

-- 检查曲面是否为平面
SELECT ST_IsPlanar(geom) FROM surfaces;