跳转到主要内容

postgis_sfcgal

PostGIS SFCGAL 函数

postgis · PostGIS SFCGAL 函数

概览

ID扩展软件包版本类别许可证编程语言
1503postgis_sfcgalpostgis3.7.0GISGPL-2.0C
属性可执行文件动态库需要预加载需要建扩展可迁移可信
--s-d-r否是否是是否
Pigsty fills EL8 gaps.

软件包

类型仓库版本兼容的 PostgreSQL 大版本包名模式依赖
EXTPGDG3.7.019 18 17 16 15postgispostgis
RPMPGDG3.7.019 18 17 16 15postgis37_$v-
DEBPGDG3.7.019 18 17 16 15postgresql-$v-postgis-3-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 3.7.0PIGSTY 3.7.0PIGSTY 3.7.0PIGSTY 3.7.0
el8.aarch64N/APIGSTY 3.7.0PIGSTY 3.7.0PIGSTY 3.7.0PIGSTY 3.7.0
el9.x86_64PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0
el9.aarch64PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0
el10.x86_64PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0
el10.aarch64PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0
d12.x86_64PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0
d12.aarch64PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0
d13.x86_64PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0
d13.aarch64PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0
u22.x86_64PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0
u22.aarch64PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0
u24.x86_64PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0
u24.aarch64PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0
u26.x86_64PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0
u26.aarch64PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0PGDG 3.7.0

源码

postgis37-filter-requires-perl-Pg.sh

pig build pkg postgis;		# build rpm/deb

安装

启用 PGDG 仓库 并更新缓存。

pig repo add pgdg -u    # add pgdg repo and update cache

使用 pig 安装扩展。

pig install postgis;		# install by package name
pig install postgis_sfcgal;		# install by extension name

pig install postgis_sfcgal -v 19;   # install for PG 19
pig install postgis_sfcgal -v 18;   # install for PG 18
pig install postgis_sfcgal -v 17;   # install for PG 17
pig install postgis_sfcgal -v 16;   # install for PG 16
pig install postgis_sfcgal -v 15;   # install for PG 15

在数据库中创建扩展。

CREATE EXTENSION postgis_sfcgal CASCADE; -- requires 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;

表格阅读器