geodetics-0.0.2: Terrestrial coordinate systems and associated calculations.

Safe HaskellNone




Geodetic Coordinates

data Ellipsoid e => Geodetic e Source

Defines a three-D position on or around the Earth using latitude, longitude and altitude with respect to a specified ellipsoid, with positive directions being North and East. The default show instance gives position in degrees, minutes and seconds to 5 decimal places, which is a resolution of about 1m on the Earth's surface. Internally latitude and longitude are stored as double precision radians. Convert to degrees using e.g. latitude g /~ degree.

The functions here deal with altitude by assuming that the local height datum is always co-incident with the ellipsoid in use, even though the "mean sea level" (the usual height datum) can be tens of meters above or below the ellipsoid, and two ellipsoids can differ by similar amounts. This is because the altitude is usually known with reference to a local datum regardless of the ellipsoid in use, so it is simpler to preserve the altitude across all operations. However if you are working with ECEF coordinates from some other source then this may give you the wrong results, depending on the altitude correction your source has used.

There is no Eq instance because comparing two arbitrary co-ordinates on the Earth is a non-trivial exercise. Clearly if all the parameters are equal on the same ellipsoid then they are indeed in the same place. However if different ellipsoids are used then two co-ordinates with different numbers can still refer to the same physical location. If you want to find out if two co-ordinates are the same to within a given tolerance then use geometricDistance (or its squared variant to avoid an extra sqrt operation).


readGroundPosition :: Ellipsoid e => e -> String -> Maybe (Geodetic e)Source

Read the latitude and longitude of a ground position and return a Geodetic position on the specified ellipsoid.

The latitude and longitude may be in any of the following formats. The comma between latitude and longitude is optional in all cases. Latitude must always be first.

  • Signed decimal degrees: 34.52327, -46.23234
  • Decimal degrees NSEW: 34.52327N, 46.23234W
  • Degrees and decimal minutes (units optional): 34° 31.4' N, 46° 13.9'
  • Degrees, minutes and seconds (units optional): 34° 3' 23.52" N, 46° 1' 56.43" W
  • DDDMMSS format with optional leading zeros: 343123.52N, 0461356.43W

toLocal :: (Ellipsoid e1, Ellipsoid e2) => e2 -> Geodetic e1 -> Geodetic e2Source

Convert a position from any geodetic to another one, assuming local altitude stays constant.

toWGS84 :: Ellipsoid e => Geodetic e -> Geodetic WGS84Source

Convert a position from any geodetic to WGS84, assuming local altitude stays constant.

antipode :: Ellipsoid e => Geodetic e -> Geodetic eSource

The point on the Earth diametrically opposite the argument, with the same altitude.

geometricalDistance :: Ellipsoid e => Geodetic e -> Geodetic e -> Length DoubleSource

The absolute distance in a straight line between two geodetic points. They must be on the same ellipsoid. Note that this is not the geodetic distance taken by following the curvature of the earth.

geometricalDistanceSq :: Ellipsoid e => Geodetic e -> Geodetic e -> Area DoubleSource

The square of the absolute distance. Comes out as Area type of course.

groundDistance :: Ellipsoid e => Geodetic e -> Geodetic e -> Maybe (Length Double, Dimensionless Double, Dimensionless Double)Source

The shortest ellipsoidal distance between two points on the ground with reference to the same ellipsoid. Altitude is ignored.

The results are the distance between the points, the bearing of the second point from the first, and (180 degrees - the bearing of the first point from the second).

The algorithm can fail to converge where the arguments are near to antipodal. In this case it returns Nothing.

Uses Vincenty's formula. "Direct and inverse solutions of geodesics on the ellipsoid with application of nested equations". T. Vincenty. Survey Review XXII 176, April 1975. http:www.ngs.noaa.govPUBS_LIBinverse.pdf

properAngle :: Angle Double -> Angle DoubleSource

Add or subtract multiples of 2*pi so that for all t, -pi < properAngle t < pi.

showAngle :: Angle Double -> StringSource

Show an angle as degrees, minutes and seconds to two decimal places.

Earth Centred Earth Fixed Coordinates

type ECEF = Vec3 (Length Double)Source

Earth-centred, Earth-fixed coordinates as a vector. The origin and axes are not defined: use with caution.

geoToEarth :: Ellipsoid e => Geodetic e -> ECEFSource

Convert a geodetic coordinate into earth centered, relative to the ellipsoid in use.

earthToGeo :: Ellipsoid e => e -> ECEF -> (Angle Double, Angle Double, Length Double)Source

Convert an earth centred coordinate into a geodetic coordinate on the specified geoid.

Uses the closed form solution of H. Vermeille: Direct transformation from geocentric coordinates to geodetic coordinates. Journal of Geodesy Volume 76, Number 8 (2002), 451-454

Re-exported for convenience

data WGS84 Source

The WGS84 geoid, major radius 6378137.0 meters, flattening = 1 / 298.257223563 as defined in "Technical Manual DMA TM 8358.1 - Datums, Ellipsoids, Grids, and Grid Reference Systems" at the National Geospatial-Intelligence Agency (NGA).

The WGS84 has a special place in this library as the standard Ellipsoid against which all others are defined.