Skip to content

Instantly share code, notes, and snippets.

@LouisaKB
Created September 12, 2018 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LouisaKB/669eacd56193d984deaca4b870b6f30e to your computer and use it in GitHub Desktop.
Save LouisaKB/669eacd56193d984deaca4b870b6f30e to your computer and use it in GitHub Desktop.
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