postgis_sfcgal
PostGIS SFCGAL functions
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
postgis | 3.6.2 | GIS | GPL-2.0 | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 1500 | postgis | No | Yes | No | Yes | No | No | - |
| 1501 | postgis_topology | No | Yes | No | Yes | No | No | topology |
| 1502 | postgis_raster | No | Yes | No | Yes | No | No | - |
| 1503 | postgis_sfcgal | No | Yes | No | Yes | No | Yes | - |
| 1504 | postgis_tiger_geocoder | No | Yes | No | Yes | Yes | No | tiger |
| 1505 | address_standardizer | No | Yes | No | Yes | No | Yes | - |
| 1506 | address_standardizer_data_us | No | Yes | No | Yes | No | Yes | - |
| Related | postgis pgrouting pointcloud pointcloud_postgis h3 h3_postgis q3c ogr_fdw geoip |
|---|
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PGDG | 3.6.2 | 1817161514 | postgis | postgis |
| RPM | PGDG | 3.6.2 | 1817161514 | postgis36_$v | - |
| DEB | PGDG | 3.6.2 | 1817161514 | postgresql-$v-postgis-3 | - |
| OS / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| 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 |
Install
You can install postgis directly. First, make sure the PGDG repository is added and enabled:
pig repo add pgdg -u # Add PGDG repo and update cache
Install the extension using pig or apt/yum/dnf:
pig install postgis; # Install for current active PG version
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:
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;
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.