Re: earthdistance compass bearing

From: John R Pierce <pierce(at)hogranch(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: earthdistance compass bearing
Date: 2013-06-18 19:09:59
Message-ID: 51C0B087.3080006@hogranch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 6/18/2013 11:16 AM, Jeff Herrin wrote:
> I don't need it to be too accurate. We're pushing hotel info into the
> GDS (sabre, expedia, orbitz, etc). They require airport info relative
> to the hotel. Example: DFW is 25 miles NW of the property. I thought
> about just faking it...comparing the hotel's lat/long from the
> airports. I can probably get N,S,E,W reliably enough, but i'm not sure
> at what point N becomes NW, etc. That just seems like a really crude
> bad way to do it, but the alternatives seem unnecessarily complex. I
> found some examples that use bearing but they all take headings in
> degrees (which im not seeing in earthdistance). I guess I'm going to
> have to either setup postGIS or brush up on my trig.

half the difference. like, if NW is 45 degrees, then its anything +/-
22.5 degrees of that.

if you're willing to accept the error in cartesian vs spherical, its
fairly simple. theta is asin(X/R) where X is the delta longitude,
and R is the radius, aka your earthdistance. asin returns radians, so
multiply by 180/pi() to get degrees. divide the degrees by 16/360 and
truncate to an integer, and you should get 0-15, index the string array
('N','NW','NW','W','W','SW','SW','S','S','SE','SE','E','E','NE','NE','N') to
get compass direction points. verify you got the polarity right on
the delta longitude such that 0 == North and 90 degrees == West.

--
john r pierce 37N 122W
somewhere on the middle of the left coast

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Steven Schlansker 2013-06-18 19:17:27 Index over only uncommon values in table
Previous Message Paul Ramsey 2013-06-18 18:58:57 Re: earthdistance compass bearing