Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ trans = ENUfromLLA(origin_lla, wgs84)
point_enu = trans(point_lla)

# Equivalently
point_enu = ENU(point_enu, point_origin, wgs84)
point_enu = ENU(point_lla, origin_lla, wgs84)
```
The `NED` coordinate system is also available as an alternative to `ENU`, with
the same interface.

Similarly, we could convert to UTM/UPS coordinates, and two types are provided
for this - `UTM` stores 3D coordinates `x`, `y`, and `z` in an unspecified zone,
Expand Down Expand Up @@ -252,7 +254,8 @@ as the geodetic coordinates mentioned above, it's common to see
defining a terrestrial reference frame.
* The east,north and up **ENU** components of a Cartesian coordinate frame at a
particular point on the ellipsoid. This coordinate system is useful as a
local frame for navigation.
local frame for navigation. It is also common for navigation systems to use
north,east and down (**NED**) coordinates.
* Easting,northing and vertical components of a **projected coordinate system** or
[**map projection**](http://www.icsm.gov.au/mapping/about_projections.html).
There's an entire zoo of these, designed to represent the curved surface of an
Expand Down Expand Up @@ -325,10 +328,17 @@ projection about the corresponding pole, otherwise `zone` is an integer between

##### `ENU{T}` - east-north-up

The `ENU` type is a local Cartesian coordinate that encodes a point's distance
The `ENU` type stores local Cartesian coordinates that encode a point's distance
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the old text is fine. Whether a coordinate is a single encoding of position or only one of the numbers which encodes position is an age-old debate.

towards east `e`, towards north `n` and upwards `u` with respect to an
unspecified origin. Like `ECEF`, `ENU` is also a subtype of `StaticVector`.

##### `NED{T}` - north-east-down

The `NED` type is an alternative convention to `ENU`. It stores local Cartesian
coordinates that encode a point's distance towards north `n`, towards east `e`
and downwards `d` with respect to an unspecified origin. Like `ECEF`, `NED` is
also a subtype of `StaticVector`.

### Geodetic Datums

Geodetic datums are modelled as subtypes of the abstract type `Datum`. The
Expand Down Expand Up @@ -379,7 +389,7 @@ be pre-cached (for instance, the origin of an ENU transformation).

The `LLAfromECEF` and `ECEFfromLLA` transformations require an ellipsoidal datum
to perform the conversion. The exact transformation is performed in both directions,
using a port the ECEF → LLA transformation from *GeographicLib*.
using a port of the ECEF → LLA transformation from *GeographicLib*.

Note that in some cases where points are very close to the centre of the ellipsoid,
multiple equivalent `LLA` points are valid solutions to the transformation problem.
Expand All @@ -402,22 +412,24 @@ native Julia port of that used in *GeographicLib*, and is accurate to nanometers
for up to several UTM zones away from the reference meridian. However, the
series expansion diverges at ±90° from the reference meridian. While the `UTMZ`-methods
will automatically choose the canonical zone and hemisphere for the input,
extreme care must be taken to choose an appropriate zone for the `UTM` methods.
(In the future, we implement the exact UTM transformation as a fallback —
contributions welcome!)
extreme care must be taken to choose an appropriate zone for the `UTM` methods
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original text is correct—the proposed change is typographically not.

(In the future, we will implement the exact UTM transformation as a fallback —
contributions welcome!).

There is also `UTMfromUTMZ` and `UTMZfromUTM` transformations that are helpful
for converting between these two formats and putting data into the same `UTM`
zone.

#### To and from local `ENU` frames
#### To and from local `ENU` and `NED` frames

The `ECEFfromENU` and `ENUfromECEF` transformations define the transformation
around a specific origin. Both the origin coordinates as an `ECEF` as well as
its corresponding latitude and longitude are stored in the transformation for
maximal efficiency when performing multiple `transform`s. The transformation can
be inverted with `inv` to perform the reverse transformation with respect to the
same origin.
same origin. Moreover, the `ENUfromNED` transformation and its inverse `NEDfromENU`
can be used to change a local frame's orientation convention between `ENU` and `NED`,
while keeping the same origin.

#### Web Mercator support

Expand All @@ -443,11 +455,17 @@ These include:
* `ECEFfromUTM(zone, hemisphere, datum) = ECEFfromLLA(datum) ∘ LLAfromUTM(zone, hemisphere, datum)`
* `ENUfromLLA(origin, datum) = ENUfromECEF(origin, datum) ∘ ECEFfromLLA(datum)`
* `LLAfromENU(origin, datum) = LLAfromECEF(datum) ∘ ECEFfromENU(origin, datum)`
* `NEDfromLLA(origin, datum) = NEDfromENU() ∘ ENUfromECEF(origin, datum) ∘ ECEFfromLLA(datum)`
* `LLAfromNED(origin, datum) = LLAfromECEF(datum) ∘ ECEFfromENU(origin,datum) ∘ ENUfromNED()`
* `ECEFfromUTMZ(datum) = ECEFfromLLA(datum) ∘ LLAfromUTMZ(datum)`
* `ENUfromUTMZ(origin, datum) = ENUfromLLA(origin, datum) ∘ LLAfromUTMZ(datum`
* `UTMZfromENU(origin, datum) = UTMZfromLLA(datum) ∘ LLAfromENU(origin, datum)`
* `NEDfromUTMZ(origin, datum) = NEDfromLLA(origin, datum) ∘ LLAfromUTMZ(datum`
* `UTMZfromNED(origin, datum) = UTMZfromLLA(datum) ∘ LLAfromNED(origin, datum)`
* `UTMfromENU(origin, zone, hemisphere, datum) = UTMfromLLA(zone, hemisphere, datum) ∘ LLAfromENU(origin, datum)`
* `ENUfromUTM(origin, zone, hemisphere, datum) = ENUfromLLA(origin, datum) ∘ LLAfromUTM(zone, hemisphere, datum)`
* `UTMfromNED(origin, zone, hemisphere, datum) = UTMfromLLA(zone, hemisphere, datum) ∘ LLAfromNED(origin, datum)`
* `NEDfromUTM(origin, zone, hemisphere, datum) = NEDfromLLA(origin, datum) ∘ LLAfromUTM(zone, hemisphere, datum)`

Constructor-based transforms for these are also provided, such as `UTMZ(ecef, datum)`
which converts to `LLA` as an intermediary, as above. When converting multiple
Expand Down
8 changes: 5 additions & 3 deletions src/Geodesy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export
# Points
ECEF,
ENU,
NED,
LLA,
LatLon,
UTM,
Expand All @@ -38,9 +39,10 @@ export

# transformation methods
transform_deriv, transform_deriv_params, compose, ∘,
ECEFfromLLA, LLAfromECEF, ENUfromECEF, ECEFfromENU, ENUfromLLA, LLAfromENU,
UTMfromLLA, LLAfromUTM, UTMfromECEF, ECEFfromUTM, ENUfromUTM, UTMfromENU,
UTMZfromLLA, LLAfromUTMZ, UTMZfromECEF, ECEFfromUTMZ, ENUfromUTMZ, UTMZfromENU,
ECEFfromLLA, LLAfromECEF, ENUfromECEF, ECEFfromENU, ENUfromLLA, LLAfromENU,
ENUfromNED, NEDfromENU, NEDfromECEF, ECEFfromNED, NEDfromLLA, LLAfromNED,
UTMfromLLA, LLAfromUTM, UTMfromECEF, ECEFfromUTM, ENUfromUTM, UTMfromENU, NEDfromUTM, UTMfromNED,
UTMZfromLLA, LLAfromUTMZ, UTMZfromECEF, ECEFfromUTMZ, ENUfromUTMZ, UTMZfromENU, NEDfromUTMZ, UTMZfromNED,
UTMZfromUTM, UTMfromUTMZ,
WebMercatorfromLLA, LLAfromWebMercator,

Expand Down
44 changes: 42 additions & 2 deletions src/conversion.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@

############################
### Identity conversions ###
############################

ECEF(ecef::ECEF, datum) = ecef
LLA(lla::LLA, datum) = lla
ENU(enu::ENU, datum) = enu
NED(ned::NED, datum) = ned
UTM(utm::UTM, datum) = utm
UTMZ(utmz::UTMZ, datum) = utmz


################################
### ENU <-> NED coordinates ###
################################

ENU(ned::NED) = ENUfromNED()(ned)
NED(enu::ENU) = NEDfromENU()(enu)


################################
### LLA <-> ECEF coordinates ###
################################
Expand All @@ -23,10 +31,17 @@ LLA(ecef::ECEF, datum) = LLAfromECEF(datum)(ecef)
################################

ENU(ecef::ECEF, origin, datum) = ENUfromECEF(origin, datum)(ecef)

ECEF(enu::ENU, origin, datum) = ECEFfromENU(origin, datum)(enu)


################################
### ECEF <-> NED coordinates ###
################################

NED(ecef::ECEF, origin, datum) = NEDfromECEF(origin, datum)(ecef)
ECEF(ned::NED, origin, datum) = ECEFfromNED(origin, datum)(ned)


################################
### LLA <-> ENU coordinates ###
################################
Expand All @@ -35,6 +50,14 @@ ENU(lla::LLA, origin, datum) = ENUfromLLA(origin, datum)(lla)
LLA(enu::ENU, origin, datum) = LLAfromENU(origin, datum)(enu)


################################
### LLA <-> NED coordinates ###
################################

NED(lla::LLA, origin, datum) = NEDfromLLA(origin, datum)(lla)
LLA(ned::NED, origin, datum) = LLAfromNED(origin, datum)(ned)


################################
### LLA <-> UTMZ coordinates ###
################################
Expand All @@ -59,6 +82,14 @@ ENU(utm::UTMZ, origin, datum) = ENUfromUTMZ(origin, datum)(utm)
UTMZ(enu::ENU, origin, datum) = UTMZfromENU(origin, datum)(enu)


################################
### NED <-> UTMZ coordinates ###
################################

NED(utm::UTMZ, origin, datum) = NEDfromUTMZ(origin, datum)(utm)
UTMZ(ned::NED, origin, datum) = UTMZfromNED(origin, datum)(ned)


###############################
### LLA <-> UTM coordinates ###
###############################
Expand All @@ -82,6 +113,15 @@ UTM(ecef::ECEF, zone::Integer, hemisphere::Bool, datum) = UTMfromECEF(zone, hemi
ENU(utm::UTM, zone::Integer, hemisphere::Bool, origin, datum) = ENUfromUTM(origin, zone, hemisphere, datum)(utm)
UTM(enu::ENU, zone::Integer, hemisphere::Bool, origin, datum) = UTMfromENU(origin, zone, hemisphere, datum)(enu)


###############################
### NED <-> UTM coordinates ###
###############################

NED(utm::UTM, zone::Integer, hemisphere::Bool, origin, datum) = NEDfromUTM(origin, zone, hemisphere, datum)(utm)
UTM(ned::NED, zone::Integer, hemisphere::Bool, origin, datum) = UTMfromNED(origin, zone, hemisphere, datum)(ned)


###############################
### UTMZ <-> UTM coordinates ###
###############################
Expand Down
18 changes: 18 additions & 0 deletions src/points.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,24 @@ end
Base.show(io::IO, ::MIME"text/plain", enu::ENU) = print(io, "ENU($(enu.e), $(enu.n), $(enu.u))")


"""
NED(n, e, d = 0.0)

North-East-Down (NED) coordinates. A local Cartesian coordinate system, linearized about a reference point.
"""
struct NED{T <: Number} <: FieldVector{T}
n::T
e::T
d::T
end
NED(x :: T, y :: T) where {T} = NED(x, y, zero(T))
@inline function NED(x,y,z)
T = promote_type(promote_type(typeof(x),typeof(y)), typeof(z))
NED{T}(x,y,z)
end
Base.show(io::IO, ::MIME"text/plain", ned::NED) = print(io, "NED($(ned.n), $(ned.e), $(ned.d))")


"""
UTM(x, y, z = 0.0)

Expand Down
Loading