{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "d02532f8-4a22-4e60-a43d-0a68aed1e51c", "metadata": {}, "outputs": [], "source": [ "from cng.utils import *\n", "from cng.h3 import *\n", "from ibis import _\n", "import ibis.selectors as s\n", "import os\n", "from osgeo import gdal\n", "from minio import Minio\n", "import streamlit \n", "from datetime import timedelta\n", "import geopandas as gpd\n", "import re\n", "\n", "# Get signed URLs to access license-controlled layers\n", "key = st.secrets[\"MINIO_KEY\"]\n", "secret = st.secrets[\"MINIO_SECRET\"]\n", "client = Minio(\"minio.carlboettiger.info\", key, secret)\n", "\n", "con = ibis.duckdb.connect(extensions = [\"spatial\", \"h3\"])\n", "endpoint = os.getenv(\"AWS_S3_ENDPOINT\", \"minio.carlboettiger.info\")\n", "duckdb_install_h3()\n", "\n", "set_secrets(con)\n" ] }, { "cell_type": "code", "execution_count": null, "id": "ae5587d2-c95c-4317-94f9-ee1dde9f0458", "metadata": {}, "outputs": [], "source": [ "%%time\n", "#Wall time: 48.9 s\n", "parquet_file = f's3://public-ca30x30/ca30x30_cbn_v3.parquet'\n", "geobuf_file = 'ca30x30_cbn_v3.fgb'\n", "ca_geo = con.read_parquet(parquet_file).mutate(acres = _.acres.round(4))\n", "ca_geo.select(~s.startswith([\"mean_\", \"pct_\"])).execute().set_crs('epsg:4326').to_file(geobuf_file)\n", "s3_cp(geobuf_file,f's3://public-ca30x30/{geobuf_file}')" ] }, { "cell_type": "code", "execution_count": null, "id": "1b278fa2-df52-40af-bc85-e43b16cf5b14", "metadata": {}, "outputs": [], "source": [ "%%time \n", "#Wall time: 19min 11s\n", "pmtiles_file = 'ca30x30_cbn_v3.pmtiles'\n", "pmtiles = f's3://public-ca30x30/{pmtiles_file}'\n", "source_layer_name = re.sub(r'\\W+', '', os.path.splitext(os.path.basename(pmtiles_file))[0])\n", "\n", "options =[f'--layer={source_layer_name}',\n", " '-z12',\n", " '--drop-rate=0', \n", " '--extend-zooms-if-still-dropping', \n", " '--no-feature-limit',\n", " '--no-tile-size-limit',\n", " '--no-tiny-polygon-reduction',\n", " '--no-simplification-of-shared-nodes'\n", " ]\n", "new_pmtiles = to_pmtiles(geobuf_file, pmtiles_file, options = options )\n", "s3_cp(new_pmtiles,pmtiles)" ] }, { "cell_type": "code", "execution_count": null, "id": "ecd34e90-8abb-4d14-a774-af07ca62333b", "metadata": {}, "outputs": [], "source": [ "pmtiles = f'https://minio.carlboettiger.info/public-ca30x30/{pmtiles_file}'\n", "\n", "paint = {\n", " \"fill-color\": \"#d09514\",\n", " \"fill-opacity\": 0.6,\n", "}\n", "style = {'version': 8, 'sources': \n", " {'ca': {'type': 'vector', 'url': f'pmtiles://{pmtiles}'}},\n", " 'layers': [{'id': 'ca30x30', 'source': 'ca',\n", " 'source-layer': 'ca30x30_cbn_v3', \n", " 'type': 'fill', \n", " 'paint': {'fill-color': {'property': 'status',\n", " 'type': 'categorical', \n", " 'stops': [['30x30 Conservation Area', \"#56711f\"],\n", " ['Other Conservation Area', \"#b6ce7a\"],\n", " ['Public or Unknown Conservation Area', \"#e5efdb\"],\n", " ['Non-Conservation Area', \"#e1e1e1\"]],\n", " 'default': '#FFFFFF'}, 'fill-opacity': 0.8}}]}\n", "\n", "\n", "import leafmap.foliumap as leafmap\n", "\n", "m = leafmap.Map(center=[35, -100], zoom=5, style=\"positron\", fullscreen_control=True)\n", "\n", "m.add_pmtiles(pmtiles, style, zoom_to_layer = True)\n", "m\n", "\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.10" } }, "nbformat": 4, "nbformat_minor": 5 }