Re: [GENERAL] Miidpoint between two long/lat points? (earthdistance?)

2011-05-26 Thread Carlo Stonebanks
Nicely done, Merlin! Hope others with the same problem can find this post.
Thanks a lot.

-Original Message-
From: Merlin Moncure [mailto:mmonc...@gmail.com] 
Sent: May 26, 2011 9:53 AM
To: Carlo Stonebanks
Cc: pgsql-general@postgresql.org
Subject: Re: [GENERAL] Miidpoint between two long/lat points?
(earthdistance?)

On Thu, May 26, 2011 at 12:05 AM, Merlin Moncure mmonc...@gmail.com wrote:
 Converted from javascript from here: http://en.wikipedia.org/wiki/Atan2

whoops! meant to say here:
http://www.movable-type.co.uk/scripts/latlong.html

merlin


-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] Miidpoint between two long/lat points? (earthdistance?)

2011-05-26 Thread Brent Wood
Why not install PostGIS with full ellipsoidal  projection support  use the 
azimuth  distance functions available in SQL?

Brent Wood

Brent Wood
DBA/GIS consultant
NIWA, Wellington
New Zealand
 Carlo Stonebanks  05/27/11 8:20 AM 
Nicely done, Merlin! Hope others with the same problem can find this post.
Thanks a lot.

-Original Message-
From: Merlin Moncure [mailto:mmonc...@gmail.com] 
Sent: May 26, 2011 9:53 AM
To: Carlo Stonebanks
Cc: pgsql-general@postgresql.org
Subject: Re: [GENERAL] Miidpoint between two long/lat points?
(earthdistance?)

On Thu, May 26, 2011 at 12:05 AM, Merlin Moncure  wrote:
 Converted from javascript from here: http://en.wikipedia.org/wiki/Atan2

whoops! meant to say here:
http://www.movable-type.co.uk/scripts/latlong.html

merlin


-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Please consider the environment before printing this email.

NIWA is the trading name of the National Institute of Water  Atmospheric 
Research Ltd.


Re: [GENERAL] Miidpoint between two long/lat points? (earthdistance?)

2011-05-26 Thread Merlin Moncure
On Thu, May 26, 2011 at 3:39 PM, Brent Wood b.w...@niwa.co.nz wrote:
 Why not install PostGIS with full ellipsoidal  projection support  use the
 azimuth  distance functions available in SQL?

installing postgis is a bit much if all you need to do are simple
distance calculations etc.

merlin

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] Miidpoint between two long/lat points? (earthdistance?)

2011-05-25 Thread Rick Genter
On Wed, May 25, 2011 at 9:47 AM, Carlo Stonebanks 
stonec.regis...@sympatico.ca wrote:

  I need to calculate the long/lat values between a line demarcated by two
 long/lat points.



 The points will be very close, but there is the 180 degree problem to
 consider, so a simple average won’t work.



 Does anyone know of a function or have a formula that will work using geo
 long/lat values? I don’t see anything obvious in the earthdistance module.


The simplest way to deal with the 180 degree problem is to remember that
you can add 360 degrees to a long and get a value that should continue to
work. So, assuming West is negative, -175 (175 degrees West) is the same
as -175+360 = 185 (185 degrees East). Then you don't have to worry about
wraparound. If the result is  180, subtract 360.
-- 
Rick Genter
rick.gen...@gmail.com


Re: [GENERAL] Miidpoint between two long/lat points? (earthdistance?)

2011-05-25 Thread Merlin Moncure
On Wed, May 25, 2011 at 12:47 PM, Carlo Stonebanks
stonec.regis...@sympatico.ca wrote:
 I need to calculate the long/lat values between a line demarcated by two
 long/lat points.



 The points will be very close, but there is the 180 degree problem to
 consider, so a simple average won’t work.



 Does anyone know of a function or have a formula that will work using geo
 long/lat values? I don’t see anything obvious in the earthdistance module.

Conerted from javascript from here: http://en.wikipedia.org/wiki/Atan2

btw i'm not huge fan of earthdistance module either -- it's easier to
just rig functions to do what you want.

merlin

create or replace function midpoint(
  lat1 float8,
  lon1 float8,
  lat2 float8,
  lon2 float8,
  lat_mid out float8,
  lon_mid out float8) returns record as
$$
   select
 atan2(sin(lat1)+sin(lat2),
sqrt( (cos(lat1)+Bx)*(cos(lat1)+Bx) + By*By) ) * 57.2957795,
 (lon1 + atan2(By, cos(lat1) + Bx)) * 57.2957795
 from
 (
select
  lat1,
  lat2,
  lon1,
  cos(lat2) * cos(dlon) as bx,
  cos(lat2) * sin(dlon) as by
  from
  (
select
$1 * 0.0174532925 as lat1,
$3 * 0.0174532925 as lat2,
$2 * 0.0174532925 as lon1,
($4 - $2) * 0.0174532925 as dlon
   ) q
  ) q;
$$ language sql immutable;

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general