A little KML to CSV converter

Today I had to take over some places a collegue marked in Google Earth. Maybe I was too blind or actually too stupid but I was not able find a simple tool for converting KML to an ArcGIS-compatible format. Except FME of course, but that would be the overkill for my purposes. So I wrote a quick and dirty XSLT-hack to convert a KML-file to a very basic CSV-structure, which I could later import as X/Y coordinates to ArcGIS.

I had following structure in Google Earth:

My Places
__Folder
____Placemark 1
____Placemark 2

Saving the folder as kml brought me this file (GE_original.kml).

For some reasons (I’m no XSLT expert) I had to delete the KML namespace declaration and of course add the XSL-stylesheet information. See the modified KML file here (GE_modified.kml).

The XSL-file I wrote you can find here (kml2csv.xsl).

Put your modfied KML file in the same folder as kml2csv.xsl and open it in a XSLT compatible Browser. You should see now coordinates and placemark names in a CSV structure instead of a KML-XML-tree:

Name,X,Y,Z
Placemark 1,13.08349600542125,47.79234503541417,0
Placemark 2,13.27061184961974,47.68484958984244,0

Save it as text file, open it in ArcGIS (or in your prefered GIS client, spatially enabled DBMS, spreadsheet app or wherever you want) and add the X/Y coordinates to your layer. For now the XSLT is limited to placemarks and it only works if your placemarks are contained by exactly one folder – as I said, a quick and dirty hack.

Further improvements to come (as soon as I have some time left):

  • the conversion of KML to GML would be a more elegant way
  • support of lines and polygons

Google Earth is a nifty tool to create some spatial notes and simple geographic objects. It’s easy to use, offers access to basic geodata but it’s definitely not a tool to produce large and complex geodatasets.


  • http://www.spatiallyadjusted.com/2005/11/25/kml-to-arcmap-converter/ Spatially Adjusted with James Fee » Blog Archive » KML to ArcMap Converter

    [...] Link – A little KML to CSV converter I wrote a quick and dirty XSLT-hack to convert a KML-file to a very basic CSV-structure, which I could later import as X/Y coordinates to ArcGIS. [...]

  • Paul

    Any further progress on this one? I am VERY interested if you find a way to export a polygon.

  • http://spanring.eu/ Christian

    Paul,
    have you tried the kml2gml stylesheet? It allows you to transform points, lines and polygons from KML to GML. With the help of OGR you can then convert the GML file to an ESRI Shapefile for instance.

  • http://www.spatiallyadjusted.com/2005/12/11/christian-spanring-transforms-kml-to-gml/ Christian Spanring Transforms KML to GML

    [...] – Styling KML to GML So I extended my begun KML to CSV XSL stylesheet to take over Google Earth KMLs in a more [...]

  • raja

    thank you

  • Jake Sopher

    Hi this has been a little helpful, but could you please define your acronyms?

    > Except FME of course, but that would be the overkill for my purposes.

    What is FME?

    and then in your reply to a the reply from Paul you reffered to OGR.

    What is OGR?

    thanks.

  • http://spanring.eu/ Christian

    I added the link to FME, it’s a commercial software for conversion between any possible spatial file format.

    OGR is an open source library doing spatial vector format conversions.

  • http://www.planeteye.com juan

    Thanks… I was stuck on the kml namespace for a while too.

  • Michael

    When will the polylines or polygons be supported?
    Thanks!

  • http://spanring.eu/ Christian

    As said above: kml2gml basically supports polygones and polylines. Unfortunately my disposable time is currently very limited for that project…

blog comments powered by Disqus