[postgis-users] Find out if polygon is circle

Rémi Cura remi.cura at gmail.com
Thu Feb 5 02:35:28 PST 2015


Hey,
your question is a little bit un-precise.
If you try to find circle that have been drawn by a CAD program for
instance (perfect circle),
you can use ST_LineToCurve().

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),
you can use a simplified Hough Transform.
(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).

(lastly, if you polygon may be so noisy that you want in fact to fit a
circle, which is another story)

I wrote an equivalent to ST_LineToCurve that has a precision parameter,
thus that will be robust if your circle are not perfect.
It is here
<https://github.com/Remi-C/PPPP_utilities/blob/aa802f136cc3768d987b77cb3a4d04e9f6a74344/postgis/arcs/rc_circularHoughTransform.sql>

In both case, what you get after calling ST_LineToCurve or rc_lineToCurve
is a geometry with potentially a mix of line and curve.
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 )

Cheers,
Rémi-C

2015-02-05 5:01 GMT+01:00 Paragon Corporation <lr at pcorp.us>:

> >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.
>
>
>
> 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
>
> A circle would be a circularstring with 3 points
>
>
>
> http://postgis.net/docs/manual-2.1/ST_LineToCurve.html
>
>
>
> e.g.
>
>
>
> SELECT ST_AsText(ST_LineToCurve(ST_Boundary(ST_Buffer(ST_Point(1,2),10))));
>
>
>
> --
>
> CIRCULARSTRING(11 2,-9 1.99999999999997,11 2)
>
>
>
>
>
>
>
>
>
> SELECT
> ST_GeometryType(ST_LineToCurve(ST_Boundary(ST_Buffer(ST_Point(1,2),10))));
>
>
>
> ST_CircularString
>
>
>
>
>
> If your geometry has any kind of curve, it should come back different
>
>
>
> So for example
>
>
>
> SELECT ST_GeometryType(ST_LineToCurve(ST_GeomFromText('LINESTRING(1 2, 3
> 4, 5 6, 7 8)')))
>
>
>
> ST_LineString
>
>
>
>
>
> Hope that helps,
>
> Regina
>
> http://www.postgis.us
>
> http://postgis.net
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at lists.osgeo.org
> http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20150205/927cd444/attachment.html>


More information about the postgis-users mailing list