Spaces:
Sleeping
Sleeping
Commit
·
59b4a4b
1
Parent(s):
594ef00
preprocessed data and using pmtiles. map is working and displays all data.
Browse files- app.py +31 -52
- ca2024.parquet +3 -0
app.py
CHANGED
@@ -7,6 +7,7 @@ import ibis
|
|
7 |
from ibis import _
|
8 |
import ibis.selectors as s
|
9 |
|
|
|
10 |
from typing import Optional
|
11 |
def to_streamlit(
|
12 |
self,
|
@@ -34,38 +35,20 @@ def to_streamlit(
|
|
34 |
raise Exception(e)
|
35 |
|
36 |
|
37 |
-
|
38 |
-
|
39 |
-
# ca_pmtiles = "ca_areas.pmtiles"
|
40 |
-
|
41 |
-
# ca_parquet = "https://data.source.coop/cboettig/ca30x30/ca_areas.parquet"
|
42 |
-
ca_parquet = "ca_areas.parquet"
|
43 |
|
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({"
|
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,17 +58,11 @@ year2023_color = "#26542C" # green
|
|
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(
|
87 |
-
percent_protected = 100 * _.Acres.sum() / ca_area_acres
|
88 |
-
)
|
89 |
.mutate(percent_protected = _.percent_protected.round(1),
|
90 |
)
|
91 |
.inner_join(colors, column)
|
@@ -102,7 +79,7 @@ def area_plot(df, column):
|
|
102 |
pie = ( base
|
103 |
.mark_arc(innerRadius= 40, outerRadius=100)
|
104 |
.encode(alt.Color("color:N").scale(None).legend(None),
|
105 |
-
tooltip=['percent_protected',
|
106 |
)
|
107 |
text = ( base
|
108 |
.mark_text(radius=80, size=14, color="white")
|
@@ -113,25 +90,25 @@ def area_plot(df, column):
|
|
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 |
manager = {
|
@@ -226,9 +203,11 @@ with st.sidebar:
|
|
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 |
|
|
|
7 |
from ibis import _
|
8 |
import ibis.selectors as s
|
9 |
|
10 |
+
|
11 |
from typing import Optional
|
12 |
def to_streamlit(
|
13 |
self,
|
|
|
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
|
|
|
42 |
style_choice = "GAP Status Code"
|
43 |
|
44 |
con = ibis.duckdb.connect()
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
ca = (con
|
47 |
.read_parquet(ca_parquet)
|
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
|
|
|
58 |
year2024_color = "#F3AB3D" # orange
|
59 |
|
60 |
|
|
|
|
|
|
|
61 |
def summary_table(column, colors):
|
62 |
|
63 |
df = (ca
|
|
|
64 |
.group_by(column)
|
65 |
+
.aggregate(percent_protected = 100 * _.Acres.sum() / ca_area_acres)
|
|
|
|
|
66 |
.mutate(percent_protected = _.percent_protected.round(1),
|
67 |
)
|
68 |
.inner_join(colors, column)
|
|
|
79 |
pie = ( base
|
80 |
.mark_arc(innerRadius= 40, outerRadius=100)
|
81 |
.encode(alt.Color("color:N").scale(None).legend(None),
|
82 |
+
tooltip=['percent_protected', column])
|
83 |
)
|
84 |
text = ( base
|
85 |
.mark_text(radius=80, size=14, color="white")
|
|
|
90 |
|
91 |
|
92 |
|
93 |
+
def pad_style(paint, alpha):
|
94 |
+
return {
|
95 |
+
"version": 8,
|
96 |
+
"sources": {
|
97 |
+
"ca": {
|
98 |
+
"type": "vector",
|
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 = {
|
|
|
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 |
|
ca2024.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ff6aa87ade59c9811346e1dd2eb68626d6b9de95bc4ee8071c7bef43a73396ec
|
3 |
+
size 137445912
|