{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Empty & Null-Geometry GeoDataFrames\n", "\n", "Demonstrates that `KeplerGl` can accept GeoDataFrames that are empty or\n", "contain only null geometries. This is useful when an analysis pipeline\n", "produces no spatial results — the layer still appears on the map,\n", "signalling that the analysis ran but found nothing." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import geopandas" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Empty GeoDataFrame (zero rows)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
namegeometry
\n", "
" ], "text/plain": [ "Empty GeoDataFrame\n", "Columns: [name, geometry]\n", "Index: []" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "empty_gdf = geopandas.GeoDataFrame(\n", " {\"name\": pd.Series([], dtype=\"str\")},\n", " geometry=geopandas.GeoSeries([], crs=\"EPSG:4326\"),\n", ")\n", "display(empty_gdf)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## All-null geometries (rows exist, but every geometry is None)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
labelgeometry
0aNone
1bNone
2cNone
\n", "
" ], "text/plain": [ " label geometry\n", "0 a None\n", "1 b None\n", "2 c None" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "null_geom_gdf = geopandas.GeoDataFrame(\n", " {\"label\": [\"a\", \"b\", \"c\"]},\n", " geometry=[None, None, None],\n", ")\n", "display(null_geom_gdf)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Load into kepler.gl" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "5acbf2fc0ae74e8191e8f0f0e267b6d5", "version_major": 2, "version_minor": 1 }, "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import keplergl\n", "w = keplergl.KeplerGl(height=500)\n", "w" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "w.add_data(data=empty_gdf, name=\"empty\")" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "w.add_data(data=null_geom_gdf, name=\"null_geom\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.5" } }, "nbformat": 4, "nbformat_minor": 4 }