mirror of
https://forge.chapril.org/tykayn/parking-land
synced 2025-06-20 01:44:42 +02:00
35 lines
1.5 KiB
Python
35 lines
1.5 KiB
Python
import requests
|
|
import json
|
|
|
|
# Configuration
|
|
OVERPASS_API = "https://overpass-api.de/api/interpreter"
|
|
|
|
import argparse
|
|
|
|
def parse_arguments():
|
|
parser = argparse.ArgumentParser(description="Récupère les données OpenStreetMap pour une ville")
|
|
parser.add_argument("city_id", help="Identifiant OpenStreetMap de la ville")
|
|
return parser.parse_args()
|
|
|
|
args = parse_arguments()
|
|
|
|
city_overpass_id = args.city_id # ID de la ville
|
|
|
|
def fetch_overpass_data():
|
|
# Requête Overpass pour obtenir les routes et bâtiments de la ville
|
|
overpass_query = f'''
|
|
[out:json][timeout:25];area(id:{city_overpass_id})->.searchArea;(way["building"](area.searchArea);nwr["amenity"="bicycle_parking"](area.searchArea);nwr["amenity"="charging_station"](area.searchArea);nwr["man_made"="charge_point"](area.searchArea);nwr["amenity"="parking"](area.searchArea);way["highway"]["highway"~"residential|primary|secondary|tertiary|service|footway|unclassified|cycleway|roundabout|mini_roundabout"](area.searchArea););out geom;
|
|
'''
|
|
|
|
response = requests.post(OVERPASS_API, data={"data": overpass_query}, headers={"X-Requested-With": "overpass-turbo"})
|
|
|
|
if response.status_code == 200:
|
|
data = response.json()
|
|
with open('overpass_data.json', 'w') as file:
|
|
json.dump(data, file, ensure_ascii=False, indent=4)
|
|
print("Données Overpass récupérées et sauvegardées dans overpass_data.json")
|
|
else:
|
|
print(f"Échec de la requête Overpass. Code d'erreur: {response.status_code}")
|
|
|
|
if __name__ == "__main__":
|
|
fetch_overpass_data()
|