Spaces:
Sleeping
Sleeping
Commit
·
b302357
1
Parent(s):
8eedc88
omitted pmtiles and only showing 110 rows. But the map works and the stats are correct!
Browse files
app.py
CHANGED
@@ -44,21 +44,28 @@ ca_parquet = "ca_areas.parquet"
|
|
44 |
ca_area_acres = 1.014e8 #acres
|
45 |
|
46 |
style_choice = "GAP Status Code"
|
47 |
-
# style_choice = "Easement"
|
48 |
-
# style_choice = "Year"
|
49 |
|
50 |
con = ibis.duckdb.connect()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
ca = (con
|
52 |
.read_parquet(ca_parquet)
|
53 |
.cast({"SHAPE": "geometry"})
|
54 |
-
.mutate(
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
|
|
57 |
)
|
58 |
|
59 |
-
# print(ca.schema())
|
60 |
-
|
61 |
-
# ca = ca.filter(ca.Release_Year == 2024)
|
62 |
|
63 |
private_color = "#DE881E" # orange #"#850101" # red
|
64 |
tribal_color = "#BF40BF" # purple
|
@@ -68,11 +75,13 @@ year2023_color = "#26542C" # green
|
|
68 |
year2024_color = "#F3AB3D" # orange
|
69 |
|
70 |
|
|
|
71 |
|
72 |
|
73 |
def summary_table(column, colors):
|
|
|
74 |
df = (ca
|
75 |
-
|
76 |
.group_by(column)
|
77 |
.aggregate(hectares_protected = (_.area.sum() / 10000).round(),
|
78 |
percent_protected = 100 * _.Acres.sum() / ca_area_acres
|
@@ -104,27 +113,29 @@ def area_plot(df, column):
|
|
104 |
|
105 |
|
106 |
|
107 |
-
def pad_style(paint, alpha):
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
|
|
|
|
125 |
|
126 |
manager = {
|
127 |
-
'property': '
|
128 |
'type': 'categorical',
|
129 |
'stops': [
|
130 |
['Federal', "darkblue"],
|
@@ -155,7 +166,8 @@ easement = {
|
|
155 |
|
156 |
|
157 |
year = {
|
158 |
-
'property': '
|
|
|
159 |
'type': 'categorical',
|
160 |
'stops': [
|
161 |
[2023, year2023_color],
|
@@ -165,7 +177,7 @@ year = {
|
|
165 |
|
166 |
|
167 |
access = {
|
168 |
-
'property': '
|
169 |
'type': 'categorical',
|
170 |
'stops': [
|
171 |
['Open Access', public_color],
|
@@ -214,16 +226,20 @@ with st.sidebar:
|
|
214 |
|
215 |
style_choice = st.radio("Color by:", style_options)
|
216 |
alpha = st.slider("transparency", 0.0, 1.0, 0.5)
|
217 |
-
style =
|
218 |
-
|
|
|
|
|
|
|
219 |
|
220 |
|
221 |
select_column = {
|
222 |
"GAP Status Code": "reGAP",
|
223 |
-
"Management Agency": "
|
224 |
"Easement": "Easement",
|
225 |
-
"Year": "
|
226 |
-
|
|
|
227 |
|
228 |
|
229 |
|
@@ -261,3 +277,4 @@ with main:
|
|
261 |
st.divider()
|
262 |
footer = st.container()
|
263 |
|
|
|
|
44 |
ca_area_acres = 1.014e8 #acres
|
45 |
|
46 |
style_choice = "GAP Status Code"
|
|
|
|
|
47 |
|
48 |
con = ibis.duckdb.connect()
|
49 |
+
|
50 |
+
new2024 = (con
|
51 |
+
.read_parquet("new2024.parquet")
|
52 |
+
.select("OBJECTID")
|
53 |
+
.mutate(established = 2024)
|
54 |
+
)
|
55 |
+
|
56 |
+
|
57 |
ca = (con
|
58 |
.read_parquet(ca_parquet)
|
59 |
.cast({"SHAPE": "geometry"})
|
60 |
+
.mutate(area = _.SHAPE.area())
|
61 |
+
.filter(_.reGAP < 3)
|
62 |
+
.left_join(new2024, "OBJECTID")
|
63 |
+
.mutate(established=_.established.fill_null(2023))
|
64 |
+
.mutate(geom = _.SHAPE.convert("epsg:3310","epsg:4326"))
|
65 |
+
.rename(name = "UNIT_NAME", access_type = "ACCESS_TYP", manager = "MNG_AGNCY", manager_type = "MNG_AG_LEV", id = "OBJECTID")
|
66 |
+
.select(_.established, _.reGAP, _.name, _.access_type, _.manager, _.manager_type, _.Easement, _.Acres, _.id, _.geom, _.area, _.Release_Year)
|
67 |
)
|
68 |
|
|
|
|
|
|
|
69 |
|
70 |
private_color = "#DE881E" # orange #"#850101" # red
|
71 |
tribal_color = "#BF40BF" # purple
|
|
|
75 |
year2024_color = "#F3AB3D" # orange
|
76 |
|
77 |
|
78 |
+
gdf = ca.head(110).execute() #workaround since the data is too large...
|
79 |
|
80 |
|
81 |
def summary_table(column, colors):
|
82 |
+
|
83 |
df = (ca
|
84 |
+
.filter(_.Release_Year == 2024)
|
85 |
.group_by(column)
|
86 |
.aggregate(hectares_protected = (_.area.sum() / 10000).round(),
|
87 |
percent_protected = 100 * _.Acres.sum() / ca_area_acres
|
|
|
113 |
|
114 |
|
115 |
|
116 |
+
# def pad_style(paint, alpha):
|
117 |
+
# return {
|
118 |
+
# "version": 8,
|
119 |
+
# "sources": {
|
120 |
+
# "ca": {
|
121 |
+
# "type": "vector",
|
122 |
+
# "url": "pmtiles://" + ca_pmtiles,
|
123 |
+
# }},
|
124 |
+
# "layers": [{
|
125 |
+
# "id": "layer1",
|
126 |
+
# "source": "ca",
|
127 |
+
# "source-layer": "CA_Cons_Areas_parentlyr_Merge_ecofix",
|
128 |
+
# "type": "fill",
|
129 |
+
# "paint": {
|
130 |
+
# "fill-color": paint,
|
131 |
+
# "fill-opacity": alpha
|
132 |
+
# }
|
133 |
+
# }]}
|
134 |
+
|
135 |
+
|
136 |
|
137 |
manager = {
|
138 |
+
'property': 'manager_type',
|
139 |
'type': 'categorical',
|
140 |
'stops': [
|
141 |
['Federal', "darkblue"],
|
|
|
166 |
|
167 |
|
168 |
year = {
|
169 |
+
'property': 'established',
|
170 |
+
# 'property': 'Release_Year',
|
171 |
'type': 'categorical',
|
172 |
'stops': [
|
173 |
[2023, year2023_color],
|
|
|
177 |
|
178 |
|
179 |
access = {
|
180 |
+
'property': 'access_type',
|
181 |
'type': 'categorical',
|
182 |
'stops': [
|
183 |
['Open Access', public_color],
|
|
|
226 |
|
227 |
style_choice = st.radio("Color by:", style_options)
|
228 |
alpha = st.slider("transparency", 0.0, 1.0, 0.5)
|
229 |
+
style = style_options[style_choice]
|
230 |
+
paint = {"fill-color": style, "fill-opacity": alpha}
|
231 |
+
m.add_gdf(gdf,layer_type="fill",name = "CA 30x30",paint = paint)
|
232 |
+
m.add_layer_control()
|
233 |
+
|
234 |
|
235 |
|
236 |
select_column = {
|
237 |
"GAP Status Code": "reGAP",
|
238 |
+
"Management Agency": "manager_type",
|
239 |
"Easement": "Easement",
|
240 |
+
"Year": "established",
|
241 |
+
# "Year": "Release_Year",
|
242 |
+
"Public Access": "access_type"}
|
243 |
|
244 |
|
245 |
|
|
|
277 |
st.divider()
|
278 |
footer = st.container()
|
279 |
|
280 |
+
|