Re: [GENERAL] earthdistance is not giving correct results.

2004-10-03 Thread Edmund Bacon
[EMAIL PROTECTED] (mike cox) writes:

 I'm running PostgreSQL 8.0 beta 1.  I'm using the
 earthdistance to find the distance between two
 different latitude and logitude locations. 
 Unfortunately, the result seems to be wrong.
 
 Here is what I'm doing:
 select
 earth_distance(ll_to_earth('122.55688','45.513746'),ll_to_earth('122.396357','47.648845'));
 
 The result I get is this:
 

I believe ll_to_earth() is expecting ll_to_earth(latitude, longitude), 

Also, I think earth_distance returns it's value in meters.

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


Re: [GENERAL] earthdistance is not giving correct results.

2004-10-03 Thread Jean-Luc Lachance
I agree, NS or EW long lat should be the same.
I was just pointing to the wrong figure.  Also, if ll_to_earth takes lat 
first, it should report an error for a |lat|  90...

Michael Fuhr wrote:
On Sat, Oct 02, 2004 at 09:29:16PM -0400, Jean-Luc Lachance wrote:
Maybe it would work with the right long  lat...
try
Protland OR -122.67555, 45.51184
Seattle WA -122.32956, 47.60342

It doesn't matter which hemisphere the longitudes are in as long
as they're in the same hemisphere:
test= select earth_distance(ll_to_earth('122.55688','45.513746'),ll_to_earth('122.396357','47.648845'));
  earth_distance  
--
 128862.563227506
(1 row)

test= select earth_distance(ll_to_earth('-122.55688','45.513746'),ll_to_earth('-122.396357','47.648845'));
  earth_distance  
--
 128862.563227506
(1 row)

What *does* matter is that one specify (lat, lon) instead of
(lon, lat):
test= select earth_distance(ll_to_earth('45.513746', '122.55688'),ll_to_earth('47.648845', '122.396357'));
  earth_distance  
--
 237996.256627247
(1 row)

That's 238km, or about 148mi; using your coordinates gives almost
the same answer, about 234km or 146mi.  As I said, the distance
between Portland and Seattle is around 150mi.

Also, do not forget that it is the line distance not the driving distance.

I doubt anybody thought that earth_distance() was calculating driving
distance.  How would it know what route to follow without an extensive
road database and a route specification?
---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
   (send unregister YourEmailAddressHere to [EMAIL PROTECTED])


Re: [GENERAL] earthdistance is not giving correct results.

2004-10-03 Thread Bruno Wolff III
On Sun, Oct 03, 2004 at 11:36:20 -0400,
  Jean-Luc Lachance [EMAIL PROTECTED] wrote:
 I agree, NS or EW long lat should be the same.
 I was just pointing to the wrong figure.  Also, if ll_to_earth takes lat 
 first, it should report an error for a |lat|  90...

I disagree with this. Latitudes greater than 90 degrees have a reasonable
meaning and it can be useful to use 0 to 180 instead of -90 to 90.
The same thing applies to longitude.

---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
  subscribe-nomail command to [EMAIL PROTECTED] so that your
  message can get through to the mailing list cleanly


[GENERAL] earthdistance is not giving correct results.

2004-10-02 Thread mike cox
I'm running PostgreSQL 8.0 beta 1.  I'm using the
earthdistance to find the distance between two
different latitude and logitude locations. 
Unfortunately, the result seems to be wrong.

Here is what I'm doing:
select
earth_distance(ll_to_earth('122.55688','45.513746'),ll_to_earth('122.396357','47.648845'));

The result I get is this:

128862.563227506

The distance from Portland to Seattle is not 128862
miles.






__
Do you Yahoo!?
Yahoo! Mail is new and improved - Check it out!
http://promotions.yahoo.com/new_mail

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


Re: [GENERAL] earthdistance is not giving correct results.

2004-10-02 Thread Tom Lane
mike cox [EMAIL PROTECTED] writes:
 The distance from Portland to Seattle is not 128862
 miles.

How about 128.8 kilometers?  The earthdistance docs say it's in meters
unless you've redefined the base unit.

regards, tom lane

---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster


Re: [GENERAL] earthdistance is not giving correct results.

2004-10-02 Thread Michael Fuhr
On Sat, Oct 02, 2004 at 07:09:25PM -0400, Tom Lane wrote:
 mike cox [EMAIL PROTECTED] writes:
  The distance from Portland to Seattle is not 128862
  miles.
 
 How about 128.8 kilometers?  The earthdistance docs say it's in meters
 unless you've redefined the base unit.

128.8 kilometers is about 80 miles; the distance from Portland to
Seattle is more like 150 miles.

  earth_distance(ll_to_earth('122.55688','45.513746'),ll_to_earth('122.396357','47.648845'));

I haven't played with earthdistance, but I'd guess that the arguments
to ll_to_earth should be (latitude, longitude) instead of (longitude,
latitude).

Here are some queries from my own implementation of the haversine
function, which is another way to measure distances on a sphere:

= select haversine(122.55688, 45.513746, 122.396357, 47.648845);
haversine 
--
 79.9258188445352

That distance is miles, which is almost exactly equivalent to the
128.8km figure from earth_distance().  Correcting the order of the
arguments gives this:

= select haversine(45.513746, 122.55688, 47.648845, 122.396357);
haversine 
--
 147.614987754694

That's more like the true distance in miles between Portland and
Seattle

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/

---(end of broadcast)---
TIP 8: explain analyze is your friend


Re: [GENERAL] earthdistance is not giving correct results.

2004-10-02 Thread Bruno Wolff III
On Sat, Oct 02, 2004 at 17:55:31 -0600,
  Michael Fuhr [EMAIL PROTECTED] wrote:
 On Sat, Oct 02, 2004 at 07:09:25PM -0400, Tom Lane wrote:
  mike cox [EMAIL PROTECTED] writes:
   The distance from Portland to Seattle is not 128862
   miles.
  
  How about 128.8 kilometers?  The earthdistance docs say it's in meters
  unless you've redefined the base unit.
 
 128.8 kilometers is about 80 miles; the distance from Portland to
 Seattle is more like 150 miles.
 
   earth_distance(ll_to_earth('122.55688','45.513746'),ll_to_earth('122.396357','47.648845'));
 
 I haven't played with earthdistance, but I'd guess that the arguments
 to ll_to_earth should be (latitude, longitude) instead of (longitude,
 latitude).

I double checked to make sure the README file says the right thing and it
does say that latitude is the first argument and longitude the second.
So it just looks like the arguments were given in the wrong order.

---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster


Re: [GENERAL] earthdistance is not giving correct results.

2004-10-02 Thread Jean-Luc Lachance
Maybe it would work with the right long  lat...
try
Protland OR -122.67555, 45.51184
Seattle WA -122.32956, 47.60342
Also, do not forget that it is the line distance not the driving distance.

Michael Fuhr wrote:
On Sat, Oct 02, 2004 at 07:09:25PM -0400, Tom Lane wrote:
mike cox [EMAIL PROTECTED] writes:
The distance from Portland to Seattle is not 128862
miles.
How about 128.8 kilometers?  The earthdistance docs say it's in meters
unless you've redefined the base unit.

128.8 kilometers is about 80 miles; the distance from Portland to
Seattle is more like 150 miles.

earth_distance(ll_to_earth('122.55688','45.513746'),ll_to_earth('122.396357','47.648845'));

I haven't played with earthdistance, but I'd guess that the arguments
to ll_to_earth should be (latitude, longitude) instead of (longitude,
latitude).
Here are some queries from my own implementation of the haversine
function, which is another way to measure distances on a sphere:
= select haversine(122.55688, 45.513746, 122.396357, 47.648845);
haversine 
--
 79.9258188445352

That distance is miles, which is almost exactly equivalent to the
128.8km figure from earth_distance().  Correcting the order of the
arguments gives this:
= select haversine(45.513746, 122.55688, 47.648845, 122.396357);
haversine 
--
 147.614987754694

That's more like the true distance in miles between Portland and
Seattle
---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


Re: [GENERAL] earthdistance is not giving correct results.

2004-10-02 Thread Michael Fuhr
On Sat, Oct 02, 2004 at 09:29:16PM -0400, Jean-Luc Lachance wrote:
 Maybe it would work with the right long  lat...
 try
 Protland OR -122.67555, 45.51184
 Seattle WA -122.32956, 47.60342

It doesn't matter which hemisphere the longitudes are in as long
as they're in the same hemisphere:

test= select 
earth_distance(ll_to_earth('122.55688','45.513746'),ll_to_earth('122.396357','47.648845'));
  earth_distance  
--
 128862.563227506
(1 row)

test= select 
earth_distance(ll_to_earth('-122.55688','45.513746'),ll_to_earth('-122.396357','47.648845'));
  earth_distance  
--
 128862.563227506
(1 row)

What *does* matter is that one specify (lat, lon) instead of
(lon, lat):

test= select earth_distance(ll_to_earth('45.513746', 
'122.55688'),ll_to_earth('47.648845', '122.396357'));
  earth_distance  
--
 237996.256627247
(1 row)

That's 238km, or about 148mi; using your coordinates gives almost
the same answer, about 234km or 146mi.  As I said, the distance
between Portland and Seattle is around 150mi.

 Also, do not forget that it is the line distance not the driving distance.

I doubt anybody thought that earth_distance() was calculating driving
distance.  How would it know what route to follow without an extensive
road database and a route specification?

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/

---(end of broadcast)---
TIP 9: the planner will ignore your desire to choose an index scan if your
  joining column's datatypes do not match


Re: [GENERAL] earthdistance is not giving correct results.

2004-10-02 Thread Tom Lane
Michael Fuhr [EMAIL PROTECTED] writes:
 What *does* matter is that one specify (lat, lon) instead of
 (lon, lat):

The earthdistance README does specify that latitude is the first
argument, but it doesn't get the function name right :-( ... it
says ll_to_cube instead of ll_to_earth.  Anyone want to go through
the file and fix any other obvious documentation errors?

regards, tom lane

---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faqs/FAQ.html