cassiebuhler commited on
Commit
2c93f68
·
1 Parent(s): 59b4a4b

adding filters to app

Browse files
Files changed (2) hide show
  1. app.py +45 -25
  2. ca2024.parquet +2 -2
app.py CHANGED
@@ -35,7 +35,8 @@ def to_streamlit(
35
  raise Exception(e)
36
 
37
 
38
- ca_pmtiles = "https://huggingface.co/datasets/boettiger-lab/ca-30x30/resolve/main/ca2024.pmtiles"
 
39
  ca_parquet = "ca2024.parquet"
40
 
41
  ca_area_acres = 1.014e8 #acres
@@ -48,8 +49,6 @@ ca = (con
48
  .cast({"geom": "geometry"})
49
  )
50
 
51
- # gdf = ca.head(250).execute() #workaround since the data is too large...
52
-
53
  private_color = "#DE881E" # orange #"#850101" # red
54
  tribal_color = "#BF40BF" # purple
55
  mixed_color = "#005a00" # green
@@ -99,17 +98,42 @@ def pad_style(paint, alpha):
99
  "url": "pmtiles://" + ca_pmtiles,
100
  }},
101
  "layers": [{
102
- "id": "layer1",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  "source": "ca",
104
  "source-layer": "ca2024",
105
- # "source-layer": "CA_Cons_Areas_parentlyr_Merge_ecofix",
106
  "type": "fill",
 
107
  "paint": {
108
  "fill-color": paint,
109
  "fill-opacity": alpha
110
  }
111
  }]}
112
 
 
 
 
 
 
 
113
 
114
  manager = {
115
  'property': 'manager_type',
@@ -117,21 +141,19 @@ manager = {
117
  'stops': [
118
  ['Federal', "darkblue"],
119
  ['State', public_color],
120
- ['Non Profit', "lightblue"],
121
  ['Special District', "darkgreen"],
122
- ['', "grey"],
 
 
123
  ['Joint', "green"],
124
  ['Tribal', tribal_color],
125
  ['Private', "darkred"],
126
- ['City', "pink"],
127
- ['County', "blue"],
128
  ['Home Owners Association', "lightgreen"]
129
  ]
130
  }
131
 
132
 
133
-
134
-
135
  easement = {
136
  'property': 'Easement',
137
  'type': 'categorical',
@@ -144,7 +166,6 @@ easement = {
144
 
145
  year = {
146
  'property': 'established',
147
- # 'property': 'Release_Year',
148
  'type': 'categorical',
149
  'stops': [
150
  [2023, year2023_color],
@@ -187,7 +208,6 @@ style_options = {
187
  }
188
 
189
 
190
-
191
  st.set_page_config(layout="wide", page_title="CA Protected Areas Explorer", page_icon=":globe:")
192
 
193
  '''
@@ -198,17 +218,20 @@ st.set_page_config(layout="wide", page_title="CA Protected Areas Explorer", page
198
  m = leafmap.Map(style="positron")
199
 
200
  with st.sidebar:
201
-
202
  if st.toggle("Protected Areas", True):
203
-
204
- style_choice = st.radio("Color by:", style_options)
205
  alpha = st.slider("transparency", 0.0, 1.0, 0.5)
206
- # style = style_options[style_choice]
207
- # paint = {"fill-color": style, "fill-opacity": alpha}
208
- # m.add_gdf(gdf,layer_type="fill",name = "CA 30x30",paint = paint)
209
- style = pad_style(style_options[style_choice], alpha)
210
- m.add_pmtiles(ca_pmtiles, style=style, visible=True, opacity=alpha, tooltip=True)
211
- m.add_layer_control()
 
 
 
 
 
212
 
213
 
214
 
@@ -217,12 +240,9 @@ select_column = {
217
  "Management Agency": "manager_type",
218
  "Easement": "Easement",
219
  "Year": "established",
220
- # "Year": "Release_Year",
221
  "Public Access": "access_type"}
222
 
223
 
224
-
225
-
226
  column = select_column[style_choice]
227
 
228
  select_colors = {
 
35
  raise Exception(e)
36
 
37
 
38
+ ca_pmtiles = "https://huggingface.co/datasets/boettiger-lab/ca-30x30/resolve/main/ca2024-tippe.pmtiles"
39
+ # ca_parquet = "https://huggingface.co/datasets/boettiger-lab/ca-30x30/resolve/main/ca2024.parquet"
40
  ca_parquet = "ca2024.parquet"
41
 
42
  ca_area_acres = 1.014e8 #acres
 
49
  .cast({"geom": "geometry"})
50
  )
51
 
 
 
52
  private_color = "#DE881E" # orange #"#850101" # red
53
  tribal_color = "#BF40BF" # purple
54
  mixed_color = "#005a00" # green
 
98
  "url": "pmtiles://" + ca_pmtiles,
99
  }},
100
  "layers": [{
101
+ "id": "ca30x30",
102
+ "source": "ca",
103
+ "source-layer": "ca2024",
104
+ "type": "fill",
105
+ "paint": {
106
+ "fill-color": paint,
107
+ "fill-opacity": alpha
108
+ }
109
+ }]}
110
+
111
+ def filter_pmtiles(paint, alpha, column, items):
112
+ return {
113
+ "version": 8,
114
+ "sources": {
115
+ "ca": {
116
+ "type": "vector",
117
+ "url": "pmtiles://" + ca_pmtiles,
118
+ }},
119
+ "layers": [{
120
+ "id": "ca30x30",
121
  "source": "ca",
122
  "source-layer": "ca2024",
 
123
  "type": "fill",
124
+ "filter": ["match", ["get", column], items, True, False],
125
  "paint": {
126
  "fill-color": paint,
127
  "fill-opacity": alpha
128
  }
129
  }]}
130
 
131
+ def getButtons(style_options, style_choice):
132
+ column = style_options[style_choice]['property']
133
+ opts = [style[0] for style in style_options[style_choice]['stops']]
134
+ buttons = {name: st.checkbox(f"{name}", value = True) for name in opts}
135
+ return column, buttons
136
+
137
 
138
  manager = {
139
  'property': 'manager_type',
 
141
  'stops': [
142
  ['Federal', "darkblue"],
143
  ['State', public_color],
144
+ ['Non Profit', "orange"],
145
  ['Special District', "darkgreen"],
146
+ ['Unknown', "grey"],
147
+ ['County', "lightblue"],
148
+ ['City', "pink"],
149
  ['Joint', "green"],
150
  ['Tribal', tribal_color],
151
  ['Private', "darkred"],
 
 
152
  ['Home Owners Association', "lightgreen"]
153
  ]
154
  }
155
 
156
 
 
 
157
  easement = {
158
  'property': 'Easement',
159
  'type': 'categorical',
 
166
 
167
  year = {
168
  'property': 'established',
 
169
  'type': 'categorical',
170
  'stops': [
171
  [2023, year2023_color],
 
208
  }
209
 
210
 
 
211
  st.set_page_config(layout="wide", page_title="CA Protected Areas Explorer", page_icon=":globe:")
212
 
213
  '''
 
218
  m = leafmap.Map(style="positron")
219
 
220
  with st.sidebar:
221
+
222
  if st.toggle("Protected Areas", True):
 
 
223
  alpha = st.slider("transparency", 0.0, 1.0, 0.5)
224
+ style_choice = st.radio("Color by:", style_options)
225
+
226
+
227
+ with st.expander(style_choice, expanded=True):
228
+ column, buttons = getButtons(style_options, style_choice)
229
+ option_choice = [key for key, value in buttons.items() if value] #return only the options selected
230
+
231
+ # If any options are selected, apply the filter
232
+ if option_choice:
233
+ style = filter_pmtiles(style_options[style_choice], alpha, column, option_choice)
234
+ m.add_pmtiles(ca_pmtiles, style=style, visible=True, name="CA", opacity=alpha, tooltip=True)
235
 
236
 
237
 
 
240
  "Management Agency": "manager_type",
241
  "Easement": "Easement",
242
  "Year": "established",
 
243
  "Public Access": "access_type"}
244
 
245
 
 
 
246
  column = select_column[style_choice]
247
 
248
  select_colors = {
ca2024.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:ff6aa87ade59c9811346e1dd2eb68626d6b9de95bc4ee8071c7bef43a73396ec
3
- size 137445912
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:10bbe99e2b1b732cbc21ace67c38a0d1c16a1e638a17bd25a5686b3052379552
3
+ size 137419604