Skip to content

Instantly share code, notes, and snippets.

@capooti
Created April 3, 2012 13:06
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save capooti/2291849 to your computer and use it in GitHub Desktop.
Save capooti/2291849 to your computer and use it in GitHub Desktop.
Parse a KML file and export it to GeoJSON with GDAL OGR Python bindings
from osgeo import ogr
def kml2geojson(kml_file):
drv = ogr.GetDriverByName('KML')
kml_ds = drv.Open(kml_file)
for kml_lyr in kml_ds:
for feat in kml_lyr:
print feat.ExportToJson()
kml2geojson('/path/to/your.kml')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment