You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I'm a novice when it comes to cartography, so please have forbearance with this probably elementary question.
I want to calculate a heading (compass course), given two points defined by their latitude/longitude values. I found two potential ways of doing it, given the functionality available in pyproj. The following code illustrates this:
import numpy
import pyproj
# Two points in Eastern Sweden:
lat1 = 58.602780
lon1 = 16.113329
lat2 = 58.616085
lon2 = 16.097278
# Create a Proj object and a Geod object.
p = pyproj.Proj(proj='utm', zone=33, ellps='WGS84', preserve_units=False)
g = pyproj.Geod(ellps='WGS84')
# Get UTM coordinates for the two points.
utm_e1, utm_n1 = p(lon1, lat1)
utm_e2, utm_n2 = p(lon2, lat2)
# 1. Calculate the UTM easting and northing differences, and derive a heading from them.
d_utm_e = utm_e2 - utm_e1
d_utm_n = utm_n2 - utm_n1
heading_utm = numpy.degrees(numpy.arctan2(d_utm_e, d_utm_n))
# 2. Get the heading directly from the Geod.inv function.
heading_geod = g.inv(lon1, lat1, lon2, lat2)[0]
# Make headings fall in the interval [0.0, 360.0[
if heading_utm < 0.0:
heading_utm += 360.0
if heading_geod < 0.0:
heading_geod += 360.0
print('heading_utm = {0:.3f}'.format(heading_utm))
print('heading_geod = {0:.3f}'.format(heading_geod))
Unfortunately, the two approaches produce results that differ by about one degree:
Obviously, one of these methods (or even both) is unsuitable for the purpose. I'd like to understand why there is a difference, and which method is the better one. If neither is good, then what should I do instead?
The ultimate purpose of this is to find a method of verifying whether the heading data reported by a dGPS system is sufficiently accurate. The system measures position data and heading data, using two fundamentally different methods. The position measurement is done in the usual GPS way, based on time differences between signals from a number of GPS satellites. The heading measurement is based on a phase difference measurement, at two separate antennas, on the GPS carrier wave (we don't know any details beyond that). Our experience is that the position measurement is more reliable than the heading measurement. The heading is vital when converting latitude/longitude data into distances in meters in a coordinate system that is co-located with the vehicle in which the dGPS unit is installed.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi, I'm a novice when it comes to cartography, so please have forbearance with this probably elementary question.
I want to calculate a heading (compass course), given two points defined by their latitude/longitude values. I found two potential ways of doing it, given the functionality available in pyproj. The following code illustrates this:
Unfortunately, the two approaches produce results that differ by about one degree:
$ python3 headingTst.py
heading_utm = 326.865
heading_geod = 327.816
Obviously, one of these methods (or even both) is unsuitable for the purpose. I'd like to understand why there is a difference, and which method is the better one. If neither is good, then what should I do instead?
The ultimate purpose of this is to find a method of verifying whether the heading data reported by a dGPS system is sufficiently accurate. The system measures position data and heading data, using two fundamentally different methods. The position measurement is done in the usual GPS way, based on time differences between signals from a number of GPS satellites. The heading measurement is based on a phase difference measurement, at two separate antennas, on the GPS carrier wave (we don't know any details beyond that). Our experience is that the position measurement is more reliable than the heading measurement. The heading is vital when converting latitude/longitude data into distances in meters in a coordinate system that is co-located with the vehicle in which the dGPS unit is installed.
Beta Was this translation helpful? Give feedback.
All reactions