Skip to content

Instantly share code, notes, and snippets.

@jackbillstrom
Created August 11, 2013 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackbillstrom/6207056 to your computer and use it in GitHub Desktop.
Save jackbillstrom/6207056 to your computer and use it in GitHub Desktop.
Converts a *.kml file to *.json, removes height. Working on to switch places with arrays. Python 3.3.2
#!/usr/bin/python
import simplejson as json, re
print ("KML to JSON")
filename = input("Select file: ")
outputFile = input("Desired filename for output: ")
fileObj = open(outputFile + ".json","w")
output = (json.dumps(dict( (entry[0].strip(), entry[1].strip())
for entry in re.findall('<name>(.*?)</name>.*?<coordinates>(.*?)</coordinates>(?s)', open(filename + ".kml").read() ) )))
clean1 = output.replace(",0 ",",")
cleanFinal = clean1.replace(',0"','"')
fileObj.write(cleanFinal)
fileObj.close()
print ("File saved!")
@jackbillstrom
Copy link
Author

Failed with filename in rev.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment