-
Notifications
You must be signed in to change notification settings - Fork 24
Description
Currently, no check is done on the range of values when either constructing or converting LLA
s or LatLon
s:
julia> using Geodesy
julia> p = LLA(lat=1000.0, lon=1000.0, alt=0.0)
LLA(lat=1000.0°, lon=1000.0°, alt=0.0)
julia> ECEF(p, wgs84)
ECEF(192951.75490366874, -1.0942837796485086e6, -6.25954296102869e6)
julia> ENU(p, p, wgs84)
ENU(0.0, 0.0, 0.0)
julia> UTMZ(p, wgs84)
UTMZ(NaN, NaN, 0.0, zone=polar (north))
(It appears the ECEF
conversion works as if the latitude wraps around over the pole, whilst clearly the UTM conversion needs valid latitudes.)
It is also the case that longitudes are compared as if they are linear numbers, when in reality they are periodic, and thus two points can represent the same position when n × 360° apart but not be 'equal':
julia> p1, p2 = LLA(0, 10, 0), LLA(0, 370, 0);
julia> p1 == p2
false
julia> ECEF(p1, wgs84) == ECEF(p2, wgs84)
true
This raises a few questions:
- Should latitudes be enforced to be in the correct range? I guess doing so in an inner constructor may reduce performance, but I haven't checked this.
- Should converting a permitted invalid latitude return nonsense values, an error, or a 'bad value' flag (as is currently done I think inadvertently for the UTM conversion)?
- Should longitudes:
a. be normalised to a range on construction (say [–180,180] or [0,360]); or
b. be compared modulo 360 when comparingLLA
s andLatLon
s; or
c. remain unnormalised and points only be equal when longitudes are strictly the same?
Letting the user make their own mistakes is an acceptable approach, but I think it should be noted carefully somewhere if this is the case. Alternatively, the safety net of bailing out when abs(latitude) > 90
is often worth the effort, not least since it quite often might catch cases of latitude and longitude being mixed up!
Happy to submit a PR for whichever route is best.
(My own preference would be for enforcement of -90 ≤ lat ≤ 90
in construction for LLA
s and LatLon
s, and modulo-360 comparison of longitudes. This allows one to keep longitudes around some arbitrary meridian.)