[postgis-users] making a circle with radius in meters, and lat/lon position

Lucas Antoine (External) Antoine.Lucas at external.thalesgroup.com
Mon Oct 20 00:35:19 PDT 2008


Hi all,

I am using postgis 1.2.1 and I would like to make a circle. I use meters
unit and lat/lon coordinate in SRID 4326.

I saw two solutions:
  * transform point to a meter-SRID 2163 then make a buffer in meters and
back transform in my SRID (4326)
  * transform distance into angle and make buffer directly in my SRID (4326)

To check result, I first watch all coords, then recompute center, and
compute distance between center and a circle point.

With function Distance: OK
with function distance_sphere: 27% too much !

I made some verification by hand and I find a result close to
distance_sphere; where is the mistake ?

Here is a sample:

-- SQL file
create table toto (id int4 );

SELECT ADDGEOMETRYCOLUMN('public', 'toto', 'area', 4326, 'GEOMETRY', 2);


-- insert a circle with 100 meter radius
--
-- with transform function
--
insert into toto (area) values (transform(
                                    Buffer(
                                        transform(
                                            GeomFromText('POINT(0.0
20)',4326), -- point in lat lon
                                            2163) -- point in meters coords
                                        ,100), -- circle in meters coords
                                    4326) );   -- circle in lat / lon

-- insert a circle with 100 meter radius
--
-- transform directly 100 meters to angle (approximation from 4326 model ?)
--
insert into toto (area) values ( Buffer(GeomFromText('POINT(0.0
20)',4326),100.0/(6376500.0*3.14159*2.0)*360.0  ) );

--
-- distance with transform function (coherent with transform circle)
--
select Distance( transform(ST_Centroid(area),2163),
                 transform(PointN(ExteriorRing(area),1),2163)) from toto;

     distance
------------------
  99.9998086273481  -> ok
 102.031862045723   -> ok
(2 rows)

--
-- distance with transform function (not coherent with transform circle)
--
select distance_sphere(ST_Centroid(area),PointN(ExteriorRing(area),1)) from
toto;
 distance_sphere
------------------
 127.779274484879   -> no ok !
 93.8880956491054
(2 rows)



More information about the postgis-users mailing list