-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmap_utils.py
208 lines (185 loc) · 5.15 KB
/
map_utils.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import folium
import leafmap.foliumap as leafmap
import streamlit as st
# from data import config
def make_map(full_gdf,apns,pipes):
# st.dataframe(apns.drop(columns=['geometry']))
lines = [
# 'Proposed Pipeline',
'AEWSD North Canal',
'FFPPP Discharge Pipeline',
# "AEWSD Alignments",
]
filled_polygons = ['Frick Unit Service Area']
hollow_polygons = ['District Boundary']
points = ['Proposed Turnout']
clip_layers = [
'Proposed Turnout',
# 'Proposed Pipeline',
"Frick Unit Service Area",
# "AEWSD Alignments",
]
service_boundary = full_gdf.pipe(lambda df:df.loc[df['label'] == "Frick Unit North Service Area"])
intersect = lambda gdf: gdf[gdf.intersects(service_boundary.unary_union)]
clip = lambda gdf: gdf.clip(service_boundary)
apns = apns.to_crs("EPSG:4326")
# find interescting shapes
# intersecting_apns = apns[apns.intersects(service_boundary.unary_union)]
m = leafmap.Map(
# tiles="https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}",
# attr="Esri",
google_map="HYBRID",
min_zoom=3,
# max_zoom=12,
# min_lat=bounds[2],
# max_lat=bounds[3],
# min_lon=bounds[0],
# max_lon=bounds[1],
# max_bounds=True,
# zoom_control=False,
draw_control=False,
search_control=False,
)
for layer in hollow_polygons:
try:
gdf = full_gdf[full_gdf['layer']==layer]
if layer in clip_layers:
gdf = clip(gdf)
# gdf = intersect(gdf)
color = gdf['color'].unique()[0]
m.add_gdf(
gdf,
layer_name=layer,
# style_function=lambda x: {"color": "red", "fillOpacity": 0},
fields=['layer'],
highlight_function=lambda x: {"fillOpacity": 0.7, "weight": 6, "color": "lightgreen"},
style={
'color':color,
'fillColor':"none",
},
# highlight_function=lambda x: x['properties'],
# highlight_function=lambda x: {"l":x['properties']['label']},
# highlight_function=lambda x: {"l":x['properties']['label']},
)
except:
pass
# st.markdown(f"Error with {layer}")
# print(f"Error with {layer}")
for layer in filled_polygons:
try:
gdf = full_gdf[full_gdf['layer']==layer]
if layer in clip_layers:
gdf = clip(gdf)
# gdf = intersect(gdf)
color = gdf['color'].unique()[0]
m.add_gdf(
gdf,
layer_name=layer,
# highlight_function=lambda x: {"l":x['properties']['label']},
fields=['layer'],
highlight_function=lambda x: {"fillOpacity": 0.4, "weight": 6, "color": "lightgreen"},
style={
# 'color':color,
'color':"none",
'fillColor':color,
"tooltip":"label",
},
# tooltip="label",
zoom_to_layer=True,
)
except:
st.markdown(f"Error with {layer}")
# print(f"Error with {layer}")
intersecting_apns = apns[apns.intersects(service_boundary.unary_union)]
# st.dataframe(intersecting_apns.drop(columns=['geometry']))
apn_gdf = intersecting_apns#)
apn_gdf['size'] = apn_gdf.geometry.area
# apn_gdf = apns
# st.dataframe(apn_gdf.drop(columns=['geometry']))
m.add_gdf(
apn_gdf,
layer_name="APNs",
# style_function=lambda x: {"color": "red", "fillOpacity": 0},
fields=['APN','Acreage','Landowner'],
# highlight_function=lambda x: {"fillOpacity": 0.7, "weight": 6, "color": "lightgreen"},
style={
'color':"white",
"weight":0.5,
},
)
for layer in points:
try:
gdf = full_gdf[full_gdf['layer']==layer]
if layer in clip_layers:
gdf = clip(gdf)
# intersect(gdf)
color = gdf['color'].unique()[0]
for i,y in gdf.iterrows():
folium.Circle(
radius=30,
location=[y.geometry.y,y.geometry.x],
color=y['color'],
fill=True,
# tooltip=[y["label"]],
tooltip="Proposed Turnout",
).add_to(m)
# add apns and labels
except:
st.markdown(f"Error with {layer}")
for layer in lines:
try:
gdf = full_gdf[full_gdf['layer']==layer]
# st.markdown(layer)
# st.markdown(gdf.crs)
if layer in clip_layers:
gdf = clip(gdf)
# intersect(gdf)
color = gdf['color'].unique()[0]
m.add_gdf(
gdf,
layer_name=layer,
fields=['layer','label'],
highlight_function=lambda x: {"fillOpacity": 0.7, "weight": 6, "color": "lightgreen"},
# tooltip="label",
style={'color': color},
)
except:
pass
# st.markdown(f"Error with {layer}")
# apns.crs = "EPSG:4326"
# st.markdown(apns.crs)
# apn_gdf = clip(apns.to_crs("EPSG:4326"))
# apn_gdf = clip(apns)
# apn_gdf = apns.to_crs("EPSG:4326")
gdf = pipes
# st.markdown(layer)
# st.markdown(gdf.crs)
# if layer in clip_layers:
# gdf = clip(gdf)
# intersect(gdf)
color = 'orange'
m.add_gdf(
gdf,
layer_name="Proposed Pipeline",
fields=['layer','label'],
highlight_function=lambda x: {"fillOpacity": 0.7, "weight": 6, "color": "lightgreen"},
# tooltip="label",
style={'color': color},
)
m.add_legend(
title="Legend",
legend_dict={
"Proposed Pipeline": "orange",
# "AEWSD Alignments": "orange",
"AEWSD North Canal": "#0000ff",
"FFPPP Discharge Pipeline": "red",
"Frick Unit Service Area": "salmon",
"District Boundary": "#000000",
"Proposed Turnout": "#ffff00",
"APN": "white",
}
)
m.zoom_to_gdf(apn_gdf)
# m.fit_bounds(bounds=ll_bounds,max_zoom=12)
# m.set_max_bounds(ll_bounds)
return m