Sunday, 21 April 2019

qgis - How to convert KML with tracks to Shapefiles?


I downloaded a KML track from Google Latitude. The service allows to download the tracked route from the user's profile providing a link such as:


https://maps.google.com/locationhistory/b/0/kml?startTime=1318716000000&endTime=1318802400000



I would like to convert the .kml file into a Shapefile. I am running Ubuntu. I am a bit familiar with QGIS and ogr2ogr. Therefore, I tried the following command as usual:


$ ogr2ogr -f "ESRI Shapefile" example.shp example.kml
ERROR 4: No layers in KML file: example.kml.
FAILURE:
Unable to open datasource `example.kml' with the following drivers.
[...]


QGIS states "invalid data source" when I open the .kml file as a vector layer.




I also tried Kml2Shp Online without success. It is not able to read any information either:


Entities found:
# Points: 0
# Paths: 0
# Inner Polygons: 0
# Outer Polygons: 0


Furthermore, I found out that Google Earth is not capable of exporting GPX. Google refers to GPSBabel which converts KML to GPX using the following command:


$ gpsbabel -i kml -f ~/Desktop/example.kml -o gpx -F ~/Desktop/example.gpx


However, in my case it outputs a GPX file without location data.



As a first success I found the website GPS Visualizer. Uploading and converting the file their actually produces a valid GPX file.




Still my question remains to be open:
Is there a command line tool that is capable of converting the file? I do not want to upload the tracking data to yet another website for the conversion.



Answer



I finally found a script which converts KML to GPX. That's good enough. It is written by ONO Hiroki. All credits belong to him. On request he rewrote the script within one day to match the current format of KML files by Google Latitude. I put the old and current version of the script to the following location.




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...