From: | Merlin Moncure <mmoncure(at)gmail(dot)com> |
---|---|
To: | Carlo Stonebanks <stonec(dot)register(at)sympatico(dot)ca> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Miidpoint between two long/lat points? (earthdistance?) |
Date: | 2011-05-26 05:05:25 |
Message-ID: | BANLkTincwYttuBEaHtc6=iJDFH28+c7m0A@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Wed, May 25, 2011 at 12:47 PM, Carlo Stonebanks
<stonec(dot)register(at)sympatico(dot)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;
From | Date | Subject | |
---|---|---|---|
Next Message | Alexander Farber | 2011-05-26 09:41:22 | Re: PostgreSQL 8.4.8 bringing my website down every evening |
Previous Message | Ben Chobot | 2011-05-26 04:15:41 | Re: temp files getting me down |