Created
May 7, 2019 14:04
-
-
Save morkapronczay/a1c5397af454f4e9b50808f3e7aca596 to your computer and use it in GitHub Desktop.
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
def json_to_geojson(data, districts): | |
# create a geojson from a list of dictionaries | |
# containing coordinates with the name of the polygon | |
# in our case a polygon is a district | |
assert type(data) == list, "The parameter data should be a list of coordinates with a name argument!" | |
geojson = { | |
"type": "FeatureCollection", | |
"features": [ | |
{ | |
"type": "Feature", | |
"geometry" : { | |
"type": "Polygon", | |
"name": district, | |
"coordinates": [[[d["lon"], d["lat"]] for d in data if d['name'] == district]], | |
}, | |
"properties" : {'name': district}, | |
} for district in districts] | |
} | |
return geojson |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment