Commit
·
3a5c93a
1
Parent(s):
3140a86
Pytorch v.39
Browse files- localisation.py +14 -10
localisation.py
CHANGED
|
@@ -3,6 +3,7 @@ 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 |
response = requests.get(url)
|
|
@@ -12,7 +13,7 @@ def get_data():
|
|
| 12 |
cleaned_data = []
|
| 13 |
for record in records:
|
| 14 |
fields = record.get("fields", {})
|
| 15 |
-
#
|
| 16 |
geoloc = fields.get("geolocalisation")
|
| 17 |
if geoloc and isinstance(geoloc, list) and len(geoloc) == 2:
|
| 18 |
lat, lon = geoloc
|
|
@@ -26,17 +27,20 @@ def display_map(data):
|
|
| 26 |
if not data:
|
| 27 |
st.write("No data available to display on the map.")
|
| 28 |
return
|
| 29 |
-
|
|
|
|
| 30 |
m = folium.Map(location=[44.837789, -0.57918], zoom_start=12)
|
| 31 |
-
|
| 32 |
for item in data:
|
| 33 |
-
lat, lon = item
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
| 40 |
folium_static(m)
|
| 41 |
|
| 42 |
if __name__ == "__main__":
|
|
|
|
| 3 |
from streamlit_folium import folium_static
|
| 4 |
import streamlit as st
|
| 5 |
|
| 6 |
+
# Supposons que cette fonction fonctionne correctement et n'a pas besoin d'être modifiée.
|
| 7 |
def get_data():
|
| 8 |
url = "https://opendata.bordeaux-metropole.fr/api/records/1.0/search/?dataset=met_etablissement_rse&q=&rows=100"
|
| 9 |
response = requests.get(url)
|
|
|
|
| 13 |
cleaned_data = []
|
| 14 |
for record in records:
|
| 15 |
fields = record.get("fields", {})
|
| 16 |
+
# Vérifiez que 'geolocalisation' ou un autre champ contient les coordonnées
|
| 17 |
geoloc = fields.get("geolocalisation")
|
| 18 |
if geoloc and isinstance(geoloc, list) and len(geoloc) == 2:
|
| 19 |
lat, lon = geoloc
|
|
|
|
| 27 |
if not data:
|
| 28 |
st.write("No data available to display on the map.")
|
| 29 |
return
|
| 30 |
+
|
| 31 |
+
# Initialiser la carte au centre de Bordeaux
|
| 32 |
m = folium.Map(location=[44.837789, -0.57918], zoom_start=12)
|
| 33 |
+
|
| 34 |
for item in data:
|
| 35 |
+
lat, lon = item.get("lat"), item.get("lon")
|
| 36 |
+
# Assurez-vous que lat et lon sont des flottants
|
| 37 |
+
if lat and lon:
|
| 38 |
+
folium.Marker(
|
| 39 |
+
[float(lat), float(lon)],
|
| 40 |
+
popup=item.get("name", "Inconnu"),
|
| 41 |
+
icon=folium.Icon(color="green", icon="leaf"),
|
| 42 |
+
).add_to(m)
|
| 43 |
+
|
| 44 |
folium_static(m)
|
| 45 |
|
| 46 |
if __name__ == "__main__":
|