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

Michael Smedberg Michael.Smedberg at redfin.com
Tue Oct 21 13:30:14 PDT 2008


Hey Lucas,

I'm not sure I 100% understand your question, but I think that you're
making an incorrect assumption.  When you " transform distance into
angle and make buffer directly in my SRID (4326)", I don't think that
the result will be a circle.

For instance, when you're near the North Pole, a degree of longitude is
shorter than a degree of latitude.  If you were, say, 2 degrees south of
the North Pole, and you drew a polygon around you that was one degree
away, the result would not be a circle, and would be shorter (as
measured in meters) in the East-West direction than in the North-South
direction, right?

In other words, I don't think you can draw a circle in 4326- a "circle"
in degrees isn't a circle in actual distance.

-----Original Message-----
From: postgis-users-bounces at postgis.refractions.net
[mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of
Lucas Antoine (External)
Sent: Monday, October 20, 2008 12:35 AM
To: 'postgis-users at postgis.refractions.net'
Subject: [postgis-users] making a circle with radius in meters,and
lat/lon position

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)
_______________________________________________
postgis-users mailing list
postgis-users at postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users




More information about the postgis-users mailing list