Created
August 11, 2021 16:56
-
-
Save leoluk/cbd4bc155d70d2791c6f0051fe40e4f7 to your computer and use it in GitHub Desktop.
Converts geojson with polygon features to a JSON blob readable by http://shadowcalculator.eu
This file contains hidden or 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
#!/usr/bin/env python3 | |
""" | |
Converts geojson with polygon features to a JSON blob readable by http://shadowcalculator.eu | |
Usage: ./shadowcalc.py trees.geojson | |
""" | |
import sys | |
import json | |
import time | |
data = json.load(open(sys.argv[1])) | |
shapes = [] | |
for feature in data['features']: | |
if feature['geometry']['type'] != 'Polygon': | |
continue | |
coords = [] | |
heights = [] | |
for coord in feature['geometry']['coordinates'][0]: | |
coords.append({'lat': coord[1], 'lng': coord[0]}) | |
heights.append(8) | |
shapes.append({'coords': coords, 'heights': heights}) | |
print(json.dumps({ | |
'shapes': shapes, | |
'timestamp': int(time.time() * 1000), | |
'mapCenterLat': coords[0]['lat'], | |
'mapCenterLng': coords[0]['lng'], | |
})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment