Skip to content

postgis_sfcgal

PostGIS SFCGAL functions

postgis · PostGIS SFCGAL functions

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
1503postgis_sfcgalpostgis3.7.0GISGPL-2.0C
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--s-d-rNoYesNoYesyesno
Pigsty fills EL8 gaps.

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
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

Source

pig build pkg postgis;		# build rpm/deb

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 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 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;

Table reader