[postgis-users] Find out if polygon is circle

Brent Wood pcreso at pcreso.com
Thu Feb 5 10:56:25 PST 2015




> I have many different polygons in my database and would like to know if
> there's any way to find out if a polygon has the shape of a circle. I
> searched both on Google and in the Postgis documentation but couldn't find
> someone with the same question.
The "lines" joining the vertices of a polygon are straight - so implicitly any polygon defined by a sequence of points is NOT a circle, but might approximate one. Also, a reprojected circle may no longer be round. Any circle can be defined by three points, but a triangle is not a circle :-)

If what you are asking is whether each vertex in the polygon boundary is the same distance from the centroid - that might be done relatively easily.
Something along the lines of (off the top of my head - this will need work to work):select count(distinct(ST_Distance(ST_Centroid(geom),((ST_DumpPoints(ST_exteriorRing(geom))).geom)))) 

for each polygon get the vertices, then get the distance between each vertex & the centroid, then see how many distinct distances there are for each feature, if only one you have a circle - the distance being the radius.

If precision becomes a problem with near zero differences creating apparently different radii for the polygon, you can select where max(dist) - min(dist) < a_very_small_number instead of all being the same. 
Cheers

Brent Wood



  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20150205/2057b0df/attachment.html>


More information about the postgis-users mailing list