[postgis-users] st_centroid Points not on Polygon

pcreso at pcreso.com pcreso at pcreso.com
Fri May 1 16:57:58 PDT 2009


The answer is no.

For a convex polygon or one with holes, the centroid may well be outside the polygon.

What I typically do for this situation is create a point column in the polygon table & run an update to populate it with the centroid. Then run a second update calling 

ST_PointOnSurface(geom) where not contains(poly,point)

If I was being picky, I'd probaby run an intermediate update to try the centroid of the convex hull of the geometry first, then ST_PointOnSurface to clean up the remainder. Just to get centroids nearer the center than ST_PointOnSurface() may return.


 
HTH,

  Brent Wood



--- On Sat, 5/2/09, Paragon Corporation <lr at pcorp.us> wrote:

> From: Paragon Corporation <lr at pcorp.us>
> Subject: RE: [postgis-users] st_centroid Points not on Polygon
> To: "'PostGIS Users Discussion'" <postgis-users at postgis.refractions.net>
> Date: Saturday, May 2, 2009, 10:20 AM
> 
> Message
>  
>  
>  
> Stan,
> I think the answer is no. 
> For example if you have a 
> polygon with holes, the centroid may very well lie in the 
> hole.
>  
> Leo
> 
> 
> 
> From: 
> postgis-users-bounces at postgis.refractions.net 
> [mailto:postgis-users-bounces at postgis.refractions.net]
> On Behalf Of 
> Sufficool, Stanley
> Sent: Friday, May 01, 2009 4:53 
> PM
> To: PostGIS Users Discussion
> Subject: [postgis-users] 
> st_centroid Points not on Polygon
> 
> 
> 
> I'm sure I ran 
> across this in the forums a year ago,
> but:
>  
> Is the st_centroid 
> function guaranteed to return a point that lies on the
> polygon? I have instances 
> when my display doe not place it on the polygon when using 
> st_centroid(st_intersection(the_geom, <WKT
> BBOX>));
>  
> Thanks in 
> advance. 
> 
> -----Inline Attachment Follows-----
> 
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
> 



More information about the postgis-users mailing list