Spaces:
Sleeping
Sleeping
reqs
Browse files- preprocess.ipynb +1 -1
- requirements.txt +1 -1
- static-maps.ipynb +196 -109
preprocess.ipynb
CHANGED
@@ -119,7 +119,7 @@
|
|
119 |
"name": "python",
|
120 |
"nbconvert_exporter": "python",
|
121 |
"pygments_lexer": "ipython3",
|
122 |
-
"version": "3.10
|
123 |
}
|
124 |
},
|
125 |
"nbformat": 4,
|
|
|
119 |
"name": "python",
|
120 |
"nbconvert_exporter": "python",
|
121 |
"pygments_lexer": "ipython3",
|
122 |
+
"version": "3.11.10"
|
123 |
}
|
124 |
},
|
125 |
"nbformat": 4,
|
requirements.txt
CHANGED
@@ -159,7 +159,7 @@ xyzservices==2024.9.0
|
|
159 |
yarl==1.9.7
|
160 |
overturemaps
|
161 |
tippecanoe
|
162 |
-
pandasai
|
163 |
seaborn
|
164 |
numpy==1.26.4
|
165 |
pandas
|
|
|
159 |
yarl==1.9.7
|
160 |
overturemaps
|
161 |
tippecanoe
|
162 |
+
pandasai==2.3.0
|
163 |
seaborn
|
164 |
numpy==1.26.4
|
165 |
pandas
|
static-maps.ipynb
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
-
"execution_count":
|
6 |
"id": "b313a218-4778-4d5b-9036-f0370d4212a0",
|
7 |
"metadata": {},
|
8 |
"outputs": [],
|
@@ -10,8 +10,6 @@
|
|
10 |
"import ibis\n",
|
11 |
"from ibis import _\n",
|
12 |
"import streamlit as st\n",
|
13 |
-
"import ibis.expr.datatypes as dt # Make sure to import the necessary module\n",
|
14 |
-
"\n",
|
15 |
"\n",
|
16 |
"conn = ibis.duckdb.connect(extensions=[\"spatial\"])\n",
|
17 |
"\n",
|
@@ -29,28 +27,20 @@
|
|
29 |
},
|
30 |
{
|
31 |
"cell_type": "code",
|
32 |
-
"execution_count":
|
33 |
"id": "ba4d8915-cde3-4ef9-ad8c-7759ed2c8a13",
|
34 |
"metadata": {},
|
35 |
"outputs": [],
|
36 |
"source": [
|
37 |
"vote_county = (votes\n",
|
38 |
-
"
|
39 |
-
"
|
40 |
-
"
|
41 |
-
"
|
42 |
-
"
|
43 |
-
"
|
44 |
-
"
|
45 |
-
"
|
46 |
-
" yes=ibis.case()\n",
|
47 |
-
" .when(_.yes.isin(['Pass', 'None','Fail']), None) # Handle non-numeric cases\n",
|
48 |
-
" .when(_.yes.notnull(), (_.yes.replace('%', '').cast('float').round(2).cast(dt.float64)).cast(dt.string) + '%') # Convert valid percentages and add %\n",
|
49 |
-
" .else_(None) # Default to None for other cases\n",
|
50 |
-
" .end()\n",
|
51 |
-
" )\n",
|
52 |
-
" .mutate(log_amount = _.log_amount.round(4))\n",
|
53 |
-
" .select('key', 'Status', 'yes', 'year', 'amount', 'log_amount', )\n",
|
54 |
" )\n",
|
55 |
"df_county = (county\n",
|
56 |
" .join(states.select(\"state\", \"state_id\"), \"state\")\n",
|
@@ -65,7 +55,7 @@
|
|
65 |
},
|
66 |
{
|
67 |
"cell_type": "code",
|
68 |
-
"execution_count":
|
69 |
"id": "0cce23c9-245c-4c28-9523-0231eb5acc17",
|
70 |
"metadata": {},
|
71 |
"outputs": [],
|
@@ -78,14 +68,6 @@
|
|
78 |
" .mutate(amount_n=_.amount.replace('$', '').replace(',', '').cast('float'))\n",
|
79 |
" .mutate(log_amount=_.amount_n.log())\n",
|
80 |
" .mutate(year=_['Date'].year().cast('int32'))\n",
|
81 |
-
" .mutate(\n",
|
82 |
-
" yes=ibis.case()\n",
|
83 |
-
" .when(_.yes.isin(['Pass', 'None','Fail']), None) # Handle non-numeric cases\n",
|
84 |
-
" .when(_.yes.notnull(), (_.yes.replace('%', '').cast('float').round(2).cast(dt.float64)).cast(dt.string) + '%') # Convert valid percentages and add %\n",
|
85 |
-
" .else_(None) # Default to None for other cases\n",
|
86 |
-
" .end()\n",
|
87 |
-
" )\n",
|
88 |
-
" .mutate(log_amount = _.log_amount.round(4))\n",
|
89 |
" .select('key', 'Status', 'yes', 'year', 'amount', 'log_amount', )\n",
|
90 |
" )\n",
|
91 |
"\n",
|
@@ -96,24 +78,87 @@
|
|
96 |
" .drop('key_right')\n",
|
97 |
" .mutate(jurisdiction = ibis.literal(\"Municipal\"))\n",
|
98 |
" .cast({\"geometry\": \"geometry\"})\n",
|
99 |
-
"
|
100 |
" )\n"
|
101 |
]
|
102 |
},
|
103 |
{
|
104 |
"cell_type": "code",
|
105 |
-
"execution_count":
|
106 |
"id": "a1e81807-8ce3-44bf-9a1c-8563fa33817c",
|
107 |
"metadata": {},
|
108 |
"outputs": [],
|
109 |
"source": [
|
110 |
-
"df = df_county.union(df_local)\n"
|
111 |
-
"# df.execute()"
|
112 |
]
|
113 |
},
|
114 |
{
|
115 |
"cell_type": "code",
|
116 |
-
"execution_count":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
"id": "5d3bee26-7ca8-490c-be5b-fc69a6c3db2a",
|
118 |
"metadata": {},
|
119 |
"outputs": [
|
@@ -123,7 +168,7 @@
|
|
123 |
"text": [
|
124 |
"The token has not been saved to the git credentials helper. Pass `add_to_git_credential=True` in this function directly or `--add-to-git-credential` if using via `huggingface-cli` if you want to set the git credential as well.\n",
|
125 |
"Token is valid (permission: write).\n",
|
126 |
-
"Your token has been saved to /home/
|
127 |
"Login successful\n"
|
128 |
]
|
129 |
}
|
@@ -154,10 +199,10 @@
|
|
154 |
" command = [\n",
|
155 |
" \"tippecanoe\",\n",
|
156 |
" \"-o\", output_file,\n",
|
157 |
-
" \"-
|
|
|
158 |
" \"--extend-zooms-if-still-dropping\",\n",
|
159 |
" \"--force\",\n",
|
160 |
-
" \"--projection\", \"EPSG:4326\", \n",
|
161 |
" input_file\n",
|
162 |
" ]\n",
|
163 |
"\n",
|
@@ -172,49 +217,88 @@
|
|
172 |
},
|
173 |
{
|
174 |
"cell_type": "code",
|
175 |
-
"execution_count":
|
176 |
-
"id": "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
177 |
"metadata": {},
|
178 |
"outputs": [
|
179 |
{
|
180 |
"data": {
|
181 |
-
"
|
182 |
-
"
|
183 |
-
"
|
184 |
-
"
|
185 |
-
|
186 |
-
|
187 |
-
"
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
{
|
194 |
-
"data": {
|
195 |
-
"application/vnd.jupyter.widget-view+json": {
|
196 |
-
"model_id": "c7314c0c7d9948c9a3feaddadccde55b",
|
197 |
-
"version_major": 2,
|
198 |
-
"version_minor": 0
|
199 |
-
},
|
200 |
"text/plain": [
|
201 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
202 |
]
|
203 |
},
|
|
|
204 |
"metadata": {},
|
205 |
-
"output_type": "
|
206 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
207 |
{
|
208 |
"name": "stderr",
|
209 |
"output_type": "stream",
|
210 |
"text": [
|
211 |
"For layer 0, using name \"vote\"\n",
|
212 |
-
"vote.geojson:496: null geometry (additional not reported): in JSON object {\"type\":\"Feature\",\"properties\":{\"key\":null,\"Status\":\"Fail\",\"yes\":\"43.
|
213 |
-
"2195 features,
|
214 |
-
"
|
215 |
-
"
|
216 |
-
" 99.9% 11/189/562 \n",
|
217 |
-
" 100.0% 11/110/897 \r"
|
218 |
]
|
219 |
},
|
220 |
{
|
@@ -223,66 +307,64 @@
|
|
223 |
"text": [
|
224 |
"Successfully generated PMTiles file: vote.pmtiles\n"
|
225 |
]
|
226 |
-
},
|
227 |
-
{
|
228 |
-
"data": {
|
229 |
-
"application/vnd.jupyter.widget-view+json": {
|
230 |
-
"model_id": "1176d2d9c19e45539fc9efc2a60db944",
|
231 |
-
"version_major": 2,
|
232 |
-
"version_minor": 0
|
233 |
-
},
|
234 |
-
"text/plain": [
|
235 |
-
"vote.pmtiles: 0%| | 0.00/4.81M [00:00<?, ?B/s]"
|
236 |
-
]
|
237 |
-
},
|
238 |
-
"metadata": {},
|
239 |
-
"output_type": "display_data"
|
240 |
}
|
241 |
],
|
242 |
"source": [
|
243 |
-
"
|
244 |
-
"gdf = gdf.set_crs(\"EPSG:4326\")\n",
|
245 |
-
"# print(gdf.crs)\n",
|
246 |
-
"# gdf.to_parquet(\"votes.parquet\")\n",
|
247 |
-
"\n",
|
248 |
-
"gdf.to_file(\"vote.geojson\")\n",
|
249 |
-
"hf_upload(\"vote.geojson\", \"boettiger-lab/landvote\")\n",
|
250 |
-
"\n",
|
251 |
-
"generate_pmtiles(\"vote.geojson\", \"vote.pmtiles\")\n",
|
252 |
-
"hf_upload(\"vote.pmtiles\", \"boettiger-lab/landvote\")\n",
|
253 |
-
"\n"
|
254 |
]
|
255 |
},
|
256 |
{
|
257 |
"cell_type": "code",
|
258 |
-
"execution_count":
|
259 |
-
"id": "
|
260 |
-
"metadata": {
|
261 |
-
"scrolled": true
|
262 |
-
},
|
263 |
"outputs": [
|
264 |
{
|
265 |
"data": {
|
266 |
-
"application/vnd.jupyter.widget-view+json": {
|
267 |
-
"model_id": "d829e5753c414cc2887dac52fd35dc82",
|
268 |
-
"version_major": 2,
|
269 |
-
"version_minor": 1
|
270 |
-
},
|
271 |
"text/plain": [
|
272 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
273 |
]
|
274 |
},
|
275 |
-
"execution_count":
|
276 |
"metadata": {},
|
277 |
"output_type": "execute_result"
|
278 |
}
|
279 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
280 |
"source": [
|
281 |
"import leafmap.maplibregl as leafmap\n",
|
282 |
"m = leafmap.Map(style=\"positron\")\n",
|
283 |
"\n",
|
284 |
"url = \"https://huggingface.co/datasets/boettiger-lab/landvote/resolve/main/vote.pmtiles\"\n",
|
285 |
"\n",
|
|
|
|
|
|
|
286 |
"outcome = [\n",
|
287 |
" 'match',\n",
|
288 |
" ['get', 'Status'], \n",
|
@@ -304,7 +386,7 @@
|
|
304 |
" \"filter\": [\n",
|
305 |
" \"==\",\n",
|
306 |
" [\"get\", \"year\"],\n",
|
307 |
-
"
|
308 |
" ], # only show buildings with height info\n",
|
309 |
" \"paint\": paint\n",
|
310 |
" },\n",
|
@@ -319,15 +401,20 @@
|
|
319 |
" tooltip=True,\n",
|
320 |
" fit_bounds=False,\n",
|
321 |
")\n",
|
322 |
-
"\n",
|
323 |
"m\n",
|
324 |
-
"\n"
|
|
|
|
|
|
|
|
|
|
|
325 |
]
|
326 |
},
|
327 |
{
|
328 |
"cell_type": "code",
|
329 |
"execution_count": null,
|
330 |
-
"id": "
|
331 |
"metadata": {},
|
332 |
"outputs": [],
|
333 |
"source": []
|
@@ -349,7 +436,7 @@
|
|
349 |
"name": "python",
|
350 |
"nbconvert_exporter": "python",
|
351 |
"pygments_lexer": "ipython3",
|
352 |
-
"version": "3.10
|
353 |
}
|
354 |
},
|
355 |
"nbformat": 4,
|
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
+
"execution_count": 26,
|
6 |
"id": "b313a218-4778-4d5b-9036-f0370d4212a0",
|
7 |
"metadata": {},
|
8 |
"outputs": [],
|
|
|
10 |
"import ibis\n",
|
11 |
"from ibis import _\n",
|
12 |
"import streamlit as st\n",
|
|
|
|
|
13 |
"\n",
|
14 |
"conn = ibis.duckdb.connect(extensions=[\"spatial\"])\n",
|
15 |
"\n",
|
|
|
27 |
},
|
28 |
{
|
29 |
"cell_type": "code",
|
30 |
+
"execution_count": 27,
|
31 |
"id": "ba4d8915-cde3-4ef9-ad8c-7759ed2c8a13",
|
32 |
"metadata": {},
|
33 |
"outputs": [],
|
34 |
"source": [
|
35 |
"vote_county = (votes\n",
|
36 |
+
" .filter(_[\"Jurisdiction Type\"] == \"County\")\n",
|
37 |
+
" .rename(county = \"Jurisdiction Name\", state_id = \"State\")\n",
|
38 |
+
" .mutate(key = _.county + ibis.literal('-') + _.state_id)\n",
|
39 |
+
" .rename(amount = 'Conservation Funds at Stake', yes = '% Yes')\n",
|
40 |
+
" .mutate(amount_n=_.amount.replace('$', '').replace(',', '').cast('float'))\n",
|
41 |
+
" .mutate(log_amount=_.amount_n.log())\n",
|
42 |
+
" .mutate(year=_['Date'].year().cast('int32'))\n",
|
43 |
+
" .select('key', 'Status', 'yes', 'year', 'amount', 'log_amount', )\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
" )\n",
|
45 |
"df_county = (county\n",
|
46 |
" .join(states.select(\"state\", \"state_id\"), \"state\")\n",
|
|
|
55 |
},
|
56 |
{
|
57 |
"cell_type": "code",
|
58 |
+
"execution_count": 28,
|
59 |
"id": "0cce23c9-245c-4c28-9523-0231eb5acc17",
|
60 |
"metadata": {},
|
61 |
"outputs": [],
|
|
|
68 |
" .mutate(amount_n=_.amount.replace('$', '').replace(',', '').cast('float'))\n",
|
69 |
" .mutate(log_amount=_.amount_n.log())\n",
|
70 |
" .mutate(year=_['Date'].year().cast('int32'))\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
" .select('key', 'Status', 'yes', 'year', 'amount', 'log_amount', )\n",
|
72 |
" )\n",
|
73 |
"\n",
|
|
|
78 |
" .drop('key_right')\n",
|
79 |
" .mutate(jurisdiction = ibis.literal(\"Municipal\"))\n",
|
80 |
" .cast({\"geometry\": \"geometry\"})\n",
|
81 |
+
" \n",
|
82 |
" )\n"
|
83 |
]
|
84 |
},
|
85 |
{
|
86 |
"cell_type": "code",
|
87 |
+
"execution_count": 29,
|
88 |
"id": "a1e81807-8ce3-44bf-9a1c-8563fa33817c",
|
89 |
"metadata": {},
|
90 |
"outputs": [],
|
91 |
"source": [
|
92 |
+
"df = df_county.union(df_local)\n"
|
|
|
93 |
]
|
94 |
},
|
95 |
{
|
96 |
"cell_type": "code",
|
97 |
+
"execution_count": 12,
|
98 |
+
"id": "e0402bc4-9b1b-4d31-8789-1970c34bcfa8",
|
99 |
+
"metadata": {},
|
100 |
+
"outputs": [
|
101 |
+
{
|
102 |
+
"data": {
|
103 |
+
"application/vnd.jupyter.widget-view+json": {
|
104 |
+
"model_id": "47d5f61e2fdc46328e233418e9b48d95",
|
105 |
+
"version_major": 2,
|
106 |
+
"version_minor": 0
|
107 |
+
},
|
108 |
+
"text/plain": [
|
109 |
+
"FloatProgress(value=0.0, layout=Layout(width='auto'), style=ProgressStyle(bar_color='black'))"
|
110 |
+
]
|
111 |
+
},
|
112 |
+
"metadata": {},
|
113 |
+
"output_type": "display_data"
|
114 |
+
}
|
115 |
+
],
|
116 |
+
"source": [
|
117 |
+
"gdf = df.execute()"
|
118 |
+
]
|
119 |
+
},
|
120 |
+
{
|
121 |
+
"cell_type": "code",
|
122 |
+
"execution_count": 31,
|
123 |
+
"id": "2d0d5b70-2739-48e8-9ac6-789cb2f9f648",
|
124 |
+
"metadata": {},
|
125 |
+
"outputs": [
|
126 |
+
{
|
127 |
+
"data": {
|
128 |
+
"text/plain": [
|
129 |
+
"['State',\n",
|
130 |
+
" 'Jurisdiction Name',\n",
|
131 |
+
" 'Jurisdiction Type',\n",
|
132 |
+
" 'Date',\n",
|
133 |
+
" 'Description',\n",
|
134 |
+
" 'Finance Mechanism',\n",
|
135 |
+
" '\"Other\" Comment',\n",
|
136 |
+
" 'Purpose',\n",
|
137 |
+
" 'Total Funds at Stake',\n",
|
138 |
+
" 'Conservation Funds at Stake',\n",
|
139 |
+
" 'Total Funds Approved',\n",
|
140 |
+
" 'Conservation Funds Approved',\n",
|
141 |
+
" 'Pass?',\n",
|
142 |
+
" 'Status',\n",
|
143 |
+
" '% Yes',\n",
|
144 |
+
" '% No',\n",
|
145 |
+
" 'Notes',\n",
|
146 |
+
" 'Voted Acq. Measure',\n",
|
147 |
+
" 'column18']"
|
148 |
+
]
|
149 |
+
},
|
150 |
+
"execution_count": 31,
|
151 |
+
"metadata": {},
|
152 |
+
"output_type": "execute_result"
|
153 |
+
}
|
154 |
+
],
|
155 |
+
"source": [
|
156 |
+
"votes.drop(\"Total Funds )"
|
157 |
+
]
|
158 |
+
},
|
159 |
+
{
|
160 |
+
"cell_type": "code",
|
161 |
+
"execution_count": 20,
|
162 |
"id": "5d3bee26-7ca8-490c-be5b-fc69a6c3db2a",
|
163 |
"metadata": {},
|
164 |
"outputs": [
|
|
|
168 |
"text": [
|
169 |
"The token has not been saved to the git credentials helper. Pass `add_to_git_credential=True` in this function directly or `--add-to-git-credential` if using via `huggingface-cli` if you want to set the git credential as well.\n",
|
170 |
"Token is valid (permission: write).\n",
|
171 |
+
"Your token has been saved to /home/jovyan/.cache/huggingface/token\n",
|
172 |
"Login successful\n"
|
173 |
]
|
174 |
}
|
|
|
199 |
" command = [\n",
|
200 |
" \"tippecanoe\",\n",
|
201 |
" \"-o\", output_file,\n",
|
202 |
+
" \"-z\", str(max_zoom),\n",
|
203 |
+
" \"--drop-densest-as-needed\",\n",
|
204 |
" \"--extend-zooms-if-still-dropping\",\n",
|
205 |
" \"--force\",\n",
|
|
|
206 |
" input_file\n",
|
207 |
" ]\n",
|
208 |
"\n",
|
|
|
217 |
},
|
218 |
{
|
219 |
"cell_type": "code",
|
220 |
+
"execution_count": null,
|
221 |
+
"id": "ac91a627-70a8-4e60-b3ef-66e9c1e02762",
|
222 |
+
"metadata": {},
|
223 |
+
"outputs": [],
|
224 |
+
"source": [
|
225 |
+
"df.execute().to_file(\"vote.geojson\")\n",
|
226 |
+
"generate_pmtiles(\"vote.geojson\", \"vote.pmtiles\")\n",
|
227 |
+
"hf_upload(\"vote.pmtiles\", \"boettiger-lab/landvote\")\n",
|
228 |
+
"\n"
|
229 |
+
]
|
230 |
+
},
|
231 |
+
{
|
232 |
+
"cell_type": "code",
|
233 |
+
"execution_count": 25,
|
234 |
+
"id": "a3bde171-e7a8-4a5d-97ea-bfffdf26918b",
|
235 |
"metadata": {},
|
236 |
"outputs": [
|
237 |
{
|
238 |
"data": {
|
239 |
+
"text/html": [
|
240 |
+
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">DatabaseTable: ibis_read_geo_pamy33s53vaepploan6xzko2mu\n",
|
241 |
+
" key string\n",
|
242 |
+
" Status string\n",
|
243 |
+
" yes string\n",
|
244 |
+
" year int32\n",
|
245 |
+
" amount string\n",
|
246 |
+
" log_amount float64\n",
|
247 |
+
" jurisdiction string\n",
|
248 |
+
" geom geospatial:geometry\n",
|
249 |
+
"</pre>\n"
|
250 |
+
],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
251 |
"text/plain": [
|
252 |
+
"DatabaseTable: ibis_read_geo_pamy33s53vaepploan6xzko2mu\n",
|
253 |
+
" key string\n",
|
254 |
+
" Status string\n",
|
255 |
+
" yes string\n",
|
256 |
+
" year int32\n",
|
257 |
+
" amount string\n",
|
258 |
+
" log_amount float64\n",
|
259 |
+
" jurisdiction string\n",
|
260 |
+
" geom geospatial:geometry"
|
261 |
]
|
262 |
},
|
263 |
+
"execution_count": 25,
|
264 |
"metadata": {},
|
265 |
+
"output_type": "execute_result"
|
266 |
+
}
|
267 |
+
],
|
268 |
+
"source": [
|
269 |
+
"import leafmap.maplibregl as leafmap\n",
|
270 |
+
"import geopandas\n",
|
271 |
+
"url = \"https://huggingface.co/datasets/boettiger-lab/landvote/resolve/main/vote.geojson\"\n",
|
272 |
+
"\n",
|
273 |
+
"conn.read_geo(url).filter\n",
|
274 |
+
"#gpf = geopandas.read_file(url, engine=\"pyogrio\")\n"
|
275 |
+
]
|
276 |
+
},
|
277 |
+
{
|
278 |
+
"cell_type": "code",
|
279 |
+
"execution_count": 18,
|
280 |
+
"id": "58094159-4efc-4b56-a1d4-dac27be86924",
|
281 |
+
"metadata": {},
|
282 |
+
"outputs": [],
|
283 |
+
"source": [
|
284 |
+
"gpf.to_file(\"vote.geojson\")"
|
285 |
+
]
|
286 |
+
},
|
287 |
+
{
|
288 |
+
"cell_type": "code",
|
289 |
+
"execution_count": 21,
|
290 |
+
"id": "221db74d-961c-4cac-a443-02b3d562b531",
|
291 |
+
"metadata": {},
|
292 |
+
"outputs": [
|
293 |
{
|
294 |
"name": "stderr",
|
295 |
"output_type": "stream",
|
296 |
"text": [
|
297 |
"For layer 0, using name \"vote\"\n",
|
298 |
+
"vote.geojson:496: null geometry (additional not reported): in JSON object {\"type\":\"Feature\",\"properties\":{\"key\":null,\"Status\":\"Fail\",\"yes\":\"43.668463401297%\",\"year\":1990,\"amount\":null,\"log_amount\":null,\"jurisdiction\":\"County\"},\"geometry\":null}\n",
|
299 |
+
"2195 features, 10372266 bytes of geometry, 95306 bytes of string pool\n",
|
300 |
+
" 99.9% 12/1136/1649 \n",
|
301 |
+
" 100.0% 12/220/1795 \r"
|
|
|
|
|
302 |
]
|
303 |
},
|
304 |
{
|
|
|
307 |
"text": [
|
308 |
"Successfully generated PMTiles file: vote.pmtiles\n"
|
309 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
310 |
}
|
311 |
],
|
312 |
"source": [
|
313 |
+
"generate_pmtiles(\"vote.geojson\", \"vote.pmtiles\")\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
314 |
]
|
315 |
},
|
316 |
{
|
317 |
"cell_type": "code",
|
318 |
+
"execution_count": 22,
|
319 |
+
"id": "23deeb8c-3ef9-4279-bd5f-7b72494ee567",
|
320 |
+
"metadata": {},
|
|
|
|
|
321 |
"outputs": [
|
322 |
{
|
323 |
"data": {
|
|
|
|
|
|
|
|
|
|
|
324 |
"text/plain": [
|
325 |
+
"<Projected CRS: EPSG:3857>\n",
|
326 |
+
"Name: WGS 84 / Pseudo-Mercator\n",
|
327 |
+
"Axis Info [cartesian]:\n",
|
328 |
+
"- X[east]: Easting (metre)\n",
|
329 |
+
"- Y[north]: Northing (metre)\n",
|
330 |
+
"Area of Use:\n",
|
331 |
+
"- name: World between 85.06°S and 85.06°N.\n",
|
332 |
+
"- bounds: (-180.0, -85.06, 180.0, 85.06)\n",
|
333 |
+
"Coordinate Operation:\n",
|
334 |
+
"- name: Popular Visualisation Pseudo-Mercator\n",
|
335 |
+
"- method: Popular Visualisation Pseudo Mercator\n",
|
336 |
+
"Datum: World Geodetic System 1984 ensemble\n",
|
337 |
+
"- Ellipsoid: WGS 84\n",
|
338 |
+
"- Prime Meridian: Greenwich"
|
339 |
]
|
340 |
},
|
341 |
+
"execution_count": 22,
|
342 |
"metadata": {},
|
343 |
"output_type": "execute_result"
|
344 |
}
|
345 |
],
|
346 |
+
"source": [
|
347 |
+
"gdf = geopandas.read_file(\"vote.pmtiles\", engine=\"pyogrio\")\n",
|
348 |
+
"gdf.crs"
|
349 |
+
]
|
350 |
+
},
|
351 |
+
{
|
352 |
+
"cell_type": "code",
|
353 |
+
"execution_count": null,
|
354 |
+
"id": "fa397626-6e94-4ab9-a3bb-2bcbd14e8d40",
|
355 |
+
"metadata": {
|
356 |
+
"scrolled": true
|
357 |
+
},
|
358 |
+
"outputs": [],
|
359 |
"source": [
|
360 |
"import leafmap.maplibregl as leafmap\n",
|
361 |
"m = leafmap.Map(style=\"positron\")\n",
|
362 |
"\n",
|
363 |
"url = \"https://huggingface.co/datasets/boettiger-lab/landvote/resolve/main/vote.pmtiles\"\n",
|
364 |
"\n",
|
365 |
+
"#gdf = df.filter(_.year==1988).execute()\n",
|
366 |
+
"#gdf.to_file(\"vote.geojson\")\n",
|
367 |
+
"\n",
|
368 |
"outcome = [\n",
|
369 |
" 'match',\n",
|
370 |
" ['get', 'Status'], \n",
|
|
|
386 |
" \"filter\": [\n",
|
387 |
" \"==\",\n",
|
388 |
" [\"get\", \"year\"],\n",
|
389 |
+
" 1988,\n",
|
390 |
" ], # only show buildings with height info\n",
|
391 |
" \"paint\": paint\n",
|
392 |
" },\n",
|
|
|
401 |
" tooltip=True,\n",
|
402 |
" fit_bounds=False,\n",
|
403 |
")\n",
|
404 |
+
"#m.add_layer_control()\n",
|
405 |
"m\n",
|
406 |
+
"\n",
|
407 |
+
"\n",
|
408 |
+
"\n",
|
409 |
+
"#m.add_geojson(\"vote.geojson\", \"fill-extrusion\", paint = paint)\n",
|
410 |
+
"#m.add_gdf(gdf, \"fill-extrusion\", paint = paint)\n",
|
411 |
+
"#m"
|
412 |
]
|
413 |
},
|
414 |
{
|
415 |
"cell_type": "code",
|
416 |
"execution_count": null,
|
417 |
+
"id": "5e521f00-1b04-4016-9a6a-71a12e846dd3",
|
418 |
"metadata": {},
|
419 |
"outputs": [],
|
420 |
"source": []
|
|
|
436 |
"name": "python",
|
437 |
"nbconvert_exporter": "python",
|
438 |
"pygments_lexer": "ipython3",
|
439 |
+
"version": "3.11.10"
|
440 |
}
|
441 |
},
|
442 |
"nbformat": 4,
|