Spaces:
Runtime error
Runtime error
Commit
·
dbd3890
1
Parent(s):
74004b8
Pytorch V0.29
Browse files- localisation.py +31 -12
localisation.py
CHANGED
|
@@ -1,22 +1,41 @@
|
|
| 1 |
import requests
|
|
|
|
|
|
|
| 2 |
import streamlit as st
|
| 3 |
|
| 4 |
def get_data():
|
| 5 |
-
url = "https://opendata.bordeaux-metropole.fr/api/records/1.0/search/?dataset=met_etablissement_rse&q=&rows=
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
for record in records
|
| 13 |
-
st.write(record) # Imprime le record complet pour inspection
|
| 14 |
fields = record.get("fields", {})
|
| 15 |
point_geo = fields.get("geolocalisation")
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
else:
|
| 18 |
st.error("Aucun enregistrement trouvé dans les données de l'API.")
|
| 19 |
return []
|
| 20 |
-
|
| 21 |
-
st.error(f"
|
| 22 |
return []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import requests
|
| 2 |
+
import folium
|
| 3 |
+
from streamlit_folium import folium_static
|
| 4 |
import streamlit as st
|
| 5 |
|
| 6 |
def get_data():
|
| 7 |
+
url = "https://opendata.bordeaux-metropole.fr/api/records/1.0/search/?dataset=met_etablissement_rse&q=&rows=100"
|
| 8 |
+
try:
|
| 9 |
+
response = requests.get(url)
|
| 10 |
+
if response.status_code == 200:
|
| 11 |
+
data = response.json()
|
| 12 |
+
records = data.get("records", [])
|
| 13 |
+
cleaned_data = []
|
| 14 |
+
for record in records:
|
|
|
|
| 15 |
fields = record.get("fields", {})
|
| 16 |
point_geo = fields.get("geolocalisation")
|
| 17 |
+
if point_geo and isinstance(point_geo, list) and len(point_geo) == 2:
|
| 18 |
+
lat, lon = point_geo # Directement extraire la latitude et la longitude
|
| 19 |
+
fields["latitude"], fields["longitude"] = lat, lon
|
| 20 |
+
cleaned_data.append(fields)
|
| 21 |
+
return cleaned_data
|
| 22 |
else:
|
| 23 |
st.error("Aucun enregistrement trouvé dans les données de l'API.")
|
| 24 |
return []
|
| 25 |
+
except requests.RequestException as e:
|
| 26 |
+
st.error(f"Erreur lors de la récupération des données de l'API: {e}")
|
| 27 |
return []
|
| 28 |
+
|
| 29 |
+
def display_map(data):
|
| 30 |
+
m = folium.Map(location=[44.837789, -0.57918], zoom_start=12)
|
| 31 |
+
for item in data:
|
| 32 |
+
lat = item.get('latitude')
|
| 33 |
+
lon = item.get('longitude')
|
| 34 |
+
if lat and lon:
|
| 35 |
+
lat, lon = float(lat), float(lon) # Assurez-vous que les coordonnées sont des nombres flottants
|
| 36 |
+
folium.Marker(
|
| 37 |
+
[lat, lon],
|
| 38 |
+
icon=folium.Icon(color="green", icon="leaf"),
|
| 39 |
+
popup=item.get('nom_courant_denomination', "Information non disponible"),
|
| 40 |
+
).add_to(m)
|
| 41 |
+
folium_static(m)
|