Skip to content

Instantly share code, notes, and snippets.

@RemiDesgrange
Last active July 7, 2019 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save RemiDesgrange/fd29aadb9493b1d7a88b7eb246a93425 to your computer and use it in GitHub Desktop.
Save RemiDesgrange/fd29aadb9493b1d7a88b7eb246a93425 to your computer and use it in GitHub Desktop.
A simple script to transform the area of massif from meteofrance into a geojson.
from typing import Dict
BASE_URL = "http://www.meteofrance.com/mf3-rpc-portlet/js/datas/zones_AVDEPT{}.json"
DEPTS = ("73", "74", "05", "38")
import requests
from geojson import Feature, FeatureCollection
def get_area(dept: str) -> Dict:
r = requests.get(BASE_URL.format(dept))
assert r.status_code == 200, "Wrong status code aborting"
return r.json()
def parse_geom(zone: str) -> Dict:
geom = {'type': 'Polygon', 'coordinates': None}
coords = zone.split(',')
# we want the area to be projected in EPSG:4326. But lat need to be bound
# in -180;+180 and long -90;+90.
coords_int = [float(x)/100 for x in coords]
geom['coordinates'] = [[coords_int[x+1], coords_int[x]] for x in range(0, len(coords_int)-1, 2)]
geom['coordinates'] = [geom['coordinates']]
return geom
def transform_to_geojson(area: Dict) -> FeatureCollection:
final = list()
for massif in area:
f = Feature(geometry=parse_geom(massif['zone']), properties={'id':massif['id'], 'slug': massif['slug'], 'label': massif['label']})
final.append(f)
return FeatureCollection(final)
if __name__ == '__main__':
for dept in DEPTS:
area = get_area(dept)
x = transform_to_geojson(area)
with open(f'{dept}.geojson', 'w') as f:
f.write(str(x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment