{ "cells": [ { "cell_type": "markdown", "id": "386f1d9d637b8a26", "metadata": {}, "source": [ "# Comparison with ArcPy\n", "\n", "This notebook compares the usage of `footbridge` with `arcpy`." ] }, { "cell_type": "code", "execution_count": 1, "id": "d092f5c1f798da3f", "metadata": { "ExecuteTime": { "end_time": "2025-08-31T22:43:49.931397Z", "start_time": "2025-08-31T22:43:42.978509Z" } }, "outputs": [], "source": [ "import os\n", "import arcpy\n", "import footbridge as ft\n", "from timer import Timer\n", "\n", "timer = Timer()\n", "\n", "# large dataset of US National Highway System roads, one feature class\n", "# https://hepgis-usdot.hub.arcgis.com/datasets/dce9f09392eb474c8ad8e6a78416279b_0\n", "gdb_path = os.path.abspath(\"NHS.gdb\")\n", "\n", "arcpy.env.overwriteOutput = True" ] }, { "cell_type": "markdown", "id": "c7b228efc15d702b", "metadata": { "ExecuteTime": { "end_time": "2025-08-24T18:51:12.449277Z", "start_time": "2025-08-24T18:51:12.440440Z" } }, "source": [ "## Load feature class into memory\n", "### ArcPy" ] }, { "cell_type": "code", "execution_count": 2, "id": "c8fb456d745ce40d", "metadata": { "ExecuteTime": { "end_time": "2025-08-31T22:44:08.635736Z", "start_time": "2025-08-31T22:43:49.940533Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "18.6794 seconds\n" ] } ], "source": [ "timer.start()\n", "# ------------\n", "arcpy.env.workspace = gdb_path\n", "arcpy_fcs = arcpy.ListFeatureClasses()\n", "fc_name = arcpy_fcs[0]\n", "fc_path = os.path.join(gdb_path, fc_name)\n", "arcpy_fc = os.path.join(\"memory\", fc_name)\n", "arcpy.conversion.ExportFeatures(fc_path, arcpy_fc)\n", "# -----------\n", "timer.stop()" ] }, { "cell_type": "markdown", "id": "b4ee69dab232a892", "metadata": {}, "source": "### footbridge" }, { "cell_type": "code", "execution_count": 3, "id": "76fc771d99b08567", "metadata": { "ExecuteTime": { "end_time": "2025-08-31T22:44:22.914934Z", "start_time": "2025-08-31T22:44:09.018110Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "13.8833 seconds\n" ] } ], "source": [ "timer.start()\n", "# ------------\n", "ft_fc = ft.GeoDatabase(gdb_path)[0]\n", "# -----------\n", "timer.stop()" ] }, { "cell_type": "markdown", "id": "160b50b4e7557157", "metadata": {}, "source": [ "| | Fewer lines | More pythonic | Faster runtime | Overall |\n", "|----------:|:-----------:|:-------------:|:--------------:|:-------:|\n", "| ArcPy | ❌ | ❌ | ✅ | ❌ |\n", "| footbridge | ✅ | ✅ | ❌ | ✅ |" ] }, { "cell_type": "markdown", "id": "828baa83afe56539", "metadata": {}, "source": [ "## Count rows\n", "### ArcPy" ] }, { "cell_type": "code", "execution_count": 4, "id": "ada0cd9842f8d08b", "metadata": { "ExecuteTime": { "end_time": "2025-08-31T22:44:23.072006Z", "start_time": "2025-08-31T22:44:22.956403Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.1106 seconds\n" ] }, { "data": { "text/plain": [ "'491781 rows'" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "timer.start()\n", "# ------------\n", "count_result = arcpy.management.GetCount(arcpy_fc)\n", "row_count = count_result[0]\n", "# -----------\n", "timer.stop()\n", "f\"{row_count} rows\"" ] }, { "cell_type": "markdown", "id": "5c22b3a9830c0fcf", "metadata": {}, "source": "### footbridge" }, { "cell_type": "code", "execution_count": 5, "id": "51935ca095c8472c", "metadata": { "ExecuteTime": { "end_time": "2025-08-31T22:44:23.098605Z", "start_time": "2025-08-31T22:44:23.093504Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.001 seconds\n" ] }, { "data": { "text/plain": [ "'491781 rows'" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "timer.start()\n", "# ------------\n", "row_count = len(ft_fc)\n", "# -----------\n", "timer.stop()\n", "f\"{row_count} rows\"" ] }, { "cell_type": "markdown", "id": "17ccb2263c92aaaf", "metadata": {}, "source": [ "| | Fewer lines | More pythonic | Faster runtime | Overall |\n", "|----------:|:-----------:|:-------------:|:--------------:|:-------:|\n", "| ArcPy | ❌ | ❌ | ❌ | ❌ |\n", "| footbridge | ✅ | ✅ | ✅ | ✅ |" ] }, { "cell_type": "markdown", "id": "182b8db87ecd2cdd", "metadata": {}, "source": [ "## Filter rows\n", "### ArcPy" ] }, { "cell_type": "code", "execution_count": 6, "id": "53f409d3c2f70999", "metadata": { "ExecuteTime": { "end_time": "2025-08-31T22:44:23.310319Z", "start_time": "2025-08-31T22:44:23.120699Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.1153 seconds\n" ] }, { "data": { "text/plain": [ "'24 rows'" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "timer.start()\n", "# ------------\n", "arcpy_fc_filtered = os.path.join(\"memory\", fc_name + \"_filtered\")\n", "arcpy.conversion.ExportFeatures(\n", " arcpy_fc, arcpy_fc_filtered, where_clause=\"ROUTEID = '50'\"\n", ")\n", "# -----------\n", "timer.stop()\n", "f\"{arcpy.management.GetCount(arcpy_fc_filtered)[0]} rows\"" ] }, { "cell_type": "markdown", "id": "f4288c3574aaa46e", "metadata": {}, "source": "### footbridge" }, { "cell_type": "code", "execution_count": 7, "id": "1b66cac88e4eeacd", "metadata": { "ExecuteTime": { "end_time": "2025-08-31T22:44:23.382214Z", "start_time": "2025-08-31T22:44:23.339306Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.0385 seconds\n" ] }, { "data": { "text/plain": [ "'24 rows'" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "timer.start()\n", "# ------------\n", "ft_fc_filtered = ft_fc.select_rows(\"ROUTEID == '50'\")\n", "# -----------\n", "timer.stop()\n", "f\"{len(ft_fc_filtered)} rows\"" ] }, { "cell_type": "markdown", "id": "ce1cbe647095ecbb", "metadata": {}, "source": [ "| | Fewer lines | More pythonic | Faster runtime | Overall |\n", "|----------:|:-----------:|:-------------:|:--------------:|:-------:|\n", "| ArcPy | ❌ | ❌ | ❌ | ❌ |\n", "| footbridge | ✅ | ✅ | ✅ | ✅ |" ] }, { "cell_type": "markdown", "id": "d4c42016d36e9ff", "metadata": {}, "source": [ "## Get the last row\n", "### ArcPy" ] }, { "cell_type": "code", "execution_count": 8, "id": "1de222bba389f6a", "metadata": { "ExecuteTime": { "end_time": "2025-08-31T22:44:25.745604Z", "start_time": "2025-08-31T22:44:23.402812Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2.3388 seconds\n" ] }, { "data": { "text/plain": [ "(491781,\n", " (-16685208.940766193, 8677951.279447716),\n", " '2025.03.27',\n", " 2022.0,\n", " 2.0,\n", " 20.0,\n", " '2281321F013',\n", " 0.0,\n", " 0.354,\n", " ' ',\n", " ' ',\n", " ' ',\n", " ' ',\n", " 4.0,\n", " 1.0,\n", " ' ',\n", " ' ',\n", " ' ',\n", " 0.0,\n", " ' ',\n", " 3.0,\n", " 4.0,\n", " 1.0,\n", " 0.0,\n", " 0.0,\n", " 2305.0,\n", " 1744.0,\n", " 0.0,\n", " 0.0,\n", " 0.0,\n", " None,\n", " 0.354,\n", " datetime.datetime(2025, 3, 5, 0, 0),\n", " 'Add: STRAHNET Connector',\n", " 'AK_HPMS_FULL_2022')" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "timer.start()\n", "# ------------\n", "with arcpy.da.SearchCursor(arcpy_fc, field_names=[\"*\"]) as s_cursor:\n", " for row in s_cursor:\n", " this_row = row\n", "# -----------\n", "timer.stop()\n", "this_row" ] }, { "cell_type": "markdown", "id": "8a09198761fe5427", "metadata": {}, "source": "### footbridge" }, { "cell_type": "code", "execution_count": 9, "id": "60126af89fe0a051", "metadata": { "ExecuteTime": { "end_time": "2025-08-31T22:44:25.817824Z", "start_time": "2025-08-31T22:44:25.790682Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.0039 seconds\n" ] }, { "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", " \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", " \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", "
VERSIONYEARSTFIPSCTFIPSROUTEIDBEGINPOINTENDPOINTSIGN1SIGNT1SIGNN1...AADT_COMAADT_SINGLFUT_AADTFUT_YEARMILESUPDATE_DATNHS_ACTIONFILE_NAMESHAPE_Lengthgeometry
ObjectID
4917802025.03.272022.02.020.02281321F0130.00.354...0.00.00.0NaT0.3542025-03-05 00:00:00+00:00Add: STRAHNET ConnectorAK_HPMS_FULL_20221176.089478MULTILINESTRING ((-16685133.238 8677491.246, -16685113.534 8677517.377, -16685110.974 8677534.721, -16685108.636 8677551.14, -16685105.964 8677567.558, -16685103.181 8677583.977, -16685100.398 8677600.396, -16685097.504 8677616.584, -16685094.721 8677633.003, -16685091.938 8677649.422, -16685089.155 8677665.841, -16685086.372 8677682.029, -16685083.478 8677698.679, -16685080.695 8677714.867, -16685077.801 8677731.286, -16685075.018 8677747.937, -16685072.123 8677764.125, -16685069.34 8677780.544, -16685066.446 8677796.964, -16685063.552 8677813.383, -16685060.658 8677829.803, -16685057.763 8677846.222, -16685054.98 8677862.642, -16685052.197 8677879.292, -16685049.748 8677895.712, -16685047.856 8677912.363, -16685046.743 8677929.245, -16685046.743 8677945.896, -16685047.744 8677962.778, -16685050.194 8677979.429, -16685053.756 8677995.849, -16685058.654 8678012.038, -16685064.665 8678027.764, -16685071.901 8678043.027, -16685080.361 8678057.597, -16685089.935 8678071.473, -16685100.51 8678084.656, -16685111.865 8678097.144, -16685123.998 8678108.707, -16685137.023 8678119.346, -16685151.049 8678128.828, -16685165.632 8678137.385, -16685180.66 8678144.554, -16685196.245 8678150.799, -16685212.386 8678155.655, -16685228.75 8678159.355, -16685245.337 8678161.899, -16685262.035 8678163.056, -16685278.955 8678163.287, -16685295.542 8678162.593, -16685312.24 8678160.974, -16685328.938 8678158.893, -16685345.302 8678156.118, -16685361.666 8678152.88, -16685377.918 8678149.179, -16685394.171 8678145.248, -16685410.312 8678141.085, -16685457.289 8678123.74, -16685473.43 8678118.883, -16685489.349 8678114.258, -16685505.379 8678109.401, -16685521.52 8678104.776, -16685537.662 8678100.613, -16685554.026 8678097.144, -16685570.501 8678094.369, -16685587.421 8678093.212, -16685604.231 8678093.675, -16685621.93 8678081.88))
\n", "

1 rows × 35 columns

\n", "
" ], "text/plain": [ " VERSION YEAR STFIPS CTFIPS ROUTEID BEGINPOINT \\\n", "ObjectID \n", "491780 2025.03.27 2022.0 2.0 20.0 2281321F013 0.0 \n", "\n", " ENDPOINT SIGN1 SIGNT1 SIGNN1 ... AADT_COM AADT_SINGL FUT_AADT \\\n", "ObjectID ... \n", "491780 0.354 ... 0.0 0.0 0.0 \n", "\n", " FUT_YEAR MILES UPDATE_DAT NHS_ACTION \\\n", "ObjectID \n", "491780 NaT 0.354 2025-03-05 00:00:00+00:00 Add: STRAHNET Connector \n", "\n", " FILE_NAME SHAPE_Length \\\n", "ObjectID \n", "491780 AK_HPMS_FULL_2022 1176.089478 \n", "\n", " geometry \n", "ObjectID \n", "491780 MULTILINESTRING ((-16685133.238 8677491.246, -16685113.534 8677517.377, -16685110.974 8677534.721, -16685108.636 8677551.14, -16685105.964 8677567.558, -16685103.181 8677583.977, -16685100.398 8677600.396, -16685097.504 8677616.584, -16685094.721 8677633.003, -16685091.938 8677649.422, -16685089.155 8677665.841, -16685086.372 8677682.029, -16685083.478 8677698.679, -16685080.695 8677714.867, -16685077.801 8677731.286, -16685075.018 8677747.937, -16685072.123 8677764.125, -16685069.34 8677780.544, -16685066.446 8677796.964, -16685063.552 8677813.383, -16685060.658 8677829.803, -16685057.763 8677846.222, -16685054.98 8677862.642, -16685052.197 8677879.292, -16685049.748 8677895.712, -16685047.856 8677912.363, -16685046.743 8677929.245, -16685046.743 8677945.896, -16685047.744 8677962.778, -16685050.194 8677979.429, -16685053.756 8677995.849, -16685058.654 8678012.038, -16685064.665 8678027.764, -16685071.901 8678043.027, -16685080.361 8678057.597, -16685089.935 8678071.473, -16685100.51 8678084.656, -16685111.865 8678097.144, -16685123.998 8678108.707, -16685137.023 8678119.346, -16685151.049 8678128.828, -16685165.632 8678137.385, -16685180.66 8678144.554, -16685196.245 8678150.799, -16685212.386 8678155.655, -16685228.75 8678159.355, -16685245.337 8678161.899, -16685262.035 8678163.056, -16685278.955 8678163.287, -16685295.542 8678162.593, -16685312.24 8678160.974, -16685328.938 8678158.893, -16685345.302 8678156.118, -16685361.666 8678152.88, -16685377.918 8678149.179, -16685394.171 8678145.248, -16685410.312 8678141.085, -16685457.289 8678123.74, -16685473.43 8678118.883, -16685489.349 8678114.258, -16685505.379 8678109.401, -16685521.52 8678104.776, -16685537.662 8678100.613, -16685554.026 8678097.144, -16685570.501 8678094.369, -16685587.421 8678093.212, -16685604.231 8678093.675, -16685621.93 8678081.88)) \n", "\n", "[1 rows x 35 columns]" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "timer.start()\n", "# ------------\n", "this_row = ft_fc[-1]\n", "# -----------\n", "timer.stop()\n", "this_row" ] }, { "cell_type": "markdown", "id": "affe430e034a700c", "metadata": {}, "source": [ "| | Fewer lines | More pythonic | Faster runtime | Overall |\n", "|----------:|:-----------:|:-------------:|:--------------:|:-------:|\n", "| ArcPy | ❌ | ❌ | ❌ | ❌ |\n", "| footbridge | ✅ | ✅ | ✅ | ✅ |" ] }, { "cell_type": "markdown", "id": "b6345626ca6efef2", "metadata": {}, "source": "## Get a row at an index" }, { "cell_type": "code", "execution_count": 10, "id": "68701b8c686805cb", "metadata": { "ExecuteTime": { "end_time": "2025-08-31T22:44:25.880105Z", "start_time": "2025-08-31T22:44:25.875696Z" } }, "outputs": [], "source": [ "row_index = 400000" ] }, { "cell_type": "markdown", "id": "c8c9375e4eabf3aa", "metadata": {}, "source": "### ArcPy" }, { "cell_type": "code", "execution_count": 11, "id": "d948189d51a3ca1d", "metadata": { "ExecuteTime": { "end_time": "2025-08-31T22:44:28.029938Z", "start_time": "2025-08-31T22:44:25.983475Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2.0408 seconds\n" ] }, { "data": { "text/plain": [ "(400001,\n", " (-8541104.104770636, 4903934.337197111),\n", " '2025.03.27',\n", " 2020.0,\n", " 42.0,\n", " 43.0,\n", " '1 22 0322 - 4031',\n", " 4.862,\n", " 4.973,\n", " 'U322',\n", " 'U',\n", " '322',\n", " '28th Division Hwy',\n", " 7.0,\n", " 1.0,\n", " ' ',\n", " ' ',\n", " ' ',\n", " 0.0,\n", " 'P',\n", " 2.0,\n", " 2.0,\n", " 4.0,\n", " 0.0,\n", " 1.0,\n", " 37081.0,\n", " 37283.0,\n", " 553.0,\n", " 593.0,\n", " 0.0,\n", " None,\n", " 0.109283,\n", " None,\n", " ' ',\n", " 'PA_NHS_2021')" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "timer.start()\n", "# ------------\n", "with arcpy.da.SearchCursor(arcpy_fc, field_names=[\"*\"]) as s_cursor:\n", " for idx, row in enumerate(s_cursor):\n", " if idx == row_index:\n", " this_row = row\n", " break\n", "# -----------\n", "timer.stop()\n", "this_row" ] }, { "cell_type": "markdown", "id": "3f6fd2cde3b63233", "metadata": {}, "source": "### footbridge" }, { "cell_type": "code", "execution_count": 12, "id": "ca5f33be31ea161f", "metadata": { "ExecuteTime": { "end_time": "2025-08-31T22:44:28.116686Z", "start_time": "2025-08-31T22:44:28.101314Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.001 seconds\n" ] }, { "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", " \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", " \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", "
VERSIONYEARSTFIPSCTFIPSROUTEIDBEGINPOINTENDPOINTSIGN1SIGNT1SIGNN1...AADT_COMAADT_SINGLFUT_AADTFUT_YEARMILESUPDATE_DATNHS_ACTIONFILE_NAMESHAPE_Lengthgeometry
ObjectID
4000002025.03.272020.042.043.01 22 0322 - 40314.8624.973U322U322...553.0593.00.0NaT0.109283NaTPA_NHS_2021230.148704MULTILINESTRING ((-8541219.173 4903933.712, -8541021.692 4903935.025, -8540989.076 4903933.274))
\n", "

1 rows × 35 columns

\n", "
" ], "text/plain": [ " VERSION YEAR STFIPS CTFIPS ROUTEID BEGINPOINT \\\n", "ObjectID \n", "400000 2025.03.27 2020.0 42.0 43.0 1 22 0322 - 4031 4.862 \n", "\n", " ENDPOINT SIGN1 SIGNT1 SIGNN1 ... AADT_COM AADT_SINGL FUT_AADT \\\n", "ObjectID ... \n", "400000 4.973 U322 U 322 ... 553.0 593.0 0.0 \n", "\n", " FUT_YEAR MILES UPDATE_DAT NHS_ACTION FILE_NAME SHAPE_Length \\\n", "ObjectID \n", "400000 NaT 0.109283 NaT PA_NHS_2021 230.148704 \n", "\n", " geometry \n", "ObjectID \n", "400000 MULTILINESTRING ((-8541219.173 4903933.712, -8541021.692 4903935.025, -8540989.076 4903933.274)) \n", "\n", "[1 rows x 35 columns]" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "timer.start()\n", "# ------------\n", "this_row = ft_fc[row_index]\n", "# -----------\n", "timer.stop()\n", "this_row" ] }, { "cell_type": "markdown", "id": "2bb3f80ad9b4078", "metadata": {}, "source": [ "| | Fewer lines | More pythonic | Faster runtime | Overall |\n", "|----------:|:-----------:|:-------------:|:--------------:|:-------:|\n", "| ArcPy | ❌ | ❌ | ❌ | ❌ |\n", "| footbridge | ✅ | ✅ | ✅ | ✅ |" ] }, { "cell_type": "markdown", "id": "317a4224c9a58f0d", "metadata": {}, "source": "## Get a column" }, { "cell_type": "code", "execution_count": 13, "id": "a8b74e8dfbd3ffad", "metadata": { "ExecuteTime": { "end_time": "2025-08-31T22:44:28.183331Z", "start_time": "2025-08-31T22:44:28.177516Z" } }, "outputs": [], "source": [ "column_name = \"MILES\"" ] }, { "cell_type": "markdown", "id": "87789bdca2b1de22", "metadata": {}, "source": "### ArcPy" }, { "cell_type": "code", "execution_count": 14, "id": "613664a998ac2971", "metadata": { "ExecuteTime": { "end_time": "2025-08-31T22:44:31.512713Z", "start_time": "2025-08-31T22:44:28.303282Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "3.1782 seconds\n" ] }, { "data": { "text/plain": [ "['OBJECTID', 'Shape', 'MILES']" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "timer.start()\n", "# ------------\n", "fc_field_mapping = arcpy.FieldMappings()\n", "fc_field_mapping.addTable(arcpy_fc)\n", "mapping_index = fc_field_mapping.findFieldMapIndex(column_name)\n", "field_map = fc_field_mapping.getFieldMap(mapping_index)\n", "\n", "new_field_mapping = arcpy.FieldMappings()\n", "new_field_mapping.addFieldMap(field_map)\n", "\n", "arcpy_fc_col = os.path.join(\"memory\", fc_name + \"_col\")\n", "result = arcpy.conversion.ExportFeatures(\n", " arcpy_fc, arcpy_fc_col, field_mapping=new_field_mapping\n", ")\n", "# -----------\n", "timer.stop()\n", "[field.name for field in arcpy.ListFields(arcpy_fc_col)]" ] }, { "cell_type": "markdown", "id": "940ed8cb5be3c9f0", "metadata": {}, "source": "### footbridge" }, { "cell_type": "code", "execution_count": 15, "id": "14013ecd0bd708fb", "metadata": { "ExecuteTime": { "end_time": "2025-08-31T22:44:31.636405Z", "start_time": "2025-08-31T22:44:31.580142Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.0474 seconds\n" ] }, { "data": { "text/plain": [ "['ObjectID', 'MILES', 'geometry']" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "timer.start()\n", "# ------------\n", "ft_fc_col = ft_fc.select_columns(column_name)\n", "# -----------\n", "timer.stop()\n", "ft_fc_col.list_fields()" ] }, { "cell_type": "markdown", "id": "e8b14fee8ac4cf6b", "metadata": {}, "source": [ "| | Fewer lines | More pythonic | Faster runtime | Overall |\n", "|----------:|:-----------:|:-------------:|:--------------:|:-------:|\n", "| ArcPy | ❌ | ❌ | ❌ | ❌ |\n", "| footbridge | ✅ | ✅ | ✅ | ✅ |" ] }, { "cell_type": "markdown", "id": "977ac4f6b57d9196", "metadata": {}, "source": [ "## Field calculator\n", "### ArcPy" ] }, { "cell_type": "code", "execution_count": 16, "id": "e54f600c755b4730", "metadata": { "ExecuteTime": { "end_time": "2025-08-31T22:44:42.357599Z", "start_time": "2025-08-31T22:44:31.644930Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "10.6854 seconds\n" ] }, { "data": { "text/plain": [ "['OBJECTID',\n", " 'Shape',\n", " 'VERSION',\n", " 'YEAR',\n", " 'STFIPS',\n", " 'CTFIPS',\n", " 'ROUTEID',\n", " 'BEGINPOINT',\n", " 'ENDPOINT',\n", " 'SIGN1',\n", " 'SIGNT1',\n", " 'SIGNN1',\n", " 'LNAME',\n", " 'NHS',\n", " 'STATUS',\n", " 'FACID',\n", " 'CONNID',\n", " 'CONNDES',\n", " 'CONNMILES',\n", " 'ACLASS',\n", " 'FCLASS',\n", " 'FACILITYT',\n", " 'THROUGH_LA',\n", " 'SPEED_LIMI',\n", " 'OWNERSHIP',\n", " 'URBANCODE',\n", " 'AADT',\n", " 'AADT_COM',\n", " 'AADT_SINGL',\n", " 'FUT_AADT',\n", " 'FUT_YEAR',\n", " 'MILES',\n", " 'UPDATE_DAT',\n", " 'NHS_ACTION',\n", " 'FILE_NAME',\n", " 'KILOMETERS']" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "timer.start()\n", "# ------------\n", "arcpy.management.CalculateField(arcpy_fc, \"KILOMETERS\", \"!MILES! * 1.60934\", \"PYTHON3\")\n", "# -----------\n", "timer.stop()\n", "[field.name for field in arcpy.ListFields(arcpy_fc)]" ] }, { "cell_type": "markdown", "id": "e7482068991dd8e", "metadata": {}, "source": "### footbridge" }, { "cell_type": "code", "execution_count": 17, "id": "bf075bc61d0d4237", "metadata": { "ExecuteTime": { "end_time": "2025-08-31T22:44:42.504849Z", "start_time": "2025-08-31T22:44:42.437058Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.0597 seconds\n" ] }, { "data": { "text/plain": [ "['ObjectID',\n", " 'VERSION',\n", " 'YEAR',\n", " 'STFIPS',\n", " 'CTFIPS',\n", " 'ROUTEID',\n", " 'BEGINPOINT',\n", " 'ENDPOINT',\n", " 'SIGN1',\n", " 'SIGNT1',\n", " 'SIGNN1',\n", " 'LNAME',\n", " 'NHS',\n", " 'STATUS',\n", " 'FACID',\n", " 'CONNID',\n", " 'CONNDES',\n", " 'CONNMILES',\n", " 'ACLASS',\n", " 'FCLASS',\n", " 'FACILITYT',\n", " 'THROUGH_LA',\n", " 'SPEED_LIMI',\n", " 'OWNERSHIP',\n", " 'URBANCODE',\n", " 'AADT',\n", " 'AADT_COM',\n", " 'AADT_SINGL',\n", " 'FUT_AADT',\n", " 'FUT_YEAR',\n", " 'MILES',\n", " 'UPDATE_DAT',\n", " 'NHS_ACTION',\n", " 'FILE_NAME',\n", " 'SHAPE_Length',\n", " 'KILOMETERS',\n", " 'geometry']" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "timer.start()\n", "# ------------\n", "ft_fc.calculate(\"KILOMETERS\", \"MILES * 1.60934\")\n", "# -----------\n", "timer.stop()\n", "ft_fc.list_fields()" ] }, { "cell_type": "markdown", "id": "d6a52104c8ca92c7", "metadata": {}, "source": [ "| | Fewer lines | More pythonic | Faster runtime | Overall |\n", "|----------:|:-----------:|:-------------:|:--------------:|:-------:|\n", "| ArcPy | ✅ | ✅ | ❌ | ❌ |\n", "| footbridge | ✅ | ✅ | ✅ | ✅ |" ] }, { "cell_type": "markdown", "id": "90b6a26141e9b7fa", "metadata": {}, "source": [ "## Buffer\n", "### ArcPy" ] }, { "cell_type": "code", "execution_count": 18, "id": "8f027d66cb42d89f", "metadata": { "ExecuteTime": { "end_time": "2025-08-31T22:44:42.701643Z", "start_time": "2025-08-31T22:44:42.519395Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.1783 seconds\n" ] } ], "source": [ "timer.start()\n", "# ------------\n", "arcpy_fc_buffered = os.path.join(\"memory\", fc_name + \"_buffered\")\n", "arcpy.analysis.PairwiseBuffer(arcpy_fc_filtered, arcpy_fc_buffered, \"10 Miles\")\n", "# -----------\n", "timer.stop()" ] }, { "cell_type": "markdown", "id": "e367b319055218cb", "metadata": {}, "source": "### footbridge" }, { "cell_type": "code", "execution_count": 19, "id": "270e0071096b92ac", "metadata": { "ExecuteTime": { "end_time": "2025-08-31T22:44:42.722156Z", "start_time": "2025-08-31T22:44:42.713474Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "< 10 ms\n" ] } ], "source": [ "timer.start()\n", "# ------------\n", "buffered = ft_fc_filtered.gdf.buffer(10 * 1609.344) # geometry units are meters\n", "ft_fc_buffered = ft.FeatureClass(buffered)\n", "# -----------\n", "timer.stop()" ] }, { "cell_type": "markdown", "id": "71050d2d36cd0b9a", "metadata": {}, "source": [ "| | Fewer lines | More pythonic | Faster runtime | Overall |\n", "|----------:|:-----------:|:-------------:|:--------------:|:-------:|\n", "| ArcPy | ✅ | ✅ | ❌ | ❌ |\n", "| footbridge | ❌ | ✅ | ✅ | ✅ |" ] }, { "cell_type": "markdown", "id": "ac2acca0df78b5f2", "metadata": {}, "source": "## Copy feature class to new geodatabase" }, { "cell_type": "code", "execution_count": 20, "id": "13cf1cf75230fa2c", "metadata": { "ExecuteTime": { "end_time": "2025-08-31T22:44:42.741922Z", "start_time": "2025-08-31T22:44:42.737792Z" } }, "outputs": [], "source": [ "out_folder = os.path.abspath(\".\")\n", "gdb_name = \"test.gdb\"\n", "out_gdb = os.path.join(out_folder, gdb_name)\n", "out_fc = os.path.join(out_gdb, fc_name)" ] }, { "cell_type": "markdown", "id": "dc2636d6f3322439", "metadata": {}, "source": "### ArcPy" }, { "cell_type": "code", "execution_count": 21, "id": "f9e1828c81640cd7", "metadata": { "ExecuteTime": { "end_time": "2025-08-31T22:44:59.305934Z", "start_time": "2025-08-31T22:44:42.777642Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "16.5243 seconds\n" ] } ], "source": [ "timer.start()\n", "# ------------\n", "arcpy.management.CreateFileGDB(out_folder, gdb_name)\n", "arcpy.conversion.ExportFeatures(arcpy_fc, out_fc)\n", "# -----------\n", "timer.stop()" ] }, { "cell_type": "markdown", "id": "dc41c091a2afc969", "metadata": {}, "source": "### footbridge" }, { "cell_type": "code", "execution_count": 22, "id": "4f1be50da232625", "metadata": { "ExecuteTime": { "end_time": "2025-08-31T22:45:17.808436Z", "start_time": "2025-08-31T22:44:59.380793Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "18.4099 seconds\n" ] } ], "source": [ "timer.start()\n", "# ------------\n", "ft_fc.save(out_gdb, fc_name, overwrite=True)\n", "# -----------\n", "timer.stop()" ] }, { "cell_type": "markdown", "id": "25989559558a87cd", "metadata": {}, "source": [ "| | Fewer lines | More pythonic | Faster runtime | Overall |\n", "|----------:|:-----------:|:-------------:|:--------------:|:-------:|\n", "| ArcPy | ❌ | ✅ | ✅ | ✅ |\n", "| footbridge | ✅ | ✅ | ❌ | ✅ |" ] }, { "cell_type": "markdown", "id": "77d138bc4585d9d4", "metadata": {}, "source": [ "## Summary\n", "\n", "| | ArcPy | footbridge |\n", "|----------------------:|:-----:|:---------:|\n", "| Load feature class | ❌ | ✅ |\n", "| Count rows | ❌ | ✅ |\n", "| Filter rows | ❌ | ✅ |\n", "| Get the last row | ❌ | ✅ |\n", "| Get a row at an index | ❌ | ✅ |\n", "| Get a column | ❌ | ✅ |\n", "| Field calculator | ❌ | ✅ |\n", "| Buffer | ❌ | ✅ |\n", "| Copy to new GDB | ✅ | ✅ |\n" ] } ], "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 }