/gist:1bd42ed71647af616676 Secret
Created
July 16, 2014 09:08
Star
You must be signed in to star a gist
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