Spaces:
Runtime error
Runtime error
LaurentTRIPIED
commited on
Commit
·
23ab2d4
1
Parent(s):
46f8b87
Pytorch v.34
Browse files- localisation.py +29 -18
localisation.py
CHANGED
@@ -5,24 +5,36 @@ 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 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
22 |
return []
|
23 |
|
24 |
-
def display_map(
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
m = folium.Map(location=[44.837789, -0.57918], zoom_start=12)
|
|
|
26 |
for item in data:
|
27 |
lat, lon = item["lat"], item["lon"]
|
28 |
folium.Marker(
|
@@ -30,9 +42,8 @@ def display_map(data):
|
|
30 |
popup=item["name"],
|
31 |
icon=folium.Icon(color="green", icon="leaf"),
|
32 |
).add_to(m)
|
|
|
33 |
folium_static(m)
|
34 |
|
35 |
-
# Cette partie est pour exécuter le test directement dans ce fichier, si désiré
|
36 |
if __name__ == "__main__":
|
37 |
-
|
38 |
-
display_map(data)
|
|
|
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 |
+
geoloc = fields.get("geolocalisation")
|
17 |
+
if geoloc:
|
18 |
+
# S'assurer que geoloc est une liste avec au moins deux éléments
|
19 |
+
lat, lon = geoloc[0], geoloc[1]
|
20 |
+
cleaned_data.append({"lat": lat, "lon": lon, "name": fields.get("nom_courant_denomination", "Inconnu")})
|
21 |
+
return cleaned_data
|
22 |
+
else:
|
23 |
+
st.error(f"Failed to fetch data. Status code: {response.status_code}")
|
24 |
+
return []
|
25 |
+
except requests.exceptions.RequestException as e:
|
26 |
+
st.error(f"Error occurred: {e}")
|
27 |
return []
|
28 |
|
29 |
+
def display_map():
|
30 |
+
data = get_data()
|
31 |
+
if not data:
|
32 |
+
st.write("No data available to display on the map.")
|
33 |
+
return
|
34 |
+
|
35 |
+
# Initialiser la carte au centre de Bordeaux
|
36 |
m = folium.Map(location=[44.837789, -0.57918], zoom_start=12)
|
37 |
+
|
38 |
for item in data:
|
39 |
lat, lon = item["lat"], item["lon"]
|
40 |
folium.Marker(
|
|
|
42 |
popup=item["name"],
|
43 |
icon=folium.Icon(color="green", icon="leaf"),
|
44 |
).add_to(m)
|
45 |
+
|
46 |
folium_static(m)
|
47 |
|
|
|
48 |
if __name__ == "__main__":
|
49 |
+
display_map()
|
|