ST_PointOnSurface — Calcola un punto che si trova in un poligono o su una geometria.
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.
Questo metodo implementa le OGC Simple Features Implementation Specification for SQL 1.1. s3.2.14.2 // s3.2.18.2
Questo metodo implementa la specifica SQL/MM. SQL-MM 3: 8.1.5, 9.5.6. Le specifiche definiscono ST_PointOnSurface solo per le geometrie di superficie. PostGIS estende la funzione per supportare tutti i tipi di geometria più comuni. Altri database (Oracle, DB2, ArcSDE) sembrano supportare questa funzione solo per le superfici. SQL Server 2008 supporta tutti i tipi di geometria più comuni.
Questa funzione supporta il 3d e non distrugge gli z-index.
Punto sulla superficie di |
Punto sulla superficie di un |
Punto sulla superficie di un |
Punto sulla superficie di una |
SELECT ST_AsText(ST_PointOnSurface('POINT(0 5)'::geometry));
------------
POINT(0 5)
SELECT ST_AsText(ST_PointOnSurface('LINESTRING(0 5, 0 10)'::geometry));
------------
POINT(0 5)
SELECT ST_AsText(ST_PointOnSurface('POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))'::geometry));
----------------
POINT(2.5 2.5)
SELECT ST_AsEWKT(ST_PointOnSurface(ST_GeomFromEWKT('LINESTRING(0 5 1, 0 0 1, 0 10 2)')));
----------------
POINT(0 0 1)
Esempio: Il risultato di ST_PointOnSurface è garantito all'interno dei poligoni, mentre il punto calcolato da ST_Centroid può essere esterno.
Rosso: punto sulla superficie; verde: centroide
SELECT ST_AsText(ST_PointOnSurface(geom)) AS pt_on_surf,
ST_AsText(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)