Circles in PostGIS
But what if you have a geometry that you know is a circle created with the method above? There is no exact method as far as I know, but her comes a good approximation.
First we want the origo of the circle. ST_Centroid(geom) comes to handy. It returns the centeroid point of the geometry, in this case the origo of the circle.
To get the radius we pick out the first point in the polygon returned by ST_Buffer with PointN(ExteriorRing(geom),1).
We need to call ExteriorRing to get the polygon of geom since ST_Buffer does return type is a geometry and not a polygon. Then we calculate the distance betwen origo and the polygons first point with ST_distance_sphere. ST_distance_sphere always returns distance in meters.
All together:
circle=ST_Buffer(GeomFromEWKT('SRID=3021;POINT(1537619 6347866)'),
10000, 16)
origo=ST_Centroid(geom)
radius=ST_distance_sphere(PointN(ExteriorRing(geom),1), origo)
I use the swedish projection RT-90 which uses distances in meters to create the circle.
Comments