{ "cells": [ { "cell_type": "markdown", "id": "4b4adc2a-bf0c-4ace-87be-dbaf90be0125", "metadata": {}, "source": [ "# Pre-processing" ] }, { "cell_type": "code", "execution_count": 1, "id": "f7e6298c-d886-432a-a1b7-c3fee914c24f", "metadata": {}, "outputs": [], "source": [ "import ibis\n", "from ibis import _\n", "\n", "conn = ibis.duckdb.connect(\"tmp\", extensions=[\"spatial\"])\n", "ca_parquet = \"https://data.source.coop/cboettig/ca30x30/ca_areas.parquet\"\n", "# or use local copy:\n", "ca_parquet = \"/home/rstudio/source.coop/cboettig/ca30x30/ca_areas.parquet\"\n" ] }, { "cell_type": "code", "execution_count": 2, "id": "a0cb34b1-8d70-49bf-80c6-244ecc8ddf84", "metadata": {}, "outputs": [], "source": [ "buffer = -0.00001\n", "\n", "tbl = (\n", " conn.read_parquet(ca_parquet)\n", " .cast({\"SHAPE\": \"geometry\"})\n", " .rename(geom = \"SHAPE\")\n", " # .filter(_.UNIT_NAME == \"Angeles National Forest\")\n", " .filter(_.reGAP < 3) \n", ")\n", "tbl_2023 = tbl.filter(_.Release_Year == 2023).mutate(geom=_.geom.buffer(buffer))\n", "tbl_2024 = tbl.filter(_.Release_Year == 2024)\n", "intersects = tbl_2024.anti_join(tbl_2023, _.geom.intersects(tbl_2023.geom))\n", "\n", "new2024 = intersects.select(\"OBJECTID\").mutate(established = 2024)" ] }, { "cell_type": "code", "execution_count": 3, "id": "275c171a-f82f-4ee8-991c-1e34eb83a33d", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "dd86bb91838d45aa87197fc49a3b2362", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, layout=Layout(width='auto'), style=ProgressStyle(bar_color='black'))" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "ca = (conn\n", " .read_parquet(ca_parquet)\n", " .cast({\"SHAPE\": \"geometry\"})\n", " .mutate(area = _.SHAPE.area())\n", " .filter(_.Release_Year == 2024)\n", " .filter(_.reGAP < 3)\n", " .left_join(new2024, \"OBJECTID\")\n", " .mutate(established=_.established.fill_null(2023))\n", " .mutate(geom = _.SHAPE.convert(\"epsg:3310\",\"epsg:4326\"))\n", " .rename(name = \"UNIT_NAME\", access_type = \"ACCESS_TYP\", manager = \"MNG_AGNCY\",\n", " manager_type = \"MNG_AG_LEV\", id = \"OBJECTID\", type = \"TYPE\")\n", " .select(_.established, _.reGAP, _.name, _.access_type, _.manager, _.manager_type,\n", " _.Easement, _.Acres, _.id, _.type, _.geom)\n", " )\n", "ca.execute().to_parquet(\"ca2024.parquet\")" ] }, { "cell_type": "markdown", "id": "cebd0ff5-8353-4b84-b9ee-182b74613554", "metadata": {}, "source": [ "# Testing & visualization\n", "\n", "`ca2024.parquet()` now contains all we need. The code below illustrates some quick examples of the kinds of visualizations and summaries we might want to compute with this data. \n" ] }, { "cell_type": "code", "execution_count": 1, "id": "55afe07c-8681-4308-bbb9-e460f7380f86", "metadata": {}, "outputs": [], "source": [ "import leafmap.maplibregl as leafmap\n", "import ibis\n", "from ibis import _\n", "conn = ibis.duckdb.connect(extensions=[\"spatial\"])\n", "\n", "ca2024 = conn.read_parquet(\"ca2024.parquet\")" ] }, { "cell_type": "markdown", "id": "ebbb2650-4442-4e54-8467-5e681d6fab9e", "metadata": {}, "source": [ "Using difference (overlap) instead:" ] }, { "cell_type": "code", "execution_count": 6, "id": "6f3df8c1-a603-4dd5-be84-8deaae928d0a", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | manager | \n", "manager_type | \n", "area | \n", "
---|---|---|---|
0 | \n", "California Department of Fish and Wildlife | \n", "State | \n", "42086.259379 | \n", "
1 | \n", "California Department of Parks and Recreation | \n", "State | \n", "17931.321473 | \n", "
2 | \n", "California Tahoe Conservancy | \n", "State | \n", "4803.250929 | \n", "
3 | \n", "California Department of Water Resources | \n", "State | \n", "2248.610289 | \n", "
4 | \n", "University of California | \n", "State | \n", "1860.854444 | \n", "
5 | \n", "California Department of Forestry and Fire Pro... | \n", "State | \n", "1089.029581 | \n", "
6 | \n", "Coachella Valley Mountains Conservancy | \n", "State | \n", "119.907070 | \n", "
7 | \n", "California State Lands Commission | \n", "State | \n", "109.016475 | \n", "
8 | \n", "California State Coastal Conservancy | \n", "State | \n", "97.314705 | \n", "
9 | \n", "California State University Sonoma | \n", "State | \n", "38.760956 | \n", "
10 | \n", "Other State | \n", "State | \n", "32.927882 | \n", "
11 | \n", "San Joaquin River Conservancy | \n", "State | \n", "1.531470 | \n", "
12 | \n", "California Department of Transportation | \n", "State | \n", "1.261433 | \n", "
13 | \n", "Unknown | \n", "State | \n", "0.255531 | \n", "
14 | \n", "California State University | \n", "State | \n", "0.021589 | \n", "