Thread: earthdistance compass bearing
I'm trying to get a compass bearing (N,S,NW,etc) using earthdistance. I can successfully get the distance between 2 points using either the point or cube method, but I've been struggling with getting the bearing. Any tips?
thanks,
altimage
thanks,
altimage
On 6/18/2013 10:42 AM, Jeff Herrin wrote: > I'm trying to get a compass bearing (N,S,NW,etc) using earthdistance. > I can successfully get the distance between 2 points using either the > point or cube method, but I've been struggling with getting the > bearing. Any tips? calculating the angle between two points on the surface of a sphere is non-trivial. You'll probably need to use PostGIS for that, and the ST_Azimuth() function, which returns angle in radians betweeen two points (multiple by 180/PI to get degrees) -- john r pierce 37N 122W somewhere on the middle of the left coast
On 06/18/2013 10:42 AM, Jeff Herrin wrote:
p { margin: 0; } I'm trying to get a compass bearing (N,S,NW,etc) using earthdistance. I can successfully get the distance between 2 points using either the point or cube method, but I've been struggling with getting the bearing. Any tips?
PostGIS has some functions that may be of use but might be overkill depending on your use but I don't see anything in earthdistance.
What are you trying to solve?
It's one thing if you are looking for a one-degree-accurate magnetic-variation-compensated great-circle heading for a 6,000km flight using WGS84 projection (initial-heading, of course, as it will vary over the course of your travel).
If you just want to be accurate to eight compass-points over a few city-blocks then simple trig is probably more than sufficient.
Cheers,
Steve
On Tue, Jun 18, 2013 at 12:42 PM, Jeff Herrin <jeff@openhotel.com> wrote: > I'm trying to get a compass bearing (N,S,NW,etc) using earthdistance. I can > successfully get the distance between 2 points using either the point or > cube method, but I've been struggling with getting the bearing. Any tips? convert the code from here: http://www.movable-type.co.uk/scripts/latlong.html I previously showed how you could convert midpoint here: http://www.mail-archive.com/pgsql-general@postgresql.org/msg159460.html merlin
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.
thanks,
altimage
thanks,
altimage
From: "Steve Crawford" <scrawford@pinpointresearch.com>
To: "Jeff Herrin" <jeff@openhotel.com>
Cc: pgsql-general@postgresql.org
Sent: Tuesday, June 18, 2013 11:37:10 AM
Subject: Re: [GENERAL] earthdistance compass bearing
PostGIS has some functions that may be of use but might be overkill depending on your use but I don't see anything in earthdistance.
What are you trying to solve?
It's one thing if you are looking for a one-degree-accurate magnetic-variation-compensated great-circle heading for a 6,000km flight using WGS84 projection (initial-heading, of course, as it will vary over the course of your travel).
If you just want to be accurate to eight compass-points over a few city-blocks then simple trig is probably more than sufficient.
Cheers,
Steve
To: "Jeff Herrin" <jeff@openhotel.com>
Cc: pgsql-general@postgresql.org
Sent: Tuesday, June 18, 2013 11:37:10 AM
Subject: Re: [GENERAL] earthdistance compass bearing
On 06/18/2013 10:42 AM, Jeff Herrin wrote:
p { margin: 0; } I'm trying to get a compass bearing (N,S,NW,etc) using earthdistance. I can successfully get the distance between 2 points using either the point or cube method, but I've been struggling with getting the bearing. Any tips?
PostGIS has some functions that may be of use but might be overkill depending on your use but I don't see anything in earthdistance.
What are you trying to solve?
It's one thing if you are looking for a one-degree-accurate magnetic-variation-compensated great-circle heading for a 6,000km flight using WGS84 projection (initial-heading, of course, as it will vary over the course of your travel).
If you just want to be accurate to eight compass-points over a few city-blocks then simple trig is probably more than sufficient.
Cheers,
Steve
The code for azimuth on a sphere isn't so gnarly you couldn't whip it up in plpgsql, http://trac.osgeo.org/postgis/browser/trunk/liblwgeom/lwgeodetic.c#L924 P. -- Paul Ramsey http://cleverelephant.ca http://postgis.net On Tuesday, June 18, 2013 at 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 airportinfo relative to the hotel. Example: DFW is 25 miles NW of the property. I thought about just faking it...comparingthe hotel's lat/long from the airports. I can probably get N,S,E,W reliably enough, but i'm not sure at whatpoint N becomes NW, etc. That just seems like a really crude bad way to do it, but the alternatives seem unnecessarilycomplex. I found some examples that use bearing but they all take headings in degrees (which im not seeing inearthdistance). I guess I'm going to have to either setup postGIS or brush up on my trig. > > thanks, > altimage > > From: "Steve Crawford" <scrawford@pinpointresearch.com (mailto:scrawford@pinpointresearch.com)> > To: "Jeff Herrin" <jeff@openhotel.com (mailto:jeff@openhotel.com)> > Cc: pgsql-general@postgresql.org (mailto:pgsql-general@postgresql.org) > Sent: Tuesday, June 18, 2013 11:37:10 AM > Subject: Re: [GENERAL] earthdistance compass bearing > > On 06/18/2013 10:42 AM, Jeff Herrin wrote: > > I'm trying to get a compass bearing (N,S,NW,etc) using earthdistance. I can successfully get the distance between 2 pointsusing either the point or cube method, but I've been struggling with getting the bearing. Any tips? > > > PostGIS has some functions that may be of use but might be overkill depending on your use but I don't see anything in earthdistance. > > What are you trying to solve? > > It's one thing if you are looking for a one-degree-accurate magnetic-variation-compensated great-circle heading for a 6,000kmflight using WGS84 projection (initial-heading, of course, as it will vary over the course of your travel). > > If you just want to be accurate to eight compass-points over a few city-blocks then simple trig is probably more than sufficient. > > Cheers, > Steve
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
On 06/18/2013 11:16 AM, Jeff Herrin wrote:
p { margin: 0; } 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.
That's pretty easy to get "close enough" without burdensome calculations using some assumptions:
1. You are using true headings (no need to adjust for magnetic-variance).
2. You are using short (metro-area) distances.
3. You are limiting yourself to the eight principal positions on the compass rose (N, NW, W, SW, ...).
4. You are not operating at very high/low latitudes.
The eight points are at 45-degree intervals around the compass-rose so simple rounding is all that is needed. I.e. N is 0 +- 22.5 degrees, NW is 45+- 22.5 degrees, etc. A bit of basic math/trig will get close enough.
I wouldn't obsess on accuracy. A swath of 45-degrees at 25 (+- .5) miles is an area of nearly 20 square miles so it's not exactly turn-by-turn precision.
Cheers,
Steve