# 8/11/2020 Tom Musolf - based on some code I found on the internet from Tim Abell # # Quick hack (no error checking & I'm not a python guy) to convert Google My Maps KML export files to # GPX files for OSMAnd mapping program on Android phones. # # There are lots of KML to GPX converters out there, like GPSVisualizer.com, but they all lose the KML icon and color info # during the translation. In addition, OSMAnd has it's own GPX extensions for it's custom icons. # What this program does is convert KML waypoints and tracks/lines into their OSMAnd GPX equivalents. # # KML Layers # Layers are ignored, but all tracks and points found in the KML file are translated into their OSMAnd GPX file equivalent. # # Tracks # Track name and description are translated. # Tracks will carry the color specified in the KML file into OSMAnd. # Line width is not translated because it is not supported in OSMAnd. # A default transparency value for the track is specified using the TrackTransparency variable. # # Points # Name and description are translated. # The KML icon is translated to an OSMAnd equivalent using the iconDictionary translation table. # This table contains # OSMAnd equivalent icon # A color for the icon or you can specify using the icon color from the KML file # Which of the 3 icon shapes that OSMAnd supports. # If the KML icon is not found in the table then a default/unknown icon is used. # Other # All other KML structures/tags are ignored # # Once you have your GPX file copy it to this location on your android phone: .../Android/data/net.osmand.plus/files/tracks # Note: The tracks folder supports nested folders so you can create folders such as: .../tracks/hikes and .../tracks/BikeRoutes # These folders and their GPX files will then show up in OSMAnd MyPlaces>Tracks # # I use OSMAnd configure map>GPX files>Appearance>Bold for the tracks I display with my GPX files. With track transparency set to # 55 (via this program) it lets me read street names and still see the track. # # Make sure you have python installed on your PC # # Cmd format: py KMLToOSMAndGPX.py "input file" > "output file" # # If no output file is specified output goes to standard out. # # Again, NO ERROR CHECKING is done for presence of input file, valid KML file structure, etc. #=========================================================================== # #!/usr/bin/python # https://timwise.co.uk/2014/02/03/converting-kml-to-gpx-with-python/ # https://gist.github.com/timabell/8791116 import argparse import xml.sax parser = argparse.ArgumentParser(description='Convert annoying google android my tracks kml data to sensible gpx files') parser.add_argument('input_file') args = parser.parse_args() input = args.input_file #iconDictionary describes the mapping between a KML icon number and an OSMAnd icon name. #It also contains a default OSMAnd color and shape to use for each OSMAnd icon type. # #iconDictionary format: # "KML icon number":["OSMAnd Icon name","HTML hex color code or flag to use KMLCOLOR","OSMAnd shape"] # #Color code is a standard HTML hex color code. This is what OSMAnd uses #As of 8/2020 OSMAnd icons do not support transparent colors. #As of 8/2020 OSMAnd supports 3 icon shapes: circle, octagon, square # #Adding additional KML icons to the dictionary. # # For each icon you want to translate you need to add a new entry/line into the iconDictionary table. # To determine what the KML and OSMAnd icons are you want go through the following steps: # # KML icon number # 1) Create a google my maps test file with the icons you want to use. # 2) Export this map as a KML file. # 3) Open up the file in a text editor and look for your points. You can ignore all the