|
Project Information
|
=This project has moved to github https://github.com/tonymorris/geo-gpx A library for parsing GPS Exchange (GPX) files using HXT. Simple ExampleRemove waypointsRemove 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 ElevationThe 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 InteractionUpdate a GPX file with function combinatorsTakes a GPX file and applies the given list of functions and writes a new GPX file. The functions are:
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 ExampleVincenty DistanceThis 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 ExampleReport Total TimeThis 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 |