-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py.old
72 lines (57 loc) · 2.7 KB
/
app.py.old
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Import the required libraries
import osmnx as ox
import geopandas as gpd
import pandas as pd
import streamlit as st
# Define the example coordinates and descriptions
example_coordinates = {
"Hagenberg, Austria": (48.36964, 14.5128),
"Lienz (Daniel), Austria": (46.8294, 12.7687),
"FTA-Communauté de communes du Guillestrois-Queyras , France": (44.6616, 6.6497),
"LTA-Communauté de communes des Baronnies en Drôme Provençale, France": (44.3555, 5.1283),
"Loeffingen-LTA (Anna), Germany": (47.8840, 8.3438),
"Elztal-FTA (Anna), Germany": (48.1442, 8.0474),
"Elzach-FTA (Anna), Germany": (48.1731, 8.0686),
"Cogne (Alessio), Italy": (45.6081, 7.3527),
"LTA (Darja), Slovenia": (46.6581, 16.1631),
"FTA (Darja), Slovenia": (46.5530, 15.6509)
}
def main():
# Set up the Streamlit app
st.title("Smart CommUnity - TA Analyzer")
# Add a selection menu for the user to choose an example
example_choice = st.selectbox("Choose a Test Area:", list(example_coordinates.keys()))
# Retrieve the selected example coordinates
selected_coordinate = example_coordinates[example_choice]
lat = st.number_input("Enter the latitude of the area:", value=selected_coordinate[0])
lon = st.number_input("Enter the longitude of the area:", value=selected_coordinate[1])
zoom = st.slider("Zoom level:", min_value=1, max_value=18, value=10)
# Allow the user to select the data to display
show_buildings = st.checkbox("Show Buildings")
show_amenities = st.checkbox("Show Amenities")
# Retrieve the graph from OpenStreetMap
G = ox.graph_from_point((lat, lon), network_type='all', dist=1000)
# Get a list of the features (buildings and/or amenities)
features = []
if show_buildings:
buildings = ox.geometries_from_point((lat, lon), tags={'building': True}, dist=1000)
features.append(buildings)
if show_amenities:
try:
amenities = ox.geometries_from_point((lat, lon), tags={'amenity': True}, dist=1000)
features.append(amenities)
except:
st.warning("No amenities found within the specified distance.")
# Concatenate the features GeoDataFrames
if len(features) > 0:
features = gpd.GeoDataFrame(pd.concat(features, ignore_index=True), crs="EPSG:4326")
# Plot the graph using OSMnx
fig, ax = ox.plot_graph(G, show=False, close=False, edge_color='gray', edge_linewidth=1, edge_alpha=0.5, figsize=(10, 10))
ax.set_title('Visualization')
# Plot the features (buildings and/or amenities)
if len(features) > 0:
features.plot(ax=ax, color='red', alpha=0.7)
# Display the plot in the Streamlit app
st.pyplot(fig)
if __name__ == "__main__":
main()