Spaces:
Sleeping
Sleeping
two solns
Browse files- explore.ipynb +24 -253
explore.ipynb
CHANGED
@@ -60,7 +60,7 @@
|
|
60 |
},
|
61 |
{
|
62 |
"cell_type": "code",
|
63 |
-
"execution_count":
|
64 |
"id": "3ceed4c7-b7a2-436e-bca1-c57e7133cdf6",
|
65 |
"metadata": {},
|
66 |
"outputs": [],
|
@@ -86,91 +86,61 @@
|
|
86 |
" .rename(geom = \"SHAPE\")\n",
|
87 |
" # .mutate(geom = _.geom.convert(\"epsg:3310\",\"epsg:4326\"))\n",
|
88 |
" # .filter( _.geom.intersects(cookie_cutter))\n",
|
89 |
-
"
|
90 |
" .select(\"reGAP\", \"UNIT_NAME\", \"MNG_AGNCY\", \"Release_Year\", \"OBJECTID\", \"geom\")\n",
|
91 |
-
")"
|
|
|
|
|
|
|
92 |
]
|
93 |
},
|
94 |
{
|
95 |
"cell_type": "code",
|
96 |
-
"execution_count":
|
97 |
"id": "a0cb34b1-8d70-49bf-80c6-244ecc8ddf84",
|
98 |
"metadata": {},
|
99 |
"outputs": [],
|
100 |
"source": [
|
101 |
"import ibis\n",
|
102 |
"from ibis import _\n",
|
|
|
103 |
"\n",
|
104 |
"tbl = (\n",
|
105 |
" conn.read_parquet(\"https://data.source.coop/cboettig/ca30x30/ca_areas.parquet\")\n",
|
106 |
" .cast({\"SHAPE\": \"geometry\"})\n",
|
107 |
-
" .
|
|
|
|
|
|
|
108 |
")\n",
|
109 |
-
"\n",
|
110 |
-
"tbl_2023 = tbl.filter(_.Release_Year == 2023)\n",
|
111 |
"tbl_2024 = tbl.filter(_.Release_Year == 2024)\n",
|
112 |
-
"intersects = tbl_2024.anti_join(tbl_2023, _.
|
113 |
-
"intersects"
|
114 |
]
|
115 |
},
|
116 |
{
|
117 |
"cell_type": "code",
|
118 |
-
"execution_count":
|
119 |
"id": "3ed21429-a75e-4b52-b6eb-d41c8f051883",
|
120 |
"metadata": {},
|
121 |
-
"outputs": [],
|
122 |
-
"source": [
|
123 |
-
"# split 2023 & 2024\n",
|
124 |
-
"allgap_2023 = angeles_forest.filter(_.Release_Year == 2023)\n",
|
125 |
-
"allgap_2024 = angeles_forest.filter(_.Release_Year == 2024)"
|
126 |
-
]
|
127 |
-
},
|
128 |
-
{
|
129 |
-
"cell_type": "code",
|
130 |
-
"execution_count": 12,
|
131 |
-
"id": "7bfac88a-822a-4e4e-883e-b7e51544abd1",
|
132 |
-
"metadata": {},
|
133 |
-
"outputs": [],
|
134 |
-
"source": [
|
135 |
-
"# split but with reGAP < 3\n",
|
136 |
-
"la_2023 = allgap_2023.filter(_.reGAP < 3)\n",
|
137 |
-
"la_2024 = allgap_2024.filter(_.reGAP < 3)\n",
|
138 |
-
"\n",
|
139 |
-
"# THIS IS ALMOST WHAT WE WANT, BUT for some issues\n",
|
140 |
-
"# All reGAP 1,2 polygons in 2024 that don't intersect 2023\n",
|
141 |
-
"la_intersects = la_2024.anti_join(la_2023, _.geom.intersects(la_2023.geom))\n",
|
142 |
-
"\n",
|
143 |
-
"#la_contains = la_2024.anti_join(la_2023, _.geom.contains(la_2023.geom.centroid()))\n",
|
144 |
-
"#centroids = la_2023.filter(_.reGAP == 2).mutate( geom = la_2023.filter(_.reGAP == 2).geom.centroid() )\n",
|
145 |
-
"#centroids = old.mutate( geom = old.geom.centroid() )"
|
146 |
-
]
|
147 |
-
},
|
148 |
-
{
|
149 |
-
"cell_type": "code",
|
150 |
-
"execution_count": 23,
|
151 |
-
"id": "ddae1f9e-988a-4aed-bc71-f1c40d2bb0ea",
|
152 |
-
"metadata": {},
|
153 |
"outputs": [
|
154 |
{
|
155 |
"data": {
|
156 |
"application/vnd.jupyter.widget-view+json": {
|
157 |
-
"model_id": "
|
158 |
"version_major": 2,
|
159 |
-
"version_minor":
|
160 |
},
|
161 |
"text/plain": [
|
162 |
-
"
|
163 |
]
|
164 |
},
|
165 |
-
"execution_count": 23,
|
166 |
"metadata": {},
|
167 |
-
"output_type": "
|
168 |
}
|
169 |
],
|
170 |
"source": [
|
171 |
"import leafmap.maplibregl as leafmap\n",
|
172 |
-
"#la_gdf = la_2024.execute()\n",
|
173 |
-
"\n",
|
174 |
"\n",
|
175 |
"release_year = {'property': 'Release_Year', 'type': 'categorical','stops': [[2023, \"#FF000080\"], [2024, \"#0000FF80\"]]},\n",
|
176 |
"gap = {\n",
|
@@ -182,97 +152,20 @@
|
|
182 |
" [3, \"#BBBBBB\"],\n",
|
183 |
" [4, \"#F8F8F8\"]]\n",
|
184 |
" }\n",
|
185 |
-
"\n",
|
186 |
"paint = {\"fill-color\": gap, \"fill-opacity\": 0.5}\n",
|
187 |
"\n",
|
188 |
"m = leafmap.Map(style=\"positron\")\n",
|
189 |
-
"
|
190 |
-
"#m.add_gdf(allgap_2024.mutate(geom = _.geom.convert(\"epsg:3310\",\"epsg:4326\")).execute(),layer_type=\"fill\", name = \"allgap_2024\", paint=paint)\n",
|
191 |
-
"m.add_gdf(la_2023.mutate(geom = _.geom.convert(\"epsg:3310\",\"epsg:4326\")).execute(),layer_type=\"fill\", name = \"2023\", paint=paint)\n",
|
192 |
-
"#m.add_gdf(la_2024.mutate(geom = _.geom.convert(\"epsg:3310\",\"epsg:4326\")).execute(),layer_type=\"fill\", name = \"2024\", paint=paint)\n",
|
193 |
-
"#m.add_gdf(la_intersects.mutate(geom = _.geom.convert(\"epsg:3310\",\"epsg:4326\")).execute(),layer_type=\"fill\", name = \"anti_intersects\", paint=paint)\n",
|
194 |
"m.add_layer_control()\n",
|
195 |
"m"
|
196 |
]
|
197 |
},
|
198 |
{
|
199 |
-
"cell_type": "
|
200 |
-
"
|
201 |
-
"id": "6832038f-0342-495f-8cbf-9a8f3cc83aac",
|
202 |
-
"metadata": {},
|
203 |
-
"outputs": [],
|
204 |
-
"source": [
|
205 |
-
"## It intersects these, even though it looks like it shouldn't\n",
|
206 |
-
"\n",
|
207 |
-
"hits = (la_2024\n",
|
208 |
-
" .filter(_.OBJECTID == 111913) # appears to be the new stuff\n",
|
209 |
-
" .join(la_2023, _.geom.intersects(la_2023.geom), how=\"left\")\n",
|
210 |
-
" .select(_.OBJECTID_right, _.geom_right, _.reGAP)\n",
|
211 |
-
" .rename(geom = \"geom_right\")\n",
|
212 |
-
")\n",
|
213 |
-
"hits\n",
|
214 |
-
"\n"
|
215 |
-
]
|
216 |
-
},
|
217 |
-
{
|
218 |
-
"cell_type": "code",
|
219 |
-
"execution_count": null,
|
220 |
-
"id": "b41b0af6-635c-4ffb-9f19-342284f18e62",
|
221 |
"metadata": {},
|
222 |
-
"outputs": [],
|
223 |
-
"source": [
|
224 |
-
"import leafmap.maplibregl as leafmap\n",
|
225 |
-
"import ibis\n",
|
226 |
-
"from ibis import _\n",
|
227 |
-
"## Minimal look\n",
|
228 |
-
"areas = (\n",
|
229 |
-
" conn.read_parquet(\"https://data.source.coop/cboettig/ca30x30/ca_areas.parquet\")\n",
|
230 |
-
" .cast({\"SHAPE\": \"geometry\"})\n",
|
231 |
-
" .rename(geom = \"SHAPE\")\n",
|
232 |
-
" .select(\"Release_Year\", \"reGAP\", \"OBJECTID\", \"geom\")\n",
|
233 |
-
" .mutate(geom = _.geom.convert(\"epsg:3310\",\"epsg:4326\"))\n",
|
234 |
-
" \n",
|
235 |
-
")\n",
|
236 |
-
"new = areas.filter(_.OBJECTID == 111913)\n",
|
237 |
-
"old = areas.filter(_.OBJECTID == 21105)\n",
|
238 |
-
"# old.geom.difference(new.geom)\n",
|
239 |
-
"\n",
|
240 |
-
"\n",
|
241 |
-
"m = leafmap.Map(style=\"positron\")\n",
|
242 |
-
"m.add_gdf(old.execute(),layer_type=\"fill\", name = \"2023\", paint=paint)\n",
|
243 |
-
"m.add_gdf(new.execute(),layer_type=\"fill\", name = \"2024\", paint=paint)\n",
|
244 |
-
"m.add_layer_control()\n",
|
245 |
-
"m"
|
246 |
-
]
|
247 |
-
},
|
248 |
-
{
|
249 |
-
"cell_type": "code",
|
250 |
-
"execution_count": null,
|
251 |
-
"id": "ab985b4f-2257-46ce-95af-508c17323ca3",
|
252 |
-
"metadata": {},
|
253 |
-
"outputs": [],
|
254 |
-
"source": []
|
255 |
-
},
|
256 |
-
{
|
257 |
-
"cell_type": "code",
|
258 |
-
"execution_count": 13,
|
259 |
-
"id": "96cefbe6-12c9-4ca4-9352-c3573924c91c",
|
260 |
-
"metadata": {},
|
261 |
-
"outputs": [],
|
262 |
"source": [
|
263 |
-
"
|
264 |
-
"la_2024.execute().to_file(\"la_2024.geojson\")\n"
|
265 |
-
]
|
266 |
-
},
|
267 |
-
{
|
268 |
-
"cell_type": "code",
|
269 |
-
"execution_count": null,
|
270 |
-
"id": "4b9ee360-8583-4096-b1e1-43772f32a182",
|
271 |
-
"metadata": {},
|
272 |
-
"outputs": [],
|
273 |
-
"source": [
|
274 |
-
"la_2024.filter(_.OBJECTID == 111913).execute().to_file(\"new.geojson\")\n",
|
275 |
-
"la_2023.filter(_.OBJECTID == 21105).execute().to_file(\"old.geojson\")\n"
|
276 |
]
|
277 |
},
|
278 |
{
|
@@ -284,7 +177,6 @@
|
|
284 |
"source": [
|
285 |
"import ibis\n",
|
286 |
"from ibis import _\n",
|
287 |
-
"\n",
|
288 |
"tbl = (\n",
|
289 |
" conn.read_parquet(\"https://data.source.coop/cboettig/ca30x30/ca_areas.parquet\")\n",
|
290 |
" .cast({\"SHAPE\": \"geometry\"})\n",
|
@@ -293,79 +185,9 @@
|
|
293 |
"\n",
|
294 |
"tbl_2023 = tbl.filter(_.Release_Year == 2023)\n",
|
295 |
"tbl_2024 = tbl.filter(_.Release_Year == 2024)\n",
|
296 |
-
"# old method\n",
|
297 |
-
"#intersects = tbl_2024.anti_join(tbl_2023, _.SHAPE.intersects(tbl_2023.SHAPE))"
|
298 |
-
]
|
299 |
-
},
|
300 |
-
{
|
301 |
-
"cell_type": "code",
|
302 |
-
"execution_count": 57,
|
303 |
-
"id": "34e264c1-e6d4-4982-b8a7-5b856a3d22c3",
|
304 |
-
"metadata": {},
|
305 |
-
"outputs": [
|
306 |
-
{
|
307 |
-
"data": {
|
308 |
-
"application/vnd.jupyter.widget-view+json": {
|
309 |
-
"model_id": "11300de9b00446b88e10c2e4f41d81ca",
|
310 |
-
"version_major": 2,
|
311 |
-
"version_minor": 0
|
312 |
-
},
|
313 |
-
"text/plain": [
|
314 |
-
"FloatProgress(value=0.0, layout=Layout(width='auto'), style=ProgressStyle(bar_color='black'))"
|
315 |
-
]
|
316 |
-
},
|
317 |
-
"metadata": {},
|
318 |
-
"output_type": "display_data"
|
319 |
-
},
|
320 |
-
{
|
321 |
-
"data": {
|
322 |
-
"application/vnd.jupyter.widget-view+json": {
|
323 |
-
"model_id": "8ca97fd0f9d74a898d03fa41497c4836",
|
324 |
-
"version_major": 2,
|
325 |
-
"version_minor": 0
|
326 |
-
},
|
327 |
-
"text/plain": [
|
328 |
-
"FloatProgress(value=0.0, layout=Layout(width='auto'), style=ProgressStyle(bar_color='black'))"
|
329 |
-
]
|
330 |
-
},
|
331 |
-
"metadata": {},
|
332 |
-
"output_type": "display_data"
|
333 |
-
},
|
334 |
-
{
|
335 |
-
"ename": "InternalException",
|
336 |
-
"evalue": "INTERNAL Error: Calling StringValue::Get on a NULL value\nThis error signals an assertion failure within DuckDB. This usually occurs due to unexpected conditions or errors in the program's logic.\nFor more information, see https://duckdb.org/docs/dev/internal_errors",
|
337 |
-
"output_type": "error",
|
338 |
-
"traceback": [
|
339 |
-
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
340 |
-
"\u001b[0;31mInternalException\u001b[0m Traceback (most recent call last)",
|
341 |
-
"Cell \u001b[0;32mIn[57], line 9\u001b[0m\n\u001b[1;32m 7\u001b[0m con\u001b[38;5;241m.\u001b[39minstall_extension(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mspatial\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 8\u001b[0m con\u001b[38;5;241m.\u001b[39mload_extension(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mspatial\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m----> 9\u001b[0m \u001b[43mdb\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msql\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'''\u001b[39;49m\n\u001b[1;32m 10\u001b[0m \u001b[38;5;124;43mCOPY(\u001b[39;49m\n\u001b[1;32m 11\u001b[0m \u001b[38;5;124;43m SELECT ST_DIFFERENCE(_2024.geom, _2023.geom) AS geom,\u001b[39;49m\n\u001b[1;32m 12\u001b[0m \u001b[38;5;124;43m FROM ST_Read(\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mla_2024.geojson\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m) _2024\u001b[39;49m\n\u001b[1;32m 13\u001b[0m \u001b[38;5;124;43m LEFT JOIN (\u001b[39;49m\n\u001b[1;32m 14\u001b[0m \u001b[38;5;124;43m SELECT *\u001b[39;49m\n\u001b[1;32m 15\u001b[0m \u001b[38;5;124;43m FROM ST_Read(\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mla_2023.geojson\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m)\u001b[39;49m\n\u001b[1;32m 16\u001b[0m \u001b[38;5;124;43m ) _2023\u001b[39;49m\n\u001b[1;32m 17\u001b[0m \u001b[38;5;124;43m ON ST_INTERSECTS(_2024.geom,_2023.geom)\u001b[39;49m\n\u001b[1;32m 18\u001b[0m \u001b[38;5;124;43m) TO \u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43msimple.geojson\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m WITH (FORMAT GDAL, DRIVER \u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mGeoJSON\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m, LAYER_CREATION_OPTIONS \u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mWRITE_BBOX=YES\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m)\u001b[39;49m\n\u001b[1;32m 19\u001b[0m \u001b[38;5;124;43m'''\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 21\u001b[0m \u001b[38;5;66;03m# IF(_2023.objectid IS NULL, _2024.geom, ST_DIFFERENCE(_2024.geom, _2023.geom)) AS geom,\u001b[39;00m\n",
|
342 |
-
"\u001b[0;31mInternalException\u001b[0m: INTERNAL Error: Calling StringValue::Get on a NULL value\nThis error signals an assertion failure within DuckDB. This usually occurs due to unexpected conditions or errors in the program's logic.\nFor more information, see https://duckdb.org/docs/dev/internal_errors"
|
343 |
-
]
|
344 |
-
}
|
345 |
-
],
|
346 |
-
"source": [
|
347 |
-
"import duckdb\n",
|
348 |
"\n",
|
349 |
"tbl_2023.execute().to_file(\"la_2023.geojson\")\n",
|
350 |
-
"tbl_2024.execute().to_file(\"la_2024.geojson\")\n"
|
351 |
-
"\n",
|
352 |
-
"con = duckdb.connect()\n",
|
353 |
-
"con.install_extension(\"spatial\")\n",
|
354 |
-
"con.load_extension(\"spatial\")\n",
|
355 |
-
"db.sql('''\n",
|
356 |
-
"COPY(\n",
|
357 |
-
" SELECT ST_DIFFERENCE(_2024.geom, _2023.geom) AS geom,\n",
|
358 |
-
" FROM ST_Read('la_2024.geojson') _2024\n",
|
359 |
-
" LEFT JOIN (\n",
|
360 |
-
" SELECT *\n",
|
361 |
-
" FROM ST_Read('la_2023.geojson')\n",
|
362 |
-
" ) _2023\n",
|
363 |
-
" ON ST_INTERSECTS(_2024.geom,_2023.geom)\n",
|
364 |
-
") TO 'simple.geojson' WITH (FORMAT GDAL, DRIVER 'GeoJSON', LAYER_CREATION_OPTIONS 'WRITE_BBOX=YES')\n",
|
365 |
-
"''')\n",
|
366 |
-
"\n",
|
367 |
-
"# IF(_2023.objectid IS NULL, _2024.geom, ST_DIFFERENCE(_2024.geom, _2023.geom)) AS geom,\n",
|
368 |
-
"\n"
|
369 |
]
|
370 |
},
|
371 |
{
|
@@ -380,22 +202,10 @@
|
|
380 |
"db.install_extension(\"spatial\")\n",
|
381 |
"db.load_extension(\"spatial\")\n",
|
382 |
"\n",
|
383 |
-
"\n",
|
384 |
"db.sql('''\n",
|
385 |
"CREATE OR REPLACE TABLE t1 AS SELECT OBJECTID AS gid, geom, FROM st_read(\"la_2024.geojson\");\n",
|
386 |
"CREATE OR REPLACE TABLE t2 AS SELECT OBJECTID AS gid, geom, FROM st_read(\"la_2023.geojson\");\n",
|
387 |
"''')\n",
|
388 |
-
"\n"
|
389 |
-
]
|
390 |
-
},
|
391 |
-
{
|
392 |
-
"cell_type": "code",
|
393 |
-
"execution_count": 9,
|
394 |
-
"id": "d467548c-892f-4786-bfb2-0599f6d3d159",
|
395 |
-
"metadata": {},
|
396 |
-
"outputs": [],
|
397 |
-
"source": [
|
398 |
-
"\n",
|
399 |
"db.sql('''\n",
|
400 |
"COPY (\n",
|
401 |
"with temp as \n",
|
@@ -455,45 +265,6 @@
|
|
455 |
"m.add_layer_control()\n",
|
456 |
"m\n"
|
457 |
]
|
458 |
-
},
|
459 |
-
{
|
460 |
-
"cell_type": "code",
|
461 |
-
"execution_count": null,
|
462 |
-
"id": "d7c08912-3c8a-4810-b046-ea46008880ca",
|
463 |
-
"metadata": {},
|
464 |
-
"outputs": [],
|
465 |
-
"source": [
|
466 |
-
"import duckdb\n",
|
467 |
-
"\n",
|
468 |
-
"con = duckdb.connect()\n",
|
469 |
-
"con.install_extension(\"spatial\")\n",
|
470 |
-
"con.load_extension(\"spatial\")\n",
|
471 |
-
"con.sql('''\n",
|
472 |
-
"COPY(\n",
|
473 |
-
"WITH geom1 AS (\n",
|
474 |
-
" SELECT geom\n",
|
475 |
-
" FROM ST_Read('new.geojson')\n",
|
476 |
-
"),\n",
|
477 |
-
"geom2 AS (\n",
|
478 |
-
" SELECT geom\n",
|
479 |
-
" FROM ST_Read('old.geojson')\n",
|
480 |
-
")\n",
|
481 |
-
"SELECT ST_Difference(\n",
|
482 |
-
" (SELECT geom FROM geom1),\n",
|
483 |
-
" (SELECT geom FROM geom2)\n",
|
484 |
-
") AS geom\n",
|
485 |
-
") TO 'simple.geojson' WITH (FORMAT GDAL, DRIVER 'GeoJSON', LAYER_CREATION_OPTIONS 'WRITE_BBOX=YES')\n",
|
486 |
-
"''')\n",
|
487 |
-
"\n"
|
488 |
-
]
|
489 |
-
},
|
490 |
-
{
|
491 |
-
"cell_type": "code",
|
492 |
-
"execution_count": null,
|
493 |
-
"id": "b47fd840-a918-4690-adc0-ca074d09932c",
|
494 |
-
"metadata": {},
|
495 |
-
"outputs": [],
|
496 |
-
"source": []
|
497 |
}
|
498 |
],
|
499 |
"metadata": {
|
|
|
60 |
},
|
61 |
{
|
62 |
"cell_type": "code",
|
63 |
+
"execution_count": 17,
|
64 |
"id": "3ceed4c7-b7a2-436e-bca1-c57e7133cdf6",
|
65 |
"metadata": {},
|
66 |
"outputs": [],
|
|
|
86 |
" .rename(geom = \"SHAPE\")\n",
|
87 |
" # .mutate(geom = _.geom.convert(\"epsg:3310\",\"epsg:4326\"))\n",
|
88 |
" # .filter( _.geom.intersects(cookie_cutter))\n",
|
89 |
+
" # .filter(_.UNIT_NAME == \"Angeles National Forest\") \n",
|
90 |
" .select(\"reGAP\", \"UNIT_NAME\", \"MNG_AGNCY\", \"Release_Year\", \"OBJECTID\", \"geom\")\n",
|
91 |
+
")\n",
|
92 |
+
"# split 2023 & 2024\n",
|
93 |
+
"allgap_2023 = angeles_forest.filter(_.Release_Year == 2023)\n",
|
94 |
+
"allgap_2024 = angeles_forest.filter(_.Release_Year == 2024)"
|
95 |
]
|
96 |
},
|
97 |
{
|
98 |
"cell_type": "code",
|
99 |
+
"execution_count": 25,
|
100 |
"id": "a0cb34b1-8d70-49bf-80c6-244ecc8ddf84",
|
101 |
"metadata": {},
|
102 |
"outputs": [],
|
103 |
"source": [
|
104 |
"import ibis\n",
|
105 |
"from ibis import _\n",
|
106 |
+
"buffer = -0.0003 \n",
|
107 |
"\n",
|
108 |
"tbl = (\n",
|
109 |
" conn.read_parquet(\"https://data.source.coop/cboettig/ca30x30/ca_areas.parquet\")\n",
|
110 |
" .cast({\"SHAPE\": \"geometry\"})\n",
|
111 |
+
" .rename(geom = \"SHAPE\")\n",
|
112 |
+
" # .filter(_.UNIT_NAME == \"Angeles National Forest\")\n",
|
113 |
+
" .filter(_.reGAP < 3) \n",
|
114 |
+
" .mutate(geom = _.geom.convert(\"epsg:3310\",\"epsg:4326\"))\n",
|
115 |
")\n",
|
116 |
+
"tbl_2023 = tbl.filter(_.Release_Year == 2023).mutate(geom=_.geom.buffer(buffer))\n",
|
|
|
117 |
"tbl_2024 = tbl.filter(_.Release_Year == 2024)\n",
|
118 |
+
"intersects = tbl_2024.anti_join(tbl_2023, _.geom.intersects(tbl_2023.geom))"
|
|
|
119 |
]
|
120 |
},
|
121 |
{
|
122 |
"cell_type": "code",
|
123 |
+
"execution_count": null,
|
124 |
"id": "3ed21429-a75e-4b52-b6eb-d41c8f051883",
|
125 |
"metadata": {},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
"outputs": [
|
127 |
{
|
128 |
"data": {
|
129 |
"application/vnd.jupyter.widget-view+json": {
|
130 |
+
"model_id": "7c5bd159278847f481827b444ffc32b8",
|
131 |
"version_major": 2,
|
132 |
+
"version_minor": 0
|
133 |
},
|
134 |
"text/plain": [
|
135 |
+
"FloatProgress(value=0.0, layout=Layout(width='auto'), style=ProgressStyle(bar_color='black'))"
|
136 |
]
|
137 |
},
|
|
|
138 |
"metadata": {},
|
139 |
+
"output_type": "display_data"
|
140 |
}
|
141 |
],
|
142 |
"source": [
|
143 |
"import leafmap.maplibregl as leafmap\n",
|
|
|
|
|
144 |
"\n",
|
145 |
"release_year = {'property': 'Release_Year', 'type': 'categorical','stops': [[2023, \"#FF000080\"], [2024, \"#0000FF80\"]]},\n",
|
146 |
"gap = {\n",
|
|
|
152 |
" [3, \"#BBBBBB\"],\n",
|
153 |
" [4, \"#F8F8F8\"]]\n",
|
154 |
" }\n",
|
|
|
155 |
"paint = {\"fill-color\": gap, \"fill-opacity\": 0.5}\n",
|
156 |
"\n",
|
157 |
"m = leafmap.Map(style=\"positron\")\n",
|
158 |
+
"m.add_gdf(intersects.execute(),layer_type=\"fill\", name = \"intes\", paint=paint)\n",
|
|
|
|
|
|
|
|
|
159 |
"m.add_layer_control()\n",
|
160 |
"m"
|
161 |
]
|
162 |
},
|
163 |
{
|
164 |
+
"cell_type": "markdown",
|
165 |
+
"id": "ebbb2650-4442-4e54-8467-5e681d6fab9e",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
"metadata": {},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
"source": [
|
168 |
+
"Using difference (overlap) instead:"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
169 |
]
|
170 |
},
|
171 |
{
|
|
|
177 |
"source": [
|
178 |
"import ibis\n",
|
179 |
"from ibis import _\n",
|
|
|
180 |
"tbl = (\n",
|
181 |
" conn.read_parquet(\"https://data.source.coop/cboettig/ca30x30/ca_areas.parquet\")\n",
|
182 |
" .cast({\"SHAPE\": \"geometry\"})\n",
|
|
|
185 |
"\n",
|
186 |
"tbl_2023 = tbl.filter(_.Release_Year == 2023)\n",
|
187 |
"tbl_2024 = tbl.filter(_.Release_Year == 2024)\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
188 |
"\n",
|
189 |
"tbl_2023.execute().to_file(\"la_2023.geojson\")\n",
|
190 |
+
"tbl_2024.execute().to_file(\"la_2024.geojson\")\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
191 |
]
|
192 |
},
|
193 |
{
|
|
|
202 |
"db.install_extension(\"spatial\")\n",
|
203 |
"db.load_extension(\"spatial\")\n",
|
204 |
"\n",
|
|
|
205 |
"db.sql('''\n",
|
206 |
"CREATE OR REPLACE TABLE t1 AS SELECT OBJECTID AS gid, geom, FROM st_read(\"la_2024.geojson\");\n",
|
207 |
"CREATE OR REPLACE TABLE t2 AS SELECT OBJECTID AS gid, geom, FROM st_read(\"la_2023.geojson\");\n",
|
208 |
"''')\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
209 |
"db.sql('''\n",
|
210 |
"COPY (\n",
|
211 |
"with temp as \n",
|
|
|
265 |
"m.add_layer_control()\n",
|
266 |
"m\n"
|
267 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
268 |
}
|
269 |
],
|
270 |
"metadata": {
|