gps-0.3.0: For manipulating GPS coordinates and trails.




Author: Thomas DuBuisson Copyright: Thomas DuBuisson License: BSD3

A basic GPS library with calculations for distance and speed along with helper functions for filtering/smoothing trails. All distances are in meters and time is in seconds. Speed is thus meters/second

The current intent of this library is to 1) Provide a standard type class interface for coordinates 2) Include fleshed out support for relevant libraries, a task too often neglected in modern Hackage packages.

Integration includes KML support via the xml package, pretty printing, anb binary.


Types and Classes

class Coordinate a whereSource

A coordinate is a place on earths surface. While twoDMS and fromDMS are the only required functions, coordinate systems may provide more accurate calculations of heading, distance, and vectors without the intermediate translation.


toDMS :: a -> DMSCoordinateSource

fromDMS :: DMSCoordinate -> aSource

distance :: a -> a -> DistanceSource

heading :: a -> a -> HeadingSource

getVector :: a -> a -> VectorSource

class Coordinate coord => Location loc coord time | loc -> coord, loc -> time whereSource

A location is a coordinate at a specific time


getCoordinate :: loc -> coordSource

getTime :: loc -> timeSource

getUTC :: loc -> UTCTimeSource

speed :: loc -> loc -> SpeedSource


data DMSCoordinate Source

DMSCoordinate is the typical degree minute second for latitude/longitude used by most civilian GPS devices.



data DMS a Source

DMS is the degrees, minutes, seconds used for both latitude and longitude




Eq (DMS a) 
Ord (DMS a) 
Read (DMS a) 
Show (DMS a) 

data Latitude Source

Empty declaration for phantom type

data Longitude Source

Empty declaration for phantom type

type Heading = DoubleSource

Angles are expressed in radians from North. 0 == North pi/2 == West pi == South (32)pi == East == - (pi 2)

type Speed = DoubleSource

Speed is hard coded as meters per second

type Vector = (Distance, Heading)Source

type Trail a = [a]Source


radiusOfEarth :: DoubleSource

radius of the earth in meters

Helper Functions

smoothTrails :: Location a b c => Speed -> Trail a -> [Trail a]Source

'smoothTrails speed trail' should separate points that would mandate a speed in excess of the given rate into separate Trails. No point are deleted; if there is only one correct trail expected then the largest resulting trail will likely be the one your looking for.

longestSmoothTrail :: Location a b c => Speed -> Trail a -> Trail aSource

longestSmoothTrail is ust smoothTrails returning only the longest smooth trail.

restLocations :: Location a b c => Distance -> NominalDiffTime -> Trail a -> [Trail a]Source

closestDistance :: Coordinate a => Trail a -> Trail a -> Maybe DistanceSource

Returns the closest distance between two trails (or Nothing if a trail is empty) O( (n * m) * log (n * m) )

normalizeDMS :: DMSCoordinate -> DMSCoordinateSource

Typically useful for printing, normalizes degreesminutesseconds into just degrees and decimal minutes: DMSCoord (DMS 45 36.938455 0) (DMS ...)

dmsToDegreePair :: DMSCoordinate -> (Double, Double)Source

Provides a lat/lon pair of doubles in degrees

dmsToRadianPair :: DMSCoordinate -> (Double, Double)Source

Provides a lat/lon pair of doubles in radians

addVector :: Vector -> DMSCoordinate -> DMSCoordinateSource

Given a vector and coordinate, computes a new DMS coordinate. within some epsilon it should hold that if dest = addVector (dist,heading) start then heading == dmsHeading start dest dist == distance start dest