-
Notifications
You must be signed in to change notification settings - Fork 0
/
st_app.py
168 lines (130 loc) · 4.36 KB
/
st_app.py
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import folium
import streamlit as st
from folium.plugins import Draw
import xarray as xr
import get_results as gr
import warnings
warnings.filterwarnings('ignore')
import plotly.graph_objects as go
import numpy as np
from streamlit_folium import st_folium
st.set_page_config(layout='wide')
st.title("Dynamic Bharat - Changes in Land Use over time")
c1,c2 = st.columns([0.3, 0.7])
## fixed for hyderabad
locations = [
[17.48875008265665, 78.32539298515482],
[17.474619897520927, 78.39807339906744],
[17.31654690472666, 78.36400909034819],
[17.33003726964443, 78.28945900216388],
]
with c1:
m = folium.Map(location=[17.365548014635493, 79.26549911841008], zoom_start=13)
folium.Polygon(
locations=locations,
smooth_factor=2,
color="crimson",
no_clip=True,
tooltip="Hi there!",
).add_to(m)
# folium.TileLayer("OpenStreetMap", overlay=False).add_to(m)
folium.TileLayer(
tiles = 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',
attr = 'Esri',
name = 'Esri Satellite',
overlay = True,
control = True,
).add_to(m)
Draw(export=True).add_to(m)
folium.LayerControl().add_to(m)
output = st_folium(m, width=10000, height=600)
try:
coords = output['all_drawings'][0]['geometry']["coordinates"][0]
topLeft = coords[0]
bottomRight = coords[2]
print(coords)
except Exception as e:
print(e)
r = None
try:
if r == None:
r = gr.get_results(topLeft, bottomRight)
print('got the results')
else:
pass
except Exception as e:
print(e)
with c2:
if r is not None:
option = st.radio("Select the class", options=["buildings", "roads", "trees", 'water'] )
if option == 'buildings':
results = r[0]
elif option == 'roads':
results = r[1]
elif option == 'trees':
results = r[2]
else:
results = r[3]
count_1_xarr1 = results['count_1_xarr1']
count_1_xarr2 = results['count_1_xarr2']
abs_change_1 = results['absolute_change_1']
pct_change_1 = results['percentage_change_1']
bs_change_0 = results['absolute_change_0']
pct_change_0 = results['percentage_change_0']
area_1 = count_1_xarr1*1.14
area_2 = count_1_xarr2*1.14
labels = ["2020", "2023"]
values = [count_1_xarr1, count_1_xarr2]
co1, co2 = st.columns(2)
# Create a bar chart with Plotly for count values only
fig = go.Figure()
# Add bar chart
fig.add_trace(go.Bar(
x=labels,
y=values,
name="Counts",
text=values,
textposition="auto"
))
# Add line chart
fig.add_trace(go.Scatter(
x=labels,
y=values,
mode='lines+markers',
name="Count Trend",
line=dict(color='royalblue', width=2),
marker=dict(size=8)
))
# Customize layout
fig.update_layout(
title="Counts with Bar and Line Chart",
xaxis_title="Variables",
yaxis_title="Values",
template="plotly_white"
)
# Display the plot in Streamlit
co1.plotly_chart(fig)
# Create labels and values for the pie chart
area_labels = ["2020", "2023"]
area_values = [area_1, area_2]
# Create a pie chart for area values
fig_pie = go.Figure(data=[go.Pie(labels=area_labels, values=area_values, hole=0.3)])
# Customize layout for pie chart
fig_pie.update_layout(
title="Area Distribution",
template="plotly_white"
)
# Display the pie chart in Streamlit
co2.plotly_chart(fig_pie)
annotations = [
f"abs_change_1: {abs_change_1}",
f"pct_change_1: {pct_change_1}",
f"bs_change_0: {bs_change_0}",
f"pct_change_0: {pct_change_0}"
]
# Display the plot in Streamlit
st.write("### Key Changes")
col1, col2, col3 = st.columns(3)
col1.metric(label="Absolute Change 1", value=f"{abs_change_1/10000}sq.km")
col2.metric(label="Percentage Change 1", value=f"{pct_change_1:2f}%")
col3.metric(label="Percentage Change 0", value=f"{pct_change_0:2f}%")