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
ogr2ogr
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.
[...]
Quantum GIS
QGIS states "invalid data source" when I open the .kml file as a vector layer.
Kml2Shp Online
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
Google Earth / GPSBabel
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.
GPS Visualizer
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.
Best Answer
Working (albeit cumbersome) solution to convert KML-/KMZ-files with
<gx:Track>
-Extension to gpx/csv/tcx, via Googles MyTracks-App.I tried to import a .kmz-file to QGIS, containing a GPS-track as
<gx:track>
-Element. (Track was recorded with MyTracks-App on Android. I only had the.kmz
.)After numerous attempts, using various tools (GPS-Tools-PlugIn, GPSBabel, some online tool, etc.) which never converted the track (i.e. LineString) but only the point features, i remembered that MyTracks offers an import-option as well. So imported the
.kmz
to MyTracks , exported the track as.gpx
and was finally able to import the.gpx
to QGIS. Job done.Here is a brief, illustrated HowTo, just in case someone is interested (sry for german UI):
1.) Copy
.kmz
toMyTracks/kml
on device.2.) Import all external KML-tracks in MyTracks-App
3.) Select imported track and export to external storage as GPX, CSV or TCX.
4.) Locate exported track in corresponding directory (i.e. MyTracks/gpx, MyTracks/csv or MyTracks/tcx) and copy/move to PC/Mac.
5.) Eat cake!
6.) Proceed with original task. (e.g. import to QGIS)