postgis_sfcgal

PostGIS SFCGAL 函数

概览

扩展包名版本分类许可证语言
postgis3.6.2GISGPL-2.0C
ID扩展名BinLibLoadCreateTrustReloc模式
1500postgis-
1501postgis_topologytopology
1502postgis_raster-
1503postgis_sfcgal-
1504postgis_tiger_geocodertiger
1505address_standardizer-
1506address_standardizer_data_us-
相关扩展postgis pgrouting pointcloud pointcloud_postgis h3 h3_postgis q3c ogr_fdw geoip

版本

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

安装

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

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

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

pig install postgis;          # 当前活跃 PG 版本安装
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 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 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

创建扩展

CREATE EXTENSION postgis_sfcgal CASCADE;  -- 依赖: postgis

用法

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

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

安装

CREATE EXTENSION postgis_sfcgal;

三维操作

三维交集与差集

-- 两个实体的三维交集
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;

三维度量

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

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

拉伸

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

细分与三角剖分

-- 将多边形细分为三角形
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))')
);

其他函数

-- 多边形的直骨架
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;

最后修改 2026-03-12: update extension pages (f579993)