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)