[postgis-users] How to add circle to Postgis database?

Brent Wood pcreso at pcreso.com
Wed Mar 7 10:59:10 PST 2007


Maciej Skorczewski wrote:
> hi i get this data and don't know hove add this to postgis database
> what type of geometry it is (MULTILINESTRING,POLYGON)?
> 
> 
> 
> center-X: -87.69581735217052,
> center-Y: 43.75183840008278
> Radius: 0.007124880185134723

Postgis doesn't (yet) support circle datatypes, just points, lines & polygons
as defined in the OGC SFS specification.

One way to approximate a circle is to define a polygon with vertices which
correspond to your circle perimiter.

To do this you can create a point at the centre location with your XY values &
then buffer this point (see the buffer function in the docs) with lots of
vertices using the radius.

There is unfortunately a nasty trap here, as the point will need to be
reprojected to a suitable equidistant or equal area projection to generate a
true circle, and the radius will need to be converted to the new projections
map units. This is because the distance represented by 1 degree of longitude
changes with latitude, decreasing away from the equator to 0 at the poles.


So it can sort of be done, but is not straightforward.


The SQL is along the lines of

select transform(buffer(transform(point,<new SRID>),<new distance>).4326) as
circle;

where 4326 is the SRID (probably) for your base lat long data. 



I hope this isn't too confusing :-)

  Brent Wood



More information about the postgis-users mailing list