-
-
Save keefo/22e05ad86256094c562a0d3d11ff710a to your computer and use it in GitHub Desktop.
A simple script to transform the area of massif from meteofrance into a geojson.
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
| 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], coords_int[x+1]] for x in range(0, len(coords_int)-1, 2)] | |
| 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