We have a large bunch of KML files, they are basically global cable maps. In our company they are wide-spread and everybody uses them with Google Earth.

Now there is an interest to extract information from these files, e.g. Cable Lengths. With Google Earth extracting Cable Length is a very tedious task because you need to look at each tiny segment's height profile. So I started writing a software to read those files, problem is: the quality of most of those KML/KMZs is really low. Sometimes linestrings contain too many or even duplicate coordinate-sequences. You can even see that in Google Earth.

So question: does it make sense to try to parse these KMLs to calculate cables' total length? Or is this too much asked from KML format?

  • 4
    This is more a question about how good is the source data. You can easily convert KML to Shapefile and calculate length - but if the source data is poor/generlised then the length will be inaccurate. KML to SHP zonums.com/online/kml2shp.php
    – Mapperz
    Commented Jun 21, 2012 at 13:15
  • Mapperz: Thanks for your answer. Ok, I tried one KML. The online converter only exports only a fraction of the cables. Is this the converter's, my or the KML's fault? BTW: On a quality scale between 0 and 10 (0 worst file I encountered here, 10 seems perfect), I give this file a 4.
    – user694971
    Commented Jun 21, 2012 at 15:53
  • And about how inaccurate are you talking? I remember one file in which a segment that is supposed to be < 300 km, was measured over 5000 km using Google Earth's height profile feature. Although this stuff is in part fixable, my yet incomplete program filters this trash.
    – user694971
    Commented Jun 21, 2012 at 15:55
  • Large KML scan be fragmented using the online tool. A Desktop solution like FME desktop (at cost) would be able to accommodate much larger KMLs and calculate your length in one workspace. Free OFFLINE desktop application - zonums.com/kml2shp.html
    – Mapperz
    Commented Jun 21, 2012 at 16:10
  • Thanks for the hint, I'll try FME desktop. Unfortunately not even ArcGIS seems to have reasonable KML support
    – user694971
    Commented Jun 22, 2012 at 9:30

3 Answers 3


You can convert kml to other GIS formats such as shape using ogr2ogr, part of gdal. If there are too many points or double points this should not really cause problems: calculating a length is a fast progress.

Although they work with any GIS program, calculating the actual length is not that straightforward: most of them only work with projected data, and if you have global cables they should work with unprojected data as well.

BTW: a google search turned up with this tool to measure lengths in kml files: http://freegeographytools.com/2007/determining-google-earth-path-lengths

  • 1
    johanvdw: I wrote a tool myself which calculates the lengths pretty reliably. Even if the web tool is more reliable, the problem persists in KMLs with lots of paths. Regarding converters: I'll try them...
    – user694971
    Commented Jun 22, 2012 at 9:28

If you can come up with a set of rules, such as vertices much travel in the positive X direction, or distance between vertices must be less than some tolerance, I can forsee a way to accomplish your task using the osgeo.ogr python module.


break line into a list of points
iterate over list, check against rules, remove bad vertices, maybe
reconstruct line
add a field, with a flag to indicate vertices were removed
export to any ogr format you want

repeat for all lines, in all kmls (and/or unzipped kmzs)


I was about to add a comment but apparently I have not enough reputation:-)

I'm not sure how you are writing your program. You may consider using XPATH ans XSLT transformation as KML is essentially an XML file. You can calculate standard deviation to see if there are apparent glitches with entered data. If you go XML way, XSLT processor will take care of iterations, and you'll need to implement just transformation rules.

While 300km segment is quite long, is your current approach projection aware? Depending on the projection, you may get slightly different results... though not 5000 km :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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