{ "cells": [ { "metadata": {}, "cell_type": "markdown", "source": "# Field Calculations", "id": "1352f7a09dd0bcb0" }, { "metadata": { "ExecuteTime": { "end_time": "2026-05-01T01:27:44.495280267Z", "start_time": "2026-05-01T01:27:44.445842745Z" } }, "cell_type": "code", "source": "import footbridge as ft", "id": "70a74488247e76b7", "outputs": [], "execution_count": 11 }, { "metadata": { "ExecuteTime": { "end_time": "2026-05-01T01:27:44.541920093Z", "start_time": "2026-05-01T01:27:44.495998301Z" } }, "cell_type": "code", "source": [ "# large dataset of US National Highway System roads\n", "# https://hepgis-usdot.hub.arcgis.com/datasets/dce9f09392eb474c8ad8e6a78416279b_0\n", "gdb_file = \"NHS.gdb\"" ], "id": "40256b93c77f7073", "outputs": [], "execution_count": 12 }, { "metadata": { "ExecuteTime": { "end_time": "2026-05-01T01:27:56.525044543Z", "start_time": "2026-05-01T01:27:44.542656710Z" } }, "cell_type": "code", "source": "gdb = ft.GeoDatabase(gdb_file)", "id": "ae69d18f3691773a", "outputs": [], "execution_count": 13 }, { "metadata": { "ExecuteTime": { "end_time": "2026-05-01T01:27:56.622908717Z", "start_time": "2026-05-01T01:27:56.576589846Z" } }, "cell_type": "code", "source": "fc = gdb[0]", "id": "9c11a257cbc298f2", "outputs": [], "execution_count": 14 }, { "metadata": { "ExecuteTime": { "end_time": "2026-05-01T01:27:56.671005534Z", "start_time": "2026-05-01T01:27:56.623681419Z" } }, "cell_type": "code", "source": "fc.list_fields()", "id": "ef8b9e89db39c726", "outputs": [ { "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", " 'geometry']" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "execution_count": 15 }, { "metadata": { "ExecuteTime": { "end_time": "2026-05-01T01:27:56.722021108Z", "start_time": "2026-05-01T01:27:56.671637956Z" } }, "cell_type": "code", "source": "fc.select_columns(\"VERSION\", geometry=False).head(silent=True)", "id": "8931f9eab93582f2", "outputs": [ { "data": { "text/plain": [ " VERSION\n", "ObjectID \n", "0 2025.08.08\n", "1 2025.08.08\n", "2 2025.08.08\n", "3 2025.08.08\n", "4 2025.08.08\n", "5 2025.08.08\n", "6 2025.08.08\n", "7 2025.08.08\n", "8 2025.08.08\n", "9 2025.08.08" ], "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", "
VERSION
ObjectID
02025.08.08
12025.08.08
22025.08.08
32025.08.08
42025.08.08
52025.08.08
62025.08.08
72025.08.08
82025.08.08
92025.08.08
\n", "
" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "execution_count": 16 }, { "metadata": { "ExecuteTime": { "end_time": "2026-05-01T01:27:56.995183001Z", "start_time": "2026-05-01T01:27:56.722753226Z" } }, "cell_type": "code", "source": [ "# change all the rows in the \"VERSION\" column to \"2025\"\n", "fc.calculate(\"VERSION\", \"2025\")" ], "id": "778e81d6a600d917", "outputs": [], "execution_count": 17 }, { "metadata": { "ExecuteTime": { "end_time": "2026-05-01T01:27:57.108793942Z", "start_time": "2026-05-01T01:27:57.059139185Z" } }, "cell_type": "code", "source": "fc.select_columns(\"VERSION\", geometry=False).head(silent=True)", "id": "1422ed010961bc23", "outputs": [ { "data": { "text/plain": [ " VERSION\n", "ObjectID \n", "0 2025\n", "1 2025\n", "2 2025\n", "3 2025\n", "4 2025\n", "5 2025\n", "6 2025\n", "7 2025\n", "8 2025\n", "9 2025" ], "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", "
VERSION
ObjectID
02025
12025
22025
32025
42025
52025
62025
72025
82025
92025
\n", "
" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "execution_count": 18 }, { "metadata": { "ExecuteTime": { "end_time": "2026-05-01T01:28:24.655016383Z", "start_time": "2026-05-01T01:27:57.109600605Z" } }, "cell_type": "code", "source": [ "fc.calculate(\"km\", \"float($MILES$) * 1.609344\")\n", "fc.select_columns((\"MILES\", \"km\"), geometry=False).head(silent=True)" ], "id": "92b4c367a3862e7d", "outputs": [ { "data": { "text/plain": [ " MILES km\n", "ObjectID \n", "0 17.912424 28.827252\n", "1 0.949648 1.528310\n", "2 1.429447 2.300472\n", "3 2.889823 4.650719\n", "4 0.249906 0.402185\n", "5 0.368853 0.593611\n", "6 12.455991 20.045974\n", "7 7.699296 12.390816\n", "8 3.027736 4.872669\n", "9 0.160367 0.258086" ], "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", "
MILESkm
ObjectID
017.91242428.827252
10.9496481.528310
21.4294472.300472
32.8898234.650719
40.2499060.402185
50.3688530.593611
612.45599120.045974
77.69929612.390816
83.0277364.872669
90.1603670.258086
\n", "
" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "execution_count": 19 } ], "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 }