navit-project.org
http://forum.navit-project.org/

Script to converting of gpx track to navit map under android
http://forum.navit-project.org/viewtopic.php?f=6&t=550
Page 1 of 1

Author:  NavitNutzer [ 11 Apr 2015, 17:23 ]
Post subject:  Script to converting of gpx track to navit map under android

This small scripts creates navit map from downloaded gpx.
You need to install QPython to be able to start it, I have saved it on common path of qpython scripts.
The navit map has to be added to navit.xml:
Code:
<map type="textfile" enabled="yes" data="/sdcard/navit/NavitRoute.txt"/>

Then first one has to download gpx (usually it is saved to “/sdcard/Download”)
Then one need to start the script: it does following:
-it reads any gpx file from downloaded directory (any means any: if there are few tracs I do not know which will be opened),
-it converts it to navit map and saves to NavitRoute.txt, if file is present it will be overwritten.
-it deletes also converted gpx track.

Script is strictly tailored to my wishes:
It is overwriting and deleting without any confirmation. Paths are hard coded, so I am not asked for anything.


Code:
import sys
import os
import re
from xml.dom.minidom import parseString

gpxpath=""
for dirname, dirnames, filenames in os.walk('/sdcard/Download'):
    for filename in filenames:
        if '.gpx' in filename:   
            gpxpath= os.path.join(dirname, filename)
            print gpxpath
gpx = open(gpxpath,"r")
Data = gpx.read()
gpx.close()
os.remove(gpxpath)
Route = open("/sdcard/navit/NavitRoute.txt","w")
Route.write("type=track label=\"MeineRoute\" desc=\"\" type=\"\" length=\"\" count=\"\"")
dom = parseString(Data)
for i in range(dom.getElementsByTagName('trkpt').length):
    dataElement=dom.getElementsByTagName('trkpt')[i].toxml()
    Point=""
    m = re.search('lon=\"(\d+\.\d+)\"', dataElement)
    if m.group(1) is not None:
        Point =m.group(1)+" "
    m = re.search('lat=\"(\d+\.\d+)\"', dataElement)
    if m.group(1) is not None:
        Point +=m.group(1)+"\n"
    Route.write(Point)



Script is os independent, runs also under windows (python 2.x has to be present, and paths have to be adapted)

Author:  KaZeR [ 13 Apr 2015, 05:07 ]
Post subject:  Re: Script to converting of gpx track to navit map under and

Thanks NavitNutzer for sharing this.

Is the purpose to be able to follow a route from a downloaded GPX?

Author:  NavitNutzer [ 14 Apr 2015, 17:58 ]
Post subject:  Re: Script to converting of gpx track to navit map under and

never used.
what about this:
http://wiki.navit-project.org/index.php/OSD
search for "route_guard"

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/