-
-
Save chaudum/1bd42ed71647af616676 to your computer and use it in GitHub Desktop.
Convert GeoJSON to WKT plygon
This file contains 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/env python2.7 | |
import sys | |
import json | |
from pprint import pprint | |
def main(): | |
""" | |
converts the files from https://github.com/johan/world.geo.json/tree/master/countries | |
see: http://gis.stackexchange.com/questions/61295/is-there-any-efficient-way-to-convert-geojson-to-wkt | |
""" | |
d = json.load(sys.stdin) | |
coords = d['features'][0]['geometry']['coordinates'][0] | |
sys.stdout.write('POLYGON((') | |
i=0 | |
for x, y in coords: | |
i+=1 | |
line = "{} {}".format(x, y) | |
if i != len(coords): | |
line += ', ' | |
sys.stdout.write(line) | |
sys.stdout.write( '))') | |
sys.stdout.write('\n') | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment