How can I find a point that is guaranteed to be within a given polygon in PostGIS?
I am aware of the ST_Centroid
function. However, the centroid is not always within a polygon, see below:
Furthermore, I would like to avoid using a point that is on the polygon boundary, but rather want one that is inside the boundary (and not inside a hole in donut shaped polygons).
Answer
If you're looking for a PostGIS function that will tell you a point that's inside your polygon then the ST_PointOnSurface function may give you what you need.
SELECT
ST_AsText(ST_PointOnSurface('POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))'::geometry));
st_astext
----------------
POINT(2.5 2.5)
(1 row)
No comments:
Post a Comment