{ "cells": [ { "cell_type": "markdown", "id": "1daaee6bc674d78c", "metadata": {}, "source": "# Using GeoDatabases and GeoDataframes" }, { "cell_type": "code", "id": "2350c95724536a35", "metadata": { "ExecuteTime": { "end_time": "2026-05-01T01:20:27.283202798Z", "start_time": "2026-05-01T01:20:16.741440369Z" } }, "source": [ "import footbridge as ft\n", "\n", "# large dataset of US National Highway System roads\n", "# https://hepgis-usdot.hub.arcgis.com/datasets/dce9f09392eb474c8ad8e6a78416279b_0\n", "fc = ft.FeatureClass(\"NHS.gdb/National_Highway_System__NHS_\")\n", "f\"{len(fc)} rows\"" ], "outputs": [ { "data": { "text/plain": [ "'492005 rows'" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "execution_count": 18 }, { "cell_type": "code", "id": "3e78ae4650b5b74b", "metadata": { "ExecuteTime": { "end_time": "2026-05-01T01:20:27.330776175Z", "start_time": "2026-05-01T01:20:27.284003682Z" } }, "source": [ "# Set the CRS when creating the Feature Dataset\n", "fds = ft.FeatureDataset(crs=\"EPSG:4326\")\n", "fds.crs.name" ], "outputs": [ { "data": { "text/plain": [ "'WGS 84'" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "execution_count": 19 }, { "cell_type": "code", "id": "323267b1224493db", "metadata": { "ExecuteTime": { "end_time": "2026-05-01T01:20:27.377843751Z", "start_time": "2026-05-01T01:20:27.331563342Z" } }, "source": [ "# The FeatureDataset will enforce the CRS\n", "fds[\"NHS\"] = fc" ], "outputs": [], "execution_count": 20 }, { "cell_type": "code", "id": "4bdb541b58948782", "metadata": { "ExecuteTime": { "end_time": "2026-05-01T01:20:27.425636375Z", "start_time": "2026-05-01T01:20:27.378797786Z" } }, "source": [ "# Or create an empty FeatureDataset, which has no CRS by default\n", "fds = ft.FeatureDataset()\n", "type(fds.crs)" ], "outputs": [ { "data": { "text/plain": [ "NoneType" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "execution_count": 21 }, { "cell_type": "code", "id": "97c2dcb61641b30b", "metadata": { "ExecuteTime": { "end_time": "2026-05-01T01:20:27.473605701Z", "start_time": "2026-05-01T01:20:27.426333980Z" } }, "source": [ "# The FeatureDataset sets its CRS from the first FeatureClass added\n", "fds[\"NHS\"] = fc\n", "fds.crs.name" ], "outputs": [ { "data": { "text/plain": [ "'WGS 84'" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "execution_count": 22 }, { "cell_type": "code", "id": "d1856365df4a1fbb", "metadata": { "ExecuteTime": { "end_time": "2026-05-01T01:20:27.521325186Z", "start_time": "2026-05-01T01:20:27.474302422Z" } }, "source": [ "# FeatureDatasets can be added to more than one GeoDatabase\n", "gdb1 = ft.GeoDatabase()\n", "gdb1[\"NHS_dataset1\"] = fds\n", "\n", "gdb2 = ft.GeoDatabase()\n", "gdb2[\"NHS_dataset2\"] = fds\n", "print(gdb1.fds_dict)\n", "print(gdb2.fds_dict)\n", "print(\"Note that the same object has different names ^\")" ], "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'NHS_dataset1': }\n", "{'NHS_dataset2': }\n", "Note that the same object has different names ^\n" ] } ], "execution_count": 23 }, { "cell_type": "code", "id": "73c4bd57f82f037a", "metadata": { "ExecuteTime": { "end_time": "2026-05-01T01:20:27.570607493Z", "start_time": "2026-05-01T01:20:27.522614620Z" } }, "source": [ "# Adding to the FeatureDataset updates it in both GeoDatabases\n", "gdb1[\"NHS_dataset1\"][\"NHS_2\"] = fc\n", "print(gdb1.fc_dict)\n", "print(gdb2.fc_dict)" ], "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'NHS': , 'NHS_2': }\n", "{'NHS': , 'NHS_2': }\n" ] } ], "execution_count": 24 }, { "cell_type": "code", "id": "2c914b1ac12fba5c", "metadata": { "ExecuteTime": { "end_time": "2026-05-01T01:20:27.618347250Z", "start_time": "2026-05-01T01:20:27.571337139Z" } }, "source": [ "# Adding a FeatureClass directly to a FeatureDataset places it in the FeatureDataset named None\n", "gdb1[\"NHS_fc2\"] = fc\n", "print(gdb1.fds_dict[None].fc_names)" ], "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['NHS_fc2']\n" ] } ], "execution_count": 25 }, { "cell_type": "code", "id": "ea69392e8194f7c5", "metadata": { "ExecuteTime": { "end_time": "2026-05-01T01:20:27.665497097Z", "start_time": "2026-05-01T01:20:27.618992044Z" } }, "source": [ "# FeatureClasses can be accessed as dicts, a list of names, or as a list of objects:\n", "gdb1.fc_dict" ], "outputs": [ { "data": { "text/plain": [ "{'NHS': ,\n", " 'NHS_2': ,\n", " 'NHS_fc2': }" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "execution_count": 26 }, { "cell_type": "code", "id": "be2007faf0557d36", "metadata": { "ExecuteTime": { "end_time": "2026-05-01T01:20:27.713599276Z", "start_time": "2026-05-01T01:20:27.666171935Z" } }, "source": "gdb1.fc_names", "outputs": [ { "data": { "text/plain": [ "['NHS', 'NHS_2', 'NHS_fc2']" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "execution_count": 27 }, { "cell_type": "code", "id": "fae471e94ea523d2", "metadata": { "ExecuteTime": { "end_time": "2026-05-01T01:20:27.760507932Z", "start_time": "2026-05-01T01:20:27.714219941Z" } }, "source": "gdb1.fcs", "outputs": [ { "data": { "text/plain": [ "[,\n", " ,\n", " ]" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "execution_count": 28 }, { "cell_type": "code", "id": "9c1bc24520947414", "metadata": { "ExecuteTime": { "end_time": "2026-05-01T01:20:27.807304971Z", "start_time": "2026-05-01T01:20:27.761247366Z" } }, "source": [ "# Which allows for easy access to FeatureClass functionality\n", "for fc in gdb1.fcs:\n", " print(fc.crs.name)" ], "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "WGS 84\n", "WGS 84\n", "WGS 84\n" ] } ], "execution_count": 29 }, { "cell_type": "code", "id": "2dde9b5ea784a8a2", "metadata": { "ExecuteTime": { "end_time": "2026-05-01T01:20:27.852721791Z", "start_time": "2026-05-01T01:20:27.807949791Z" } }, "source": [], "outputs": [], "execution_count": 29 } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.6" } }, "nbformat": 4, "nbformat_minor": 5 }