ST_PatchN

更新时间:
复制 MD 格式

Returns the Nth face of a polyhedral surface geometry. Returns NULL for all other geometry types.

Syntax

geometry ST_PatchN(geometry geomA, integer n);

Parameters

ParameterDescription
geomAThe geometry object. Must be a polyhedral surface (POLYHEDRALSURFACE or POLYHEDRALSURFACEM).
nThe 1-based index of the face to return.

Usage notes

  • Indexing is 1-based. The first face has index 1, not 0.

  • Returns NULL if geomA is not a polyhedral surface.

  • Supports 3D geometries and preserves Z coordinates.

  • To extract all faces at once, use ST_Dump.

Example

-- Return the first face of a polyhedral surface
SELECT ST_AsText(
  ST_PatchN(
    'POLYHEDRALSURFACE(
      ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)),
      ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)),
      ((1 1 0, 1 1 1, 1 0 1, 1 0 0, 1 1 0)),
      ((0 1 0, 0 1 1, 1 1 1, 1 1 0, 0 1 0)),
      ((0 0 1, 1 0 1, 1 1 1, 0 1 1, 0 0 1))
    )'::geometry,
    1
  )
);

Output:

              st_astext
---------------------------------------------
 POLYGON Z ((0 0 0,0 0 1,0 1 1,0 1 0,0 0 0))
(1 row)

See also

  • ST_Dump — expands a geometry into a set of component geometries; more efficient for extracting all faces