mirror of
https://forge.chapril.org/tykayn/wololo
synced 2025-06-20 01:34:42 +02:00
add RNB config
This commit is contained in:
parent
22a8c09bfb
commit
97f818a29e
3 changed files with 257808 additions and 0 deletions
256210
wip/buildings_code_insee_91338.geojson
Normal file
256210
wip/buildings_code_insee_91338.geojson
Normal file
File diff suppressed because it is too large
Load diff
54
wip/extract_rnb.py
Normal file
54
wip/extract_rnb.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
import requests
|
||||
import json
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--insee_code", type=str, required=True)
|
||||
args = parser.parse_args()
|
||||
|
||||
# Création de la structure GeoJSON
|
||||
geojson = {
|
||||
"type": "FeatureCollection",
|
||||
"features": []
|
||||
}
|
||||
|
||||
# URL initiale
|
||||
url = f"https://rnb-api.beta.gouv.fr/api/alpha/buildings/?insee_code={args.insee_code}"
|
||||
total_buildings = 0
|
||||
|
||||
# Boucle pour récupérer toutes les pages
|
||||
while url:
|
||||
print(f"Récupération de {url}")
|
||||
response = requests.get(url)
|
||||
data = response.json()
|
||||
|
||||
# Conversion des résultats en features GeoJSON
|
||||
for building in data['results']:
|
||||
feature = {
|
||||
"type": "Feature",
|
||||
"geometry": building['shape'], # La forme du bâtiment est déjà en format GeoJSON
|
||||
"properties": {
|
||||
"rnb_id": building['rnb_id'],
|
||||
"status": building['status'],
|
||||
"addresses": building['addresses'],
|
||||
"ext_ids": building['ext_ids'],
|
||||
"is_active": building['is_active']
|
||||
}
|
||||
}
|
||||
geojson['features'].append(feature)
|
||||
|
||||
total_buildings += len(data['results'])
|
||||
print(f"Nombre de bâtiments traités : {total_buildings}")
|
||||
|
||||
# Préparation de l'URL suivante
|
||||
url = data.get('next')
|
||||
|
||||
# Affichage du nombre total de bâtiments
|
||||
print(f"\nNombre total de bâtiments extraits : {total_buildings}")
|
||||
|
||||
# Sauvegarde du GeoJSON
|
||||
output_file = f'buildings_code_insee_{args.insee_code}.geojson'
|
||||
with open(output_file, 'w', encoding='utf-8') as f:
|
||||
json.dump(geojson, f, ensure_ascii=False, indent=2)
|
||||
|
||||
print(f"\nFichier sauvegardé : {output_file}")
|
1544
wip/results.json
Normal file
1544
wip/results.json
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue