Commit
·
b0c9fd5
1
Parent(s):
749b2f3
Pytorch v.32
Browse files- localisation.py +34 -14
localisation.py
CHANGED
|
@@ -1,20 +1,40 @@
|
|
|
|
|
| 1 |
import folium
|
| 2 |
from streamlit_folium import folium_static
|
| 3 |
import streamlit as st
|
| 4 |
|
| 5 |
-
def
|
| 6 |
-
#
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
| 20 |
folium_static(m)
|
|
|
|
| 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 de l'API
|
| 8 |
+
url = "https://opendata.bordeaux-metropole.fr/api/records/1.0/search/?dataset=met_etablissement_rse&q=&rows=100"
|
| 9 |
+
try:
|
| 10 |
+
response = requests.get(url)
|
| 11 |
+
if response.status_code == 200:
|
| 12 |
+
data = response.json()
|
| 13 |
+
records = data.get("records", [])
|
| 14 |
+
cleaned_data = []
|
| 15 |
+
for record in records:
|
| 16 |
+
fields = record.get("fields", {})
|
| 17 |
+
# Assurez-vous que la structure de 'fields' correspond à ce que vous attendez
|
| 18 |
+
if 'geolocalisation' in fields:
|
| 19 |
+
cleaned_data.append(fields)
|
| 20 |
+
return cleaned_data
|
| 21 |
+
else:
|
| 22 |
+
st.error("Échec de la récupération des données. Statut HTTP : {}".format(response.status_code))
|
| 23 |
+
return []
|
| 24 |
+
except requests.exceptions.RequestException as e:
|
| 25 |
+
st.error("Erreur lors de la connexion à l'API : {}".format(e))
|
| 26 |
+
return []
|
| 27 |
|
| 28 |
+
def display_map(data):
|
| 29 |
+
# Initialise la carte
|
| 30 |
+
m = folium.Map(location=[44.837789, -0.57918], zoom_start=12)
|
| 31 |
+
# Ajoute un marqueur pour chaque élément dans 'data'
|
| 32 |
+
for item in data:
|
| 33 |
+
point_geo = item.get('geolocalisation')
|
| 34 |
+
if point_geo:
|
| 35 |
+
lat, lon = point_geo[0], point_geo[1]
|
| 36 |
+
folium.Marker([lat, lon],
|
| 37 |
+
icon=folium.Icon(color="green", icon="leaf"),
|
| 38 |
+
popup=item.get('nom_courant_denomination', 'Inconnu')
|
| 39 |
+
).add_to(m)
|
| 40 |
folium_static(m)
|