I have a gpx file. I mapped the route to a local openstreetmap (followed https://wiki.openstreetmap.org/wiki/Openlayers_Track_example example). My requirement is to get distance of the route. How can i achieve that? I need to achieve it programmatic-ally using javascript. Please help, Thanks. asked 15 May '14, 12:02 ErmaIsabel aseerel4c26 ♦ |
Hi Ermalsabel, the short answer : 1) Get a (free) copy of BaseCamp 2) Import your *.gpx file in BaseCamp 3) Right Click the file 4) Choose open. One of the statistics is the total lenght The long answer : 1) Get a (free) copy of eg GpsBabel 2) Convert the .gpx to .csv 3) Use a spreadsheet to calculate any statistic I use Excel but others will work. Calculating distances can be done with The haversine formula but also more straight forward with the spherical law of cosines if you use double precision variables. Also use double precision to calculate time and average speed if there are a few thousand data points in your *.Gpx log as adding increase the error proportionally. answered 15 May '14, 12:55 Gys de Jongh 3
Thank you very much for your reply.I need to achieve it programmatic-ally using javascript. Sorry my question doesn't explain much
(15 May '14, 13:08)
ErmaIsabel
|
Openlayers is a JavaScript lib that allows to show maps on websites. It also contains stuff to handle gpx data, and a few geometric functions that would very probably answer your need. answered 16 May '14, 18:04 yvecai |
GPX files are XML. Its been a while since I've played with Javascript so I can't remember if the XML calls I was using are built in or were part of a library. But anyway, your first step is parsing the GPX to get an array of data. You may find a bunch of "wpt" (waypoint) elements which you want to ignore. Then there can be one or more "trk" (track) elements that you are interested in. Each track element contains a bunch of "trkpt" elements with "lat" and "lon" attributes. You want to add the distances between each track element to get the total length of the track. However you don't want the angular distance summed: Convert it to feet/meters or what ever units you need first. There are some quick and dirty conversions you could do but you'll probably want to read up on the official equations for converting spherical coordinates to linear distances. Since that is just math, you can do it in Javascript. answered 16 May '14, 19:41 n76 |
What about an external solution (as gpsPrune for example), or does it need to be a webimplementation?
So there is no relation to OSM at all, right? It is just how to calculate the distance from a "route" inside a gpx file? OSM is just the background for viewing, right?