Created
August 11, 2016 17:27
-
-
Save zouzias/38469093729c91f1034fc2ed010bf39b to your computer and use it in GitHub Desktop.
Convert GeoJSON data to WKT
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
import json | |
import geojson | |
from shapely.geometry import shape | |
# Get cities from https://github.com/mahemoff/geodata/blob/master/cities.geojson | |
with open('cities.geojson') as json_data: | |
d = json.load(json_data) | |
for country in d['features']: | |
name = country['properties']['city'] | |
id = country['id'] | |
geo = country['geometry'] | |
s = shape(geojson.loads(json.dumps(geo))) | |
wkt = s.wkt | |
result = '{"id": "' + id + '", "name" : "' + name + '", "shape":"' + wkt + '"}' | |
# print(id + ' : ' + name + ' : ' + wkt) | |
print(result) |
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
import json | |
import geojson | |
from shapely.geometry import shape | |
# Get countries file from https://github.com/zouzias/world.geo.json/blob/master/countries.geo.json | |
with open('countries.geo.json') as json_data: | |
d = json.load(json_data) | |
for country in d['features']: | |
name = country['properties']['name'] | |
id = country['id'] | |
geo = country['geometry'] | |
s = shape(geojson.loads(json.dumps(geo))) | |
wkt = s.wkt | |
result = '{"id": "' + id + '", "name" : "' + name + '", "shape":"' + wkt + '"}' | |
# print(id + ' : ' + name + ' : ' + wkt) | |
print(result) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment