Created
August 11, 2013 22:00
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Failed with filename in rev.1