postgis_sfcgal

postgis_sfcgal

postgis : PostGIS SFCGAL functions

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
1503
postgis_sfcgal
postgis
3.6.2
GIS
GPL-2.0
C
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--s-d-r
No
Yes
No
Yes
yes
no
Relationships
Requires
postgis
See Also
pgrouting
pointcloud
pointcloud_postgis
h3
h3_postgis
q3c
ogr_fdw
geoip
Siblings
postgis
postgis_topology
postgis_raster
postgis_tiger_geocoder
address_standardizer
address_standardizer_data_us

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXT
PGDG
3.6.2
18
17
16
15
14
postgispostgis
RPM
PGDG
3.6.2
18
17
16
15
14
postgis36_$v-
DEB
PGDG
3.6.2
18
17
16
15
14
postgresql-$v-postgis-3-
Linux / PGPG18PG17PG16PG15PG14
el8.x86_64
PGDG 3.6.1
PGDG 3.6.1
PGDG 3.6.1
PGDG 3.6.1
PGDG 3.6.1
el8.aarch64
PGDG 3.6.1
PGDG 3.6.1
PGDG 3.6.1
PGDG 3.6.1
PGDG 3.6.1
el9.x86_64
PGDG 3.6.2
PGDG 3.6.2
PGDG 3.6.2
PGDG 3.6.2
PGDG 3.6.2
el9.aarch64
PGDG 3.6.2
PGDG 3.6.2
PGDG 3.6.2
PGDG 3.6.2
PGDG 3.6.2
el10.x86_64
PGDG 3.6.2
PGDG 3.6.2
PGDG 3.6.2
PGDG 3.6.2
PGDG 3.6.2
el10.aarch64
PGDG 3.6.2
PGDG 3.6.2
PGDG 3.6.2
PGDG 3.6.2
PGDG 3.6.2
d12.x86_64
PGDG 3.6.2
PGDG 3.6.2
PGDG 3.6.2
PGDG 3.6.2
PGDG 3.6.2
d12.aarch64
PGDG 3.6.2
PGDG 3.6.2
PGDG 3.6.2
PGDG 3.6.2
PGDG 3.6.2
d13.x86_64
PGDG 3.6.2
PGDG 3.6.2
PGDG 3.6.2
PGDG 3.6.2
PGDG 3.6.2
d13.aarch64
PGDG 3.6.2
PGDG 3.6.2
PGDG 3.6.2
PGDG 3.6.2
PGDG 3.6.2
u22.x86_64
PGDG 3.6.2
PGDG 3.6.2
PGDG 3.6.2
PGDG 3.6.2
PGDG 3.6.2
u22.aarch64
PGDG 3.6.2
PGDG 3.6.2
PGDG 3.6.2
PGDG 3.6.2
PGDG 3.6.2
u24.x86_64
PGDG 3.6.2
PGDG 3.6.2
PGDG 3.6.2
PGDG 3.6.2
PGDG 3.6.2
u24.aarch64
PGDG 3.6.2
PGDG 3.6.2
PGDG 3.6.2
PGDG 3.6.2
PGDG 3.6.2

Source

Install

Make sure PGDG repo available:

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

Install this extension with pig:

pig install postgis;		# install via package name, for the active PG version
pig install postgis_sfcgal;		# install by extension name, for the current active PG version

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
pig install postgis_sfcgal -v 14;   # install for PG 14

Create this extension with:

CREATE EXTENSION postgis_sfcgal CASCADE; -- requires postgis

Usage

PostGIS SFCGAL: 3D geometry and advanced operations powered by SFCGAL

PostGIS SFCGAL provides advanced 2D and 3D spatial operations by wrapping the SFCGAL library. It adds support for 3D geometry operations, volume calculations, extrusion, tesselation, and other functions not available in the core PostGIS GEOS backend.

Setup

CREATE EXTENSION postgis_sfcgal;

3D Operations

3D Intersection and Difference

-- 3D intersection of two solids
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)))')
);

-- 3D difference
SELECT ST_3DDifference(solid_a, solid_b) FROM solids;

-- 3D union
SELECT ST_3DUnion(solid_a, solid_b) FROM solids;

3D Measurements

-- 3D area of a surface
SELECT ST_3DArea(geom) FROM surfaces;

-- Volume of a solid
SELECT ST_Volume(geom) FROM solids;

Extrusion

-- Extrude a 2D polygon into a 3D solid
SELECT ST_Extrude(
    ST_GeomFromText('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))'),
    0, 0, 10  -- dx, dy, dz
);

Tesselation and Triangulation

-- Tesselate a polygon into triangles
SELECT ST_Tesselate(
    ST_GeomFromText('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))')
);

-- Constrained Delaunay triangulation
SELECT ST_ConstrainedDelaunayTriangles(
    ST_GeomFromText('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))')
);

Other Functions

-- Straight skeleton of a polygon
SELECT ST_StraightSkeleton(
    ST_GeomFromText('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))')
);

-- Approximate medial axis
SELECT ST_ApproximateMedialAxis(
    ST_GeomFromText('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))')
);

-- Minkowski sum
SELECT ST_MinkowskiSum(
    ST_GeomFromText('LINESTRING(0 0, 4 0)'),
    ST_GeomFromText('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))')
);

-- Check planarity of a surface
SELECT ST_IsPlanar(geom) FROM surfaces;
Last updated on