Created
September 12, 2018 11:09
-
-
Save LouisaKB/669eacd56193d984deaca4b870b6f30e 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
import json | |
def remap_linear_ring(linear_ring): | |
return list(map(lambda c: [c['lng'], c['lat']], linear_ring)) | |
def shapes_to_multipolygon(shapes): | |
allRings = [] | |
for shape in shapes: | |
shell = remap_linear_ring(shape['shell']) | |
holes = list(map(lambda h:remap_linear_ring(h), shape['holes'])) | |
rings = [shell] | |
rings.extend(holes) | |
allRings.append(rings) | |
return { | |
'type': 'MultiPolygon', | |
'coordinates': allRings | |
} | |
def response_to_geojson(response): | |
response_data = json.loads(response) | |
multi_polygons = list(map(lambda r: shapes_to_multipolygon(r['shapes']), response_data['results'])) | |
return { | |
'type': 'FeatureCollection', | |
'features': multi_polygons | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment