ST_PointOnSurface — Computes a point guaranteed to lie in a polygon, or on a geometry.
geometry ST_PointOnSurface(geometry
g1);
Returns a POINT which is guaranteed to lie in the interior of a surface
(POLYGON, MULTIPOLYGON, and CURVEPOLYGON).
In PostGIS this function also works on line and point geometries.
This method implements the OGC Simple Features
Implementation Specification for SQL 1.1.
s3.2.14.2 // s3.2.18.2
This method implements the SQL/MM specification.
SQL-MM 3: 8.1.5, 9.5.6.
The specifications define ST_PointOnSurface for surface geometries only.
PostGIS extends the function to support all common geometry types.
Other databases (Oracle, DB2, ArcSDE) seem to support this function only for surfaces.
SQL Server 2008 supports all common geometry types.
This function supports 3d and will not drop the z-index.
Point on surface of a MultiPoint.
SELECT ST_PointOnSurface( 'MULTIPOINT (8 24,10 92,12 154,17 68,28 10,29 52,29 84,55 50,56 24,131 14,160 180,189 180)');
POINT(55 50)
Point on surface of a LineString.
SELECT ST_PointOnSurface( 'LINESTRING (190 160,10 190,40 90,20 70,10 10,30 40,30 10,110 40,70 10,110 10,140 40,140 10,160 30,180 10)');
POINT(40 90)
Point on surface of a Polygon.
SELECT ST_PointOnSurface( 'POLYGON ((190 190,10 190,10 10,190 10,190 20,160 30,60 30,60 130,190 140,190 190))');
POINT(35 80)
Point on surface of the highest-dimension components of a GeometryCollection.
SELECT ST_PointOnSurface(
'GEOMETRYCOLLECTION (POLYGON ((190 170,180 100,80 140,80 160,130 160,110 180,110 190,180 180,190 170)),
LINESTRING (80 120,120 20,140 70,150 30,180 50,190 10),
MULTIPOINT (19 150,22 49,30 13,32 101,45 35,67 88,75 16))');
POINT(133.571 150)
SELECT ST_PointOnSurface('LINESTRING(0 5 1,0 0 1,0 10 2)');
st_asewkt -------------- POINT(0 0 1) (1 row)
Example: The result of ST_PointOnSurface is guaranteed to lie within polygons, whereas the point computed by ST_Centroid may be outside.
SELECT ST_PointOnSurface(geom) AS pt_on_surf, ST_Centroid(geom) AS centroid
FROM (SELECT 'POLYGON ((130 120,120 190,30 140,50 20,190 20,
170 100,90 60,90 130,130 120))'::geometry AS geom) AS t;
pt_on_surf | centroid -----------------+--------------------------------------------- POINT(62.5 110) | POINT(100.18264840182648 85.11415525114155)