Navit2gpx: Unterschied zwischen den Versionen
Doc (Diskussion | Beiträge) (Die Seite wurde neu angelegt: == Navit2gpx == Da Navit seine Lesezeichen in der Datei bookmarks.txt in einem hex-Format im Bogenmaß abspeichert, hat stettberger aus dem Quellcode die Umrechnungsfo...) |
|||
| Zeile 3: | Zeile 3: | ||
Da Navit seine Lesezeichen in der Datei bookmarks.txt in einem hex-Format im Bogenmaß abspeichert, hat stettberger aus dem Quellcode die Umrechnungsformel auf "normale" Koordinaten herausgepfriemelt und das ganze in ein schönes Python-Script verpackt, welches dann gleich gpx-Koordinaten ausspuckt um in OSM verwendet zu werden. | Da Navit seine Lesezeichen in der Datei bookmarks.txt in einem hex-Format im Bogenmaß abspeichert, hat stettberger aus dem Quellcode die Umrechnungsformel auf "normale" Koordinaten herausgepfriemelt und das ganze in ein schönes Python-Script verpackt, welches dann gleich gpx-Koordinaten ausspuckt um in OSM verwendet zu werden. | ||
Hintergrund der Aktion: Doc ist mit seinem Rad öfters mal auf "unbekanntem" Gelände unterwegs und auf diese Weise kann man nicht kartografierte Ortschaften zumindest mal als existent in OSM eintragen (:razz:) | Hintergrund der Aktion: Doc ist mit seinem Rad öfters mal auf "unbekanntem" Gelände unterwegs und auf diese Weise kann man nicht kartografierte Ortschaften zumindest mal als existent in OSM eintragen (:razz:) | ||
| + | |||
| + | #!/usr/bin/python | ||
| + | |||
| + | import sys, math, re | ||
| + | |||
| + | def parse_bookmark(b): | ||
| + | m = re.match('mg:(-?)0x(.*) (-?)0x(.*) type=bookmark label="(.*)"', b) | ||
| + | if m: | ||
| + | long = int(m.group(1)+m.group(2), 16) | ||
| + | lat = int(m.group(3)+m.group(4), 16) | ||
| + | long = long * 180 / math.pi / 6371000.0 | ||
| + | lat = (math.atan(math.exp(lat / 6371000.0 )) - math.pi / 4) * 360 / math.pi | ||
| + | print '<wpt lat="%f" lon="%f"><name>%s</name></wpt>' %(lat, long, m.group(5)) | ||
| + | |||
| + | |||
| + | print """<?xml version="1.0" encoding="UTF-8" standalone="no" ?> | ||
| + | <gpx xmlns="http://www.topografix.com/GPX/1/1" creator="byHand" version="1.1" | ||
| + | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| + | xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"> | ||
| + | """ | ||
| + | |||
| + | for bookmark in sys.stdin.readlines(): | ||
| + | bookmark = bookmark.strip() | ||
| + | if bookmark[0:3] == "mg:": | ||
| + | parse_bookmark(bookmark) | ||
| + | |||
| + | |||
| + | print "</gpx>" | ||
| + | |||
| + | |||
| + | |||
| + | Usage: python navit2gpx.py < bookmarks.txt > waypoints.gpx | ||
Aktuelle Version vom 17. Juli 2009, 22:51 Uhr
Da Navit seine Lesezeichen in der Datei bookmarks.txt in einem hex-Format im Bogenmaß abspeichert, hat stettberger aus dem Quellcode die Umrechnungsformel auf "normale" Koordinaten herausgepfriemelt und das ganze in ein schönes Python-Script verpackt, welches dann gleich gpx-Koordinaten ausspuckt um in OSM verwendet zu werden. Hintergrund der Aktion: Doc ist mit seinem Rad öfters mal auf "unbekanntem" Gelände unterwegs und auf diese Weise kann man nicht kartografierte Ortschaften zumindest mal als existent in OSM eintragen (:razz:)
#!/usr/bin/python
import sys, math, re
def parse_bookmark(b):
m = re.match('mg:(-?)0x(.*) (-?)0x(.*) type=bookmark label="(.*)"', b)
if m:
long = int(m.group(1)+m.group(2), 16)
lat = int(m.group(3)+m.group(4), 16)
long = long * 180 / math.pi / 6371000.0
lat = (math.atan(math.exp(lat / 6371000.0 )) - math.pi / 4) * 360 / math.pi
print '<wpt lat="%f" lon="%f"><name>%s</name></wpt>' %(lat, long, m.group(5))
print """<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" creator="byHand" version="1.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
"""
for bookmark in sys.stdin.readlines():
bookmark = bookmark.strip()
if bookmark[0:3] == "mg:":
parse_bookmark(bookmark)
print "</gpx>"
Usage: python navit2gpx.py < bookmarks.txt > waypoints.gpx