Functions / PostGIS / ST_PatchN
PostGISGeometry Accessors

ST_PatchN

What is ST_PatchN?

ST_PatchN is a PostGIS function that returns the Nth patch (polygon face) of a POLYHEDRALSURFACE or TIN geometry. Index is 1-based.

SQL
ST_PatchN(geometry g, integer n)geometry

Returns NULL for out-of-range indices or non-polyhedral input.

When would you use ST_PatchN?

Use ST_PatchN to access a specific face of a 3D surface — for example the roof polygon of a building model or a specific triangle of a TIN for detailed analysis:

SQL
1SELECT building_id,
2       ST_PatchN(surface_geom, 1) AS primary_face
3FROM buildings_3d;

For bulk iteration use ST_Dump, which also unpacks polyhedral surfaces into individual patches in modern PostGIS.

FAQs

How is ST_PatchN different from ST_GeometryN?

ST_GeometryN operates on collections and multi-geometries. ST_PatchN operates specifically on POLYHEDRALSURFACE and TIN patches. Use the appropriate accessor for the input type.

What type does ST_PatchN return?

A POLYGON geometry (or triangle for TIN) in the same SRID and dimensionality as the input.

Is the index 0- or 1-based?

1-based. Use ST_NumPatches(g) to bound valid indices.

When is this used in practice?

Almost exclusively in 3D workflows — BIM, CAD imports, architectural models, point-cloud triangulation. Pure 2D pipelines rarely touch it.