[postgis-users] Calculation distance between two points

iKey eike.lueders at gmail.com
Wed Jan 19 07:11:31 PST 2011


Hi Nicklas,

thanks for your reply.

Your second version with casting to geographic coordinates works fine for
me. :)
I think on my own I'd never found this solution. ;)

Many thanks again!!

Best regards
Eike



Nicklas Avén wrote:
> 
> Hallo Eike
> 
> The issue here is, latitude-longitude vs longitude-latitude.
> 
> In PostGIS the order is longitude latitude
> 
> 
> So if you reverse the order of the coordinates you will get about 539
> meters.
> 
> What is right or wrong depends on which one is longitude and which one
> is latitude.
> 
> Another way to write your query in 1.5 is casting to geography
> 
> So, to compare the two orderings:
> 
> SELECT
>  ST_Distance('POINT(52.278888888889
> 8.0430555555556)'::geography,'POINT(52.2812598 8.036165)'::geography),
>  ST_Distance('POINT(8.0430555555556
> 52.278888888889)'::geography,'POINT(8.036165 52.2812598)'::geography)
> 
> 
> 
> 
> 
> HTH
> Nicklas
> 
> 
> 
> 
> On Wed, 2011-01-19 at 06:40 -0800, iKey wrote:
>> Dear Community,
>> 
>> I want to calculate the distance between two points with a postgres
>> query.
>> The point reference system of my DB is epsg 4326. As far as I know I have
>> to
>> transform them, because with
>> WGS84 4326 I can calculate the distance in radian only.
>> 
>> This is an example query in that I try to calculate the distance in
>> different ways, but with no luck so far :(
>> SELECT	ST_Distance(ST_Transform(ST_GeomFromText('POINT(52.278888888889
>> 8.0430555555556)',4326),
>> 900913),ST_Transform(ST_GeomFromText('POINT(52.2812598 8.036165)', 4326),
>> 900913))
>> 	,ST_Distance_Sphere(ST_GeomFromText('POINT(52.278888888889
>> 8.0430555555556)',4326), ST_GeomFromText('POINT(52.2812598 8.036165)',
>> 4326))
>> 	,ST_Distance_Spheroid(ST_GeomFromText('POINT(52.278888888889
>> 8.0430555555556)',4326), ST_GeomFromText('POINT(52.2812598 8.036165)',
>> 4326), 'SPHEROID["WGS 84",6378137,298.257223563]')
>> FROM pois 
>> LIMIT 1;
>> 
>> The results look like this
>> 818.392971975843;
>> 809.44384291019;
>> 805.637737963218
>> 
>> When i calculate the distance in GoogleEarth or GoogleMaps I get a result
>> about 538,06m, so I think there is going something wrong in my
>> calculation with postgres.
>> 
>> Does anyone has any ideas whats going wrong or what else I can try?
>> 
>> Best regards
>> Eike
> 
> 
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
> 
> 

-- 
View this message in context: http://old.nabble.com/Calculation-distance-between-two-points-tp30710456p30710748.html
Sent from the PostGIS - User mailing list archive at Nabble.com.




More information about the postgis-users mailing list