ST_PointOnSurface — 计算保证位于多边形内或几何体上的点。
geometry ST_PointOnSurface(
geometry g1)
;
返回一个 POINT
它保证位于曲面(多边形、多重曲面和弯曲多边形)的内部。在PostGIS中,此功能也适用于线和点几何图形。
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。规范仅为曲面几何图形定义ST_PointOnSurface。PostGIS扩展了该功能,以支持所有常见的几何类型。其他数据库(Oracle、DB2、ArcSDE)似乎仅支持曲面的此功能。SQL Server 2008支持所有常见几何图形类型。
This function supports 3d and will not drop the z-index.
![]() 曲面上的点 | ![]() 曲面上的点 |
![]() 曲面上的点 | ![]() 曲面上的点 |
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)
示例: ST_PointOnSurface的结果保证位于面内,而由计算的点 ST_Centroid 可能在外面。
红色:面上的点;绿色:质心
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)