gx-begone
v0.1.0
Published
Convert Google's proprietary gx-prefixed KML format (output my My Tracks) to standard KML.
Downloads
2
Readme
gx-begone
Convert Google's proprietary gx-prefixed KML format (output by My Tracks) to standard KML.
Usage
Both of these conversion solutions use the xsltproc
command-line xslt-processing tool. Depending on how nice you want the output to be, you may also want xmllint
or json for NodeJS.
gx:KML → KML
To turn my.kml
into my_better.kml
:
xsltproc gx-begone.xslt /path/to/my.kml | xmllint --format - > my_better.kml
The command-line tool xmllint
is used to make the output nicer, but you can leave it off if you don't care about that.
gx:KML → GeoJSON
To turn my.kml
into my.geojson
, run the following commands from the root directory of this repo:
npm install # install json nodejs tool
xsltproc gx-to-geojson.xslt /path/to/my.kml | nodejs ./node_modules/.bin/json > my.json
The json
command line tool is used to prettify the json output of gx-to-geojson.xslt
.
Note that you will need NodeJS installed on your system to use the above json prettifier.
Ta da! Now you can view your GeoJSON or KML in QGIS or transform it into other formats using ogr2ogr.
The Problem
Google introduced KML several years ago to store data for display in Google Earth and Google Maps. Since it was adapted as an international standard by the Open Geospatial Consortium (OGC) in 2008, lots of open tools have been developed for viewing KML and converting it to other popular formats. In particular, the conversion tool ogr2ogr can convert standard KML to a wide range of other formats.
However, with Google Earth 5.0, released in 2009/2010, Google introduced a new "gx"
namespace not part of the OGC standard.
Google Earth saves KML documents using elements from this new "gx"
namespace, as does Google's My Tracks Android application. As of July 2014, Google's extended namespace is not supported by other open tools, so these files can only be opened in Google Earth and Google Maps.
What a pain.
The Solution
This repository provides two xslt
files for transforming Google-prefixed KML produced by My Tracks to standard KML and GeoJSON. Be warned: this conversion is lossy: the KML files output by My Tracks include timestamp data and velocity data that standard KML does not yet have a good way of recording.
Conversion loss:
* gx:KML -> KML
converter only extracts the path (it loses the timestamps and velocity data)
* gx:KML -> GeoJSON
converter extracts path and timestamps (it places the timestamps in an array in the "properties"
object of the "GeoJSON Feature", and loses the velocity data.)
If you need this data, send me a message asking me to include this in the conversion, or submit a pull request.
Javascript Converter
I spent some time working on a Javascript converter using xmldom
and xpath
. I put that aside in favor of the quicker xslt
-based approach, but if you're interested, you can view the code in the javascript
branch in this repo.