add RNB config

This commit is contained in:
Tykayn 2025-03-01 00:27:09 +01:00 committed by tykayn
parent 22a8c09bfb
commit 97f818a29e
3 changed files with 257808 additions and 0 deletions

File diff suppressed because it is too large Load diff

54
wip/extract_rnb.py Normal file
View 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

File diff suppressed because it is too large Load diff