<div dir="ltr"><div><div><div><div><div><div><div><div>Hey,<br></div>your question is a little bit un-precise.<br></div>If you try to find circle that have been drawn by a CAD program for instance (perfect circle),<br></div>you can use ST_LineToCurve().<br><br></div>If you are trying to detect polygons that look like circle (maybe the border is very close to a circle, but overall it is really close to a circle),<br></div>you can use a simplified Hough Transform.<br></div>(for each 3 successive points in your exterior ring, compute the associated circle (centre + radius), then merge the results with a tolerance, then decide if it is a circle or not).<br></div><br></div><div>(lastly, if you polygon may be so noisy that you want in fact to fit a circle, which is another story)<br></div><div><br></div>I wrote an equivalent to ST_LineToCurve that has a precision parameter, thus that will be robust if your circle are not perfect.<br><div><div><div>It is <a href="https://github.com/Remi-C/PPPP_utilities/blob/aa802f136cc3768d987b77cb3a4d04e9f6a74344/postgis/arcs/rc_circularHoughTransform.sql">here</a><br></div><div><br>In both case, what you get after calling ST_LineToCurve or rc_lineToCurve is a geometry with potentially a mix of line and curve.<br>You must then define how to decide based on this results if you accept the polygon as a circle or not (or maybe return a "circleness" indice )<br><br>Cheers,<br>Rémi-C<br></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-02-05 5:01 GMT+01:00 Paragon Corporation <span dir="ltr"><<a href="mailto:lr@pcorp.us" target="_blank">lr@pcorp.us</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div link="#0563C1" vlink="#954F72" lang="EN-US"><div><span class=""><pre>>I have many different polygons in my database and would like to know if<u></u><u></u></pre></span><p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New"">there's any way to find out if a polygon has the shape of a circle. I<u></u><u></u></span></p><span class=""><p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New"">searched both on Google and in the Postgis documentation but couldn't find<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New"">someone with the same question.<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New""><u></u> <u></u></span></p></span><p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New"">One thought – use the ST_LineToCurve function and see if it comes back with a circularstring or one of the curved family of geometry types<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New"">A circle would be a circularstring with 3 points<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New""><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New""><a href="http://postgis.net/docs/manual-2.1/ST_LineToCurve.html" target="_blank">http://postgis.net/docs/manual-2.1/ST_LineToCurve.html</a><u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New""><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New"">e.g.<u></u><u></u></span></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">SELECT ST_AsText(ST_LineToCurve(ST_Boundary(ST_Buffer(ST_Point(1,2),10))));<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">--<u></u><u></u></p><p class="MsoNormal">CIRCULARSTRING(11 2,-9 1.99999999999997,11 2)<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">SELECT ST_GeometryType(ST_LineToCurve(ST_Boundary(ST_Buffer(ST_Point(1,2),10))));<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">ST_CircularString<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">If your geometry has any kind of curve, it should come back different<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">So for example<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">SELECT ST_GeometryType(ST_LineToCurve(ST_GeomFromText('LINESTRING(1 2, 3 4, 5 6, 7 8)')))<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">ST_LineString<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">Hope that helps,<u></u><u></u></p><p class="MsoNormal">Regina<u></u><u></u></p><p class="MsoNormal"><a href="http://www.postgis.us" target="_blank">http://www.postgis.us</a><u></u><u></u></p><p class="MsoNormal"><a href="http://postgis.net" target="_blank">http://postgis.net</a><u></u><u></u></p></div></div><br>_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@lists.osgeo.org">postgis-users@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users" target="_blank">http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users</a><br></blockquote></div><br></div>