Spaces:
Sleeping
Sleeping
fromcarlostocosta
commited on
Commit
•
5d1ac9e
1
Parent(s):
7123c15
Leaflet maps
Browse files- app.py +11 -89
- app_paused.py +110 -0
- requirements.txt +1 -0
app.py
CHANGED
@@ -1,100 +1,22 @@
|
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
-
import random
|
4 |
import plotly.express as px
|
5 |
from geopy.distance import geodesic
|
|
|
6 |
from PIL import Image
|
7 |
|
8 |
-
|
9 |
-
|
10 |
|
11 |
-
|
12 |
-
cities
|
13 |
-
|
14 |
-
"Paris": (48.8566, 2.3522),
|
15 |
-
"Berlin": (52.5200, 13.4050),
|
16 |
-
"Madrid": (40.4168, -3.7038),
|
17 |
-
"Rome": (41.9028, 12.4964),
|
18 |
-
"Vienna": (48.2082, 16.3738),
|
19 |
-
"Amsterdam": (52.3667, 4.8945),
|
20 |
-
"Athens": (37.9838, 23.7275),
|
21 |
-
"Stockholm": (59.3293, 18.0686),
|
22 |
-
"Brussels": (50.8503, 4.3517),
|
23 |
-
"Helsinki": (60.1699, 24.9384),
|
24 |
-
"Warsaw": (52.2297, 21.0122),
|
25 |
-
"Copenhagen": (55.6761, 12.5683),
|
26 |
-
"Lisbon": (38.7223, -9.1393),
|
27 |
-
"Dublin": (53.3498, -6.2603),
|
28 |
-
"Budapest": (47.4979, 19.0402),
|
29 |
-
"Prague": (50.0755, 14.4378),
|
30 |
-
"Sofia": (42.6977, 23.3219),
|
31 |
-
"Bucharest": (44.4396, 26.0963),
|
32 |
-
"Luxembourg": (49.6116, 6.1319),
|
33 |
-
"Riga": (56.9496, 24.1052),
|
34 |
-
"Valletta": (35.8989, 14.5146),
|
35 |
-
"Vilnius": (54.6872, 25.2797),
|
36 |
-
"Bratislava": (48.1486, 17.1077),
|
37 |
-
"Ljubljana": (46.0569, 14.5058),
|
38 |
-
"Nicosia": (35.1856, 33.3823),
|
39 |
-
"Tallinn": (59.4370, 24.7536),
|
40 |
-
"Zagreb": (45.8150, 15.9819),
|
41 |
-
"Nicosia": (35.1856, 33.3823),
|
42 |
-
"Valletta": (35.8989, 14.5146)
|
43 |
-
}
|
44 |
|
45 |
-
# Coordinates of beach and mountain areas
|
46 |
-
beach_coordinates = (45.0, 10.0) # Example beach coordinates
|
47 |
-
mountain_coordinates = (48.0, 10.0) # Example mountain coordinates
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
beach_distance = geodesic(city_coordinates, beach_coordinates).km
|
53 |
-
mountain_distance = geodesic(city_coordinates, mountain_coordinates).km
|
54 |
-
|
55 |
-
if beach_distance <= 200:
|
56 |
-
return "Beach"
|
57 |
-
elif mountain_distance <= 200:
|
58 |
-
return "Mountain"
|
59 |
-
else:
|
60 |
-
return "City"
|
61 |
-
|
62 |
-
# Create an empty DataFrame
|
63 |
-
df = pd.DataFrame(columns=["DMO", "City", "Latitude", "Longitude", "Area", "Environmental", "Cultural",
|
64 |
-
"Community", "Socio-economic", "Infrastructure", "Stakeholder",
|
65 |
-
"Visitor_education", "Monitoring"])
|
66 |
-
|
67 |
-
# Populate the DataFrame
|
68 |
-
for i in range(30):
|
69 |
-
dmo = dmo_names[i]
|
70 |
-
city = random.choice(list(cities.keys()))
|
71 |
-
latitude, longitude = cities[city]
|
72 |
-
area = determine_area(latitude, longitude)
|
73 |
-
environmental = round(random.uniform(0, 10), 2)
|
74 |
-
cultural = round(random.uniform(0, 10), 2)
|
75 |
-
community = round(random.uniform(0, 10), 2)
|
76 |
-
socio_economic = round(random.uniform(0, 10), 2)
|
77 |
-
infrastructure = round(random.uniform(0, 10), 2)
|
78 |
-
stakeholder = round(random.uniform(0, 10), 2)
|
79 |
-
visitor_education = round(random.uniform(0, 10), 2)
|
80 |
-
monitoring = round(random.uniform(0, 10), 2)
|
81 |
-
|
82 |
-
df.loc[i] = [dmo, city, latitude, longitude, area, environmental, cultural, community,
|
83 |
-
socio_economic, infrastructure, stakeholder, visitor_education, monitoring]
|
84 |
-
|
85 |
-
df.loc[df['DMO'].isin(['DMO14', 'DMO19', 'DMO27', 'DMO15', 'DMO20', 'DMO21']), 'Area'] = 'Beach'
|
86 |
-
df.loc[df['DMO'].isin(['DMO4', 'DMO23', 'DMO8']), 'Area'] = 'Mountain'
|
87 |
-
|
88 |
-
fig = px.scatter_mapbox(df, lat="Latitude", lon="Longitude", hover_name="DMO", hover_data=["Environmental", "Cultural",
|
89 |
-
"Community", "Socio-economic",
|
90 |
-
"Infrastructure", "Stakeholder",
|
91 |
-
"Visitor_education", "Monitoring"],
|
92 |
-
color="Area", color_discrete_sequence=["blue", "green", "red"], zoom=3)
|
93 |
-
|
94 |
-
fig.update_layout(mapbox_style="open-street-map")
|
95 |
-
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
|
96 |
-
|
97 |
-
st.plotly_chart(fig, use_container_width=True)
|
98 |
|
99 |
img = Image.open('mastercard_logo.png')
|
100 |
|
@@ -107,4 +29,4 @@ with col2:
|
|
107 |
st.write("")
|
108 |
|
109 |
with col3:
|
110 |
-
st.image(img)
|
|
|
1 |
+
import geopandas as gpd
|
2 |
import streamlit as st
|
3 |
import pandas as pd
|
|
|
4 |
import plotly.express as px
|
5 |
from geopy.distance import geodesic
|
6 |
+
import leafmap.foliumap as leafmap
|
7 |
from PIL import Image
|
8 |
|
9 |
+
m = leafmap.Map(center=(47.903671, 15.483612), zoom=5)
|
10 |
+
cities = gpd.read_file("https://raw.githubusercontent.com/idris-maps/map-of-europe/master/data/cities.json")
|
11 |
|
12 |
+
selected_cities = st.multiselect(
|
13 |
+
'Select cities:',
|
14 |
+
['Lisbon', 'London', 'Budapest', 'Rome', 'Madrid', 'Barcelona'], None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
|
|
|
|
|
|
16 |
|
17 |
+
if selected_cities:
|
18 |
+
m.add_gdf(cities[cities['name'].isin(selected_cities)], layer_name="cities", fill_colors="red")
|
19 |
+
m.to_streamlit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
img = Image.open('mastercard_logo.png')
|
22 |
|
|
|
29 |
st.write("")
|
30 |
|
31 |
with col3:
|
32 |
+
st.image(img)
|
app_paused.py
ADDED
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import random
|
4 |
+
import plotly.express as px
|
5 |
+
from geopy.distance import geodesic
|
6 |
+
from PIL import Image
|
7 |
+
|
8 |
+
# Define the DMO names
|
9 |
+
dmo_names = ["DMO" + str(i) for i in range(1, 31)]
|
10 |
+
|
11 |
+
# Dictionary of large European cities with their coordinates
|
12 |
+
cities = {
|
13 |
+
"London": (51.5074, -0.1278),
|
14 |
+
"Paris": (48.8566, 2.3522),
|
15 |
+
"Berlin": (52.5200, 13.4050),
|
16 |
+
"Madrid": (40.4168, -3.7038),
|
17 |
+
"Rome": (41.9028, 12.4964),
|
18 |
+
"Vienna": (48.2082, 16.3738),
|
19 |
+
"Amsterdam": (52.3667, 4.8945),
|
20 |
+
"Athens": (37.9838, 23.7275),
|
21 |
+
"Stockholm": (59.3293, 18.0686),
|
22 |
+
"Brussels": (50.8503, 4.3517),
|
23 |
+
"Helsinki": (60.1699, 24.9384),
|
24 |
+
"Warsaw": (52.2297, 21.0122),
|
25 |
+
"Copenhagen": (55.6761, 12.5683),
|
26 |
+
"Lisbon": (38.7223, -9.1393),
|
27 |
+
"Dublin": (53.3498, -6.2603),
|
28 |
+
"Budapest": (47.4979, 19.0402),
|
29 |
+
"Prague": (50.0755, 14.4378),
|
30 |
+
"Sofia": (42.6977, 23.3219),
|
31 |
+
"Bucharest": (44.4396, 26.0963),
|
32 |
+
"Luxembourg": (49.6116, 6.1319),
|
33 |
+
"Riga": (56.9496, 24.1052),
|
34 |
+
"Valletta": (35.8989, 14.5146),
|
35 |
+
"Vilnius": (54.6872, 25.2797),
|
36 |
+
"Bratislava": (48.1486, 17.1077),
|
37 |
+
"Ljubljana": (46.0569, 14.5058),
|
38 |
+
"Nicosia": (35.1856, 33.3823),
|
39 |
+
"Tallinn": (59.4370, 24.7536),
|
40 |
+
"Zagreb": (45.8150, 15.9819),
|
41 |
+
"Nicosia": (35.1856, 33.3823),
|
42 |
+
"Valletta": (35.8989, 14.5146)
|
43 |
+
}
|
44 |
+
|
45 |
+
# Coordinates of beach and mountain areas
|
46 |
+
beach_coordinates = (45.0, 10.0) # Example beach coordinates
|
47 |
+
mountain_coordinates = (48.0, 10.0) # Example mountain coordinates
|
48 |
+
|
49 |
+
# Function to determine the area based on proximity to beach or mountain
|
50 |
+
def determine_area(latitude, longitude):
|
51 |
+
city_coordinates = (latitude, longitude)
|
52 |
+
beach_distance = geodesic(city_coordinates, beach_coordinates).km
|
53 |
+
mountain_distance = geodesic(city_coordinates, mountain_coordinates).km
|
54 |
+
|
55 |
+
if beach_distance <= 200:
|
56 |
+
return "Beach"
|
57 |
+
elif mountain_distance <= 200:
|
58 |
+
return "Mountain"
|
59 |
+
else:
|
60 |
+
return "City"
|
61 |
+
|
62 |
+
# Create an empty DataFrame
|
63 |
+
df = pd.DataFrame(columns=["DMO", "City", "Latitude", "Longitude", "Area", "Environmental", "Cultural",
|
64 |
+
"Community", "Socio-economic", "Infrastructure", "Stakeholder",
|
65 |
+
"Visitor_education", "Monitoring"])
|
66 |
+
|
67 |
+
# Populate the DataFrame
|
68 |
+
for i in range(30):
|
69 |
+
dmo = dmo_names[i]
|
70 |
+
city = random.choice(list(cities.keys()))
|
71 |
+
latitude, longitude = cities[city]
|
72 |
+
area = determine_area(latitude, longitude)
|
73 |
+
environmental = round(random.uniform(0, 10), 2)
|
74 |
+
cultural = round(random.uniform(0, 10), 2)
|
75 |
+
community = round(random.uniform(0, 10), 2)
|
76 |
+
socio_economic = round(random.uniform(0, 10), 2)
|
77 |
+
infrastructure = round(random.uniform(0, 10), 2)
|
78 |
+
stakeholder = round(random.uniform(0, 10), 2)
|
79 |
+
visitor_education = round(random.uniform(0, 10), 2)
|
80 |
+
monitoring = round(random.uniform(0, 10), 2)
|
81 |
+
|
82 |
+
df.loc[i] = [dmo, city, latitude, longitude, area, environmental, cultural, community,
|
83 |
+
socio_economic, infrastructure, stakeholder, visitor_education, monitoring]
|
84 |
+
|
85 |
+
df.loc[df['DMO'].isin(['DMO14', 'DMO19', 'DMO27', 'DMO15', 'DMO20', 'DMO21']), 'Area'] = 'Beach'
|
86 |
+
df.loc[df['DMO'].isin(['DMO4', 'DMO23', 'DMO8']), 'Area'] = 'Mountain'
|
87 |
+
|
88 |
+
fig = px.scatter_mapbox(df, lat="Latitude", lon="Longitude", hover_name="DMO", hover_data=["Environmental", "Cultural",
|
89 |
+
"Community", "Socio-economic",
|
90 |
+
"Infrastructure", "Stakeholder",
|
91 |
+
"Visitor_education", "Monitoring"],
|
92 |
+
color="Area", color_discrete_sequence=["blue", "green", "red"], zoom=3)
|
93 |
+
|
94 |
+
fig.update_layout(mapbox_style="open-street-map")
|
95 |
+
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
|
96 |
+
|
97 |
+
st.plotly_chart(fig, use_container_width=True)
|
98 |
+
|
99 |
+
img = Image.open('mastercard_logo.png')
|
100 |
+
|
101 |
+
col1, col2, col3 = st.columns([1,6,1])
|
102 |
+
|
103 |
+
with col1:
|
104 |
+
st.write("")
|
105 |
+
|
106 |
+
with col2:
|
107 |
+
st.write("")
|
108 |
+
|
109 |
+
with col3:
|
110 |
+
st.image(img)
|
requirements.txt
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
geopy
|
2 |
joblib
|
|
|
3 |
pandas
|
4 |
plotly
|
5 |
scikit-learn==1.0.2
|
|
|
1 |
geopy
|
2 |
joblib
|
3 |
+
leafmap
|
4 |
pandas
|
5 |
plotly
|
6 |
scikit-learn==1.0.2
|