My favorites | Sign in
Project Home Downloads Wiki
Project Information
Members

=This project has moved to github https://github.com/tonymorris/geo-gpx

A library for parsing GPS Exchange (GPX) files using HXT.

Simple Example

Remove waypoints

Remove all waypoints from a GPX file and write the result to a new file.

import Data.Geo.GPX

removeWaypoints :: FilePath -> FilePath -> IO ()
removeWaypoints = flip interactGpx removeWpts

Min/Max Elevation

The following is a complete example that finds the minimum and maximum elevation (ele) in a list of GPX files.

import Data.Geo.GPX
import Data.Maybe
import Control.Monad
import Control.Arrow

minMaxEle :: [FilePath] -> IO (Double, Double)
minMaxEle = fmap ((minimum &&& maximum) . (maybeToList . ele =<<) . (wpts =<<)) . readGpxFiles

Interaction

Update a GPX file with function combinators

Takes a GPX file and applies the given list of functions and writes a new GPX file. The functions are:

  1. Set the copyright element in the metadata with an author, year and license.
  2. Add a waypoint; see the home value below.
  3. Set the creator attribute of the gpx element.

import Data.Geo.GPX

interaction :: FilePath -> FilePath -> IO ()
interaction = flip interactsGpx [
                -- set the copyright in the metadata
                setCopyright' (copyrightType "Fred" (Just "2009") (Just "BSD3")), 
                -- add a waypoint (home)
                usingWpts (home:),
                -- set the creator
                setCreator "Me!"]

home :: WptType
home = setDesc' "My house" .
       setCmt' "I live here" .
       setEle' 326.7 $
       wptType' (latitudeType (-27.69301))
                (longitudeType 152.718)

Advanced Example

Vincenty Distance

This program requires an additional package (Geodetic).

This program computes the distance of tracks in a GPX file using Vincenty's inverse geodetic algorithm and prints out the name of the track and the result in metres.

import Control.Applicative
import Data.Geo hiding (lat, lon)
import Data.Geo.GPX

fileDistance :: FilePath -> IO [(Maybe String, Double)]
fileDistance = fmap distance . readGpxFile

distance :: [Gpx] -> [(Maybe String, Double)]
distance = fmap (name &&& foldl (\n (c, d) -> n + ellipsoidalDistance (inverse () c d)) 0 . (zip <*> tail) .
             (uncurry (!.!) . latlon <$>) . trkpts)

Advanced Example

Report Total Time

This program reports the start and end dates of track segments (trkseg) in a GPX file and computes the time difference.

import Data.Geo.GPX
import Data.Time
import Data.Maybe
import Text.XML.XSD.DateTime

startEnd :: FilePath -> IO (DateTime, DateTime)
startEnd = fmap ((minimum &&& maximum) . (maybeToList . time =<<) . (trkpts =<<)) . readGpxFile

report :: FilePath -> IO ()
report p = do (start, end) <- startEnd p
              print ("Start:        " ++ show start)
              print ("End:          " ++ show end)
              print ("Total Time:   " ++ show (uncurry diffUTCTime (toUTCTime end, toUTCTime start)))

Links

Powered by Google Project Hosting