Skip to content

Instantly share code, notes, and snippets.

@chaudum
Created July 16, 2014 09:08
Show Gist options
  • Save chaudum/1bd42ed71647af616676 to your computer and use it in GitHub Desktop.
Save chaudum/1bd42ed71647af616676 to your computer and use it in GitHub Desktop.
Convert GeoJSON to WKT plygon
#!/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