Re: PostGIS

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Sandeep Kumar Jakkaraju <sandeepkumar(dot)jakkaraju(at)gmail(dot)com>
Cc: b(dot)wood(at)niwa(dot)co(dot)nz, Postgresql <pgsql-general(at)postgresql(dot)org>
Subject: Re: PostGIS
Date: 2006-11-04 04:19:22
Message-ID: 20061104041922.GA73674@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Nov 02, 2006 at 09:11:58PM +0530, Sandeep Kumar Jakkaraju wrote:
> Like We have used the Haversine formula ...given on most of the websites ...
> to calculate the distance between to lat/lon points ..

You can examine the PostGIS source code to see how distance_sphere()
works; the underlying function is LWGEOM_distance_sphere() in
lwgeom/lwgeom_spheroid.c. The algorithm appears to be Haversine.

> which doesnt match with the distance given by distance_sphere() method

Could you post an example showing how you're calling distance_sphere(),
the output you get, and the output you get from other Haversine
functions? Several possibilities might explain the discrepancy:

1. If the difference is small then distance_sphere() might be using
a different value for the earth's radius than some other Haversine
function. The earth isn't a perfect sphere so simple functions use
approximations of the earth's radius and different functions might
use different values. distance_sphere() uses 6370986.884258304,
which is a reasonable (if overly precise) approximation of the
earth's radius in meters.

2. Make sure you're comparing the same units. A Haversine function
that returns distance in feet or miles won't return the same distance
as distance_sphere(), which returns meters.

3. Make sure your PostGIS geometries have coordinates in the correct
order: (X Y) which is (longitude latitude). This is a common cause
of problems for people accustomed to thinking (latitude longitude)
and who therefore create geometries as (Y X).

--
Michael Fuhr

In response to

  • Re: PostGIS at 2006-11-02 15:41:58 from Sandeep Kumar Jakkaraju

Browse pgsql-general by date

  From Date Subject
Next Message Shane Ambler 2006-11-04 04:33:14 Re: Can PostgreSQL reside on the same server as MSDE?
Previous Message Alexander Staubo 2006-11-03 22:08:47 Per-row security