Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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 for Linux that is capable of converting the file? I do not want to upload the tracking data to yet another website for the conversion.

share|improve this question
    
You can load the KML into QGIS and save as shapefile natively. –  Mapperz May 22 '13 at 19:42
1  
@Mapperz Please re-read my question: I already wrote that QGIS does not accept the file. –  JJD May 22 '13 at 20:13
1  
Are you sure it is a KML file ? size bigger than 0. It could be KMZ file (which qgis didnt support while ago , i think) –  simplexio May 22 '13 at 20:20
    
@simplexio All I can tell you is that Google Latitudes offers a download link as KML. I updated my question accordingly. –  JJD May 22 '13 at 20:26
    
And its has size and there is data when you use 'cat file' ? –  simplexio May 22 '13 at 20:32

4 Answers 4

Not the operating system you want, but BaseCamp by Garmin can read your kml file, and exporting to csv gives a file that can be added with delimited text to QGIS. The data leads to Indonesia.


EDIT

Unfortunately, KML is not a very strict standard. That means that almost every form of data storage is allowed, as long as it is valid XML. The kml drivers incorporated in OGR, QGIS and others only support the storage format the developer had as example. If you face a huge number of KML files, it might be worth writing a XML parser style sheet that picks the coordinates and outputs them in a simple format like CSV:

http://stackoverflow.com/questions/10195399/transforming-xml-formerly-kml-using-xslt

share|improve this answer
up vote 1 down vote accepted

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.

share|improve this answer
1  
I opened a ticket for supporting the Google Latitude format in the GDAL KML driver: trac.osgeo.org/gdal/ticket/5095 –  Andre Joost May 27 '13 at 11:09
1  
... and already fixed in the latest GDAL libkml driver with r6053. Unfortunately, this driver is not included in the gisinternals Windows builds. –  Andre Joost May 28 '13 at 19:55
    
@AndreJoost That was awesome fast. Thank you for the report! –  JJD May 29 '13 at 14:27

QGIS on Ubuntu

Vector (select directory) browse for kml file (drop down list) then add

Then select the features (point, lines, polygons etc) select all or individually

enter image description here

enter image description here

enter image description here

Source KML tested https://developers.google.com/kml/documentation/KML_Samples.kml

share|improve this answer
2  
Well, as the user said, it's not working. Just check the kml he links :/ –  RobinC May 22 '13 at 20:35
    
they are blocked - KML can only be simple lines and polygons. –  Mapperz May 22 '13 at 20:37
1  
No, this kml is a GPS track, with coordinates like this : <gx:Track> <altitudeMode>clampToGround</altitudeMode> <when>2012-02-27T08:44:37.614-08:00</when> <gx:coord>95.425701 5.4245077 312</gx:coord> <when>2012-02-27T08:45:16.653-08:00</when> <gx:coord>95.4175155 5.4290813 125</gx:coord> <when>2012-02-27T08:45:44.686-08:00</when> <gx:coord>95.4120326 5.4325564 103</gx:coord> <when>2012-02-27T08:46:45.641-08:00</when> etc. –  RobinC May 22 '13 at 20:38
1  
I tried to open it in Google Earth, and save it to kml/kmz from there (sometimes works as KML can contains links instead of coordinates), but this strange format remains the same. –  RobinC May 22 '13 at 20:40

Hi JJD, If you have QGIS Installed on Ubuntu, you can convert KML to SHP by following these step:(In QGIS GUI, not command mode)

  1. Add your .KML file by add vector layer button
  2. Selecting file type Keyhole Markup Language
  3. Adding your file and right-click on layer name and choose Save As
  4. Save it as a new file and select Esri shape as a file type
  5. Now you have a SHP on your hard disk

Hope this will help you.

share|improve this answer
2  
Please re-read my question: I already wrote that QGIS does not accept the file. You can try it with the file yourself. –  JJD May 22 '13 at 20:13
    
check your kml is vaild first & test a different file. –  Mapperz May 22 '13 at 20:35
1  
If having a line from that track is enough its a solution (I think cause its a KML track QGIS couldn't open it as regular KML) –  Mohsen Raimipour May 22 '13 at 20:53
1  
Go to gpsies.com/convert.do and upload your data and convert it to GeoJSON track (in convert to track menu) and then add it to qgis as a vector layer and save it as shp. Hope that works fine. –  Mohsen Raimipour May 22 '13 at 20:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.