From 323d0d2c51ae6d3c97568040a9ddf0b4c8d6efd0 Mon Sep 17 00:00:00 2001 From: Manushi Majumdar Date: Fri, 19 Sep 2025 23:16:46 -0400 Subject: [PATCH] updating data and mapping functions --- .../part5_generate_od_cost_matrix.ipynb | 1377 ++++++++--------- 1 file changed, 626 insertions(+), 751 deletions(-) diff --git a/guide/11-performing-network-analyses/part5_generate_od_cost_matrix.ipynb b/guide/11-performing-network-analyses/part5_generate_od_cost_matrix.ipynb index 849b2aaedd..7fb68acb20 100644 --- a/guide/11-performing-network-analyses/part5_generate_od_cost_matrix.ipynb +++ b/guide/11-performing-network-analyses/part5_generate_od_cost_matrix.ipynb @@ -122,6 +122,8 @@ "from arcgis.gis import GIS\n", "import arcgis.network as network\n", "from arcgis.features import FeatureLayer, Feature, FeatureSet, FeatureCollection, use_proximity\n", + "from arcgis.map.symbols import SimpleLineSymbolEsriSLS, PictureMarkerSymbolEsriPMS\n", + "from arcgis.map.popups import PopupInfo\n", "import pandas as pd\n", "import time\n", "import datetime as dt" @@ -140,7 +142,7 @@ "metadata": {}, "outputs": [], "source": [ - "my_gis = GIS('home')" + "my_gis = GIS(profile='your_online_profile')" ] }, { @@ -194,36 +196,22 @@ "execution_count": 3, "metadata": {}, "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "You do not have permissions to access this resource or perform this operation.\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Trying from an alternative source...\n" - ] - }, { "data": { "text/html": [ "
\n", " \n", "\n", "
\n", - " hospitals_SB_county\n", + " hospitals_SB_county\n", " \n", - "
Feature Layer Collection by arcgis_python\n", - "
Last Modified: September 27, 2019\n", - "
0 comments, 10 views\n", + "

Feature Layer Collection by arcgis_python\n", + "
Last Modified: October 21, 2021\n", + "
0 comments, 55 views\n", "
\n", "
\n", " " @@ -232,36 +220,14 @@ "" ] }, + "execution_count": 3, "metadata": {}, - "output_type": "display_data" + "output_type": "execute_result" } ], "source": [ - "\"\"\" This try-except block will help you download the CSV and publish to current GIS object, if \n", - " \"You do not have permissions to access this resource or perform this operation.\"\n", - "\"\"\"\n", - "try:\n", - " hospital_item = my_gis.content.get(\"a2817bf9632a43f5ad1c6b0c153b0fab\")\n", - "except RuntimeError as ne:\n", - " try:\n", - " print(\"Trying from an alternative source...\")\n", - " hospital_item = my_gis.content.get(\"50fb63f303304835a048d16bd86c3024\")\n", - " except RuntimeError as ne:\n", - " print(\"Trying to publish from csv...\")\n", - " import requests\n", - " import csv\n", - " import os\n", - "\n", - " out_file_name = 'hospitals_SB_county.csv'\n", - " url = \"https://data.chhs.ca.gov/datastore/dump/641c5557-7d65-4379-8fea-6b7dedbda40b?q=&sort=_id+asc&fields=OSHPD_ID%2CFACILITY_NAME%2CLICENSE_NUM%2CFACILITY_LEVEL_DESC%2CDBA_ADDRESS1%2CDBA_CITY%2CDBA_ZIP_CODE%2CCOUNTY_CODE%2CCOUNTY_NAME%2CER_SERVICE_LEVEL_DESC%2CTOTAL_NUMBER_BEDS%2CFACILITY_STATUS_DESC%2CFACILITY_STATUS_DATE%2CLICENSE_TYPE_DESC%2CLICENSE_CATEGORY_DESC%2CLATITUDE%2CLONGITUDE&filters=%7B%22COUNTY_CODE%22%3A+%5B%2236%22%5D%7D&format=csv\"\n", - " download = requests.get(url)\n", - "\n", - " with open(out_file_name, 'w') as out_file:\n", - " out_file.writelines(download.text)\n", - " print(out_file_name)\n", - " csv_item = my_gis.content.add({}, out_file_name)\n", - " hospital_item = csv_item.publish()\n", - "display(hospital_item)" + "hospital_item = my_gis.content.get(\"e438435c220b4713b0a5779a8ebb5d16\")\n", + "hospital_item" ] }, { @@ -269,25 +235,10 @@ "execution_count": 4, "metadata": {}, "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "\n", - "'Invalid field: County' parameter is invalid\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Trying from an alternative approach...\n" - ] - }, { "data": { "text/plain": [ - " 33 features" + " 36 features" ] }, "metadata": {}, @@ -296,17 +247,7 @@ ], "source": [ "hospital_fl = FeatureLayer(hospital_item.url + \"/0\")\n", - "\n", - "\"\"\" If you are using the exisiting layer from Esri_LivngAtlas, there is a \"County\" column in the dataset;\n", - " or else, the feature layer collection published from the downloaded CSV file is already targetted at SB County.\n", - "\"\"\"\n", - "try:\n", - " facilities = hospital_fl.query(where=\"County='SAN BERNARDINO' AND State='CA'\", as_df=False)\n", - "except RuntimeError as re:\n", - " \"\"\" when seeing 'Invalid field: County' parameter is invalid\n", - " \"\"\"\n", - " print(\"Trying from an alternative approach...\")\n", - " facilities = hospital_fl.query(where=\"Dba_city='REDLANDS' or Dba_city='LOMA LINDA'\", as_df=False)\n", + "facilities = hospital_fl.query(where=\"DBA_CITY='Redlands' or DBA_CITY='Loma Linda'\", as_df=False)\n", "display(facilities)" ] }, @@ -385,36 +326,34 @@ } ], "source": [ - "map1 = my_gis.map('Redlands, CA', zoomlevel=12)\n", + "map1 = my_gis.map('Redlands, CA')\n", "map1" ] }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ - "map1.clear_graphics()\n", - "\n", - "hospital_symbol = {\"type\":\"esriPMS\",\n", - " \"url\":\"http://static.arcgis.com/images/Symbols/SafetyHealth/Hospital.png\",\n", - " \"contentType\": \"image/png\", \"width\":20, \"height\":20}\n", + "hospital_symbol = PictureMarkerSymbolEsriPMS(**{\"type\":\"esriPMS\",\n", + " \"url\":\"http://static.arcgis.com/images/Symbols/SafetyHealth/Hospital.png\",\n", + " \"contentType\":\"image/png\",\"width\":20,\"height\":20})\n", "\n", - "map1.draw(facilities, symbol=hospital_symbol)" + "map1.content.draw(facilities, symbol=hospital_symbol)" ] }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ - "traffic_accident_symbol = {\"type\":\"esriPMS\",\n", - " \"url\":\"http://static.arcgis.com/images/Symbols/Transportation/TrafficAccident.png\",\n", - " \"contentType\": \"image/png\", \"width\":20, \"height\":20}\n", + "traffic_accident_symbol = PictureMarkerSymbolEsriPMS(**{\"type\":\"esriPMS\",\n", + " \"url\":\"http://static.arcgis.com/images/Symbols/Transportation/TrafficAccident.png\",\n", + " \"contentType\":\"image/png\",\"width\":20,\"height\":20})\n", "\n", - "map1.draw(incidents, symbol=traffic_accident_symbol)" + "map1.content.draw(incidents, symbol=traffic_accident_symbol)" ] }, { @@ -436,14 +375,15 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Wall time: 8.35 s\n" + "CPU times: total: 1.22 s\n", + "Wall time: 30 s\n" ] } ], @@ -468,7 +408,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -485,7 +425,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -509,7 +449,7 @@ { "data": { "text/plain": [ - " 33 features" + " 36 features" ] }, "metadata": {}, @@ -531,7 +471,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -555,119 +495,131 @@ " \n", " \n", " \n", - " DestinationName\n", - " DestinationOID\n", - " DestinationRank\n", " ObjectID\n", - " OriginName\n", + " DestinationRank\n", + " Total_Time\n", + " Total_Distance\n", + " OriginID\n", " OriginOID\n", - " SHAPE\n", + " OriginName\n", + " DestinationID\n", + " DestinationOID\n", + " DestinationName\n", " Shape_Length\n", - " Total_Distance\n", - " Total_Time\n", + " SHAPE\n", " \n", " \n", " \n", " \n", " 19\n", - " Location 4\n", - " 23\n", - " 4\n", " 20\n", - " Incident at Bowling\n", + " 4\n", + " 1.718791\n", + " 1.056159\n", " 5\n", - " {'paths': [[[-117.19469899999996, 34.063568000...\n", - " 0.014748\n", - " 1.909752\n", - " 4.016058\n", + " 5\n", + " Incident at Bowling\n", + " 32\n", + " 305\n", + " Location 32\n", + " 0.007773\n", + " {\"paths\": [[[-117.19469899999996, 34.063568000...\n", " \n", " \n", " 20\n", - " Location 31\n", - " 357\n", - " 1\n", " 21\n", - " Incident at Burger\n", + " 1\n", + " 0.563098\n", + " 0.190786\n", + " 6\n", " 6\n", - " {'paths': [[[-117.20120099999997, 34.063364000...\n", + " Incident at Burger\n", + " 36\n", + " 448\n", + " Location 36\n", " 0.001528\n", - " 0.202159\n", - " 0.665024\n", + " {\"paths\": [[[-117.20120099999997, 34.063364000...\n", " \n", " \n", " 21\n", - " Location 27\n", - " 245\n", - " 2\n", " 22\n", + " 2\n", + " 0.898813\n", + " 0.189793\n", + " 6\n", + " 6\n", " Incident at Burger\n", " 6\n", - " {'paths': [[[-117.20120099999997, 34.063364000...\n", - " 0.005566\n", - " 0.684698\n", - " 1.734902\n", + " 111\n", + " Location 6\n", + " 0.001413\n", + " {\"paths\": [[[-117.20120099999997, 34.063364000...\n", " \n", " \n", " 22\n", - " Location 28\n", - " 256\n", - " 3\n", " 23\n", - " Incident at Burger\n", + " 3\n", + " 1.732952\n", + " 0.784955\n", + " 6\n", " 6\n", - " {'paths': [[[-117.20120099999997, 34.063364000...\n", + " Incident at Burger\n", + " 31\n", + " 295\n", + " Location 31\n", " 0.005566\n", - " 0.684698\n", - " 1.734902\n", + " {\"paths\": [[[-117.20120099999997, 34.063364000...\n", " \n", " \n", " 23\n", - " Location 5\n", - " 41\n", - " 4\n", " 24\n", - " Incident at Burger\n", + " 4\n", + " 1.732952\n", + " 0.784955\n", + " 6\n", " 6\n", - " {'paths': [[[-117.20120099999997, 34.063364000...\n", - " 0.016599\n", - " 2.150643\n", - " 3.899969\n", + " Incident at Burger\n", + " 32\n", + " 305\n", + " Location 32\n", + " 0.005566\n", + " {\"paths\": [[[-117.20120099999997, 34.063364000...\n", " \n", " \n", "\n", "" ], "text/plain": [ - " DestinationName DestinationOID DestinationRank ObjectID \\\n", - "19 Location 4 23 4 20 \n", - "20 Location 31 357 1 21 \n", - "21 Location 27 245 2 22 \n", - "22 Location 28 256 3 23 \n", - "23 Location 5 41 4 24 \n", + " ObjectID DestinationRank Total_Time Total_Distance OriginID \\\n", + "19 20 4 1.718791 1.056159 5 \n", + "20 21 1 0.563098 0.190786 6 \n", + "21 22 2 0.898813 0.189793 6 \n", + "22 23 3 1.732952 0.784955 6 \n", + "23 24 4 1.732952 0.784955 6 \n", "\n", - " OriginName OriginOID \\\n", - "19 Incident at Bowling 5 \n", - "20 Incident at Burger 6 \n", - "21 Incident at Burger 6 \n", - "22 Incident at Burger 6 \n", - "23 Incident at Burger 6 \n", + " OriginOID OriginName DestinationID DestinationOID \\\n", + "19 5 Incident at Bowling 32 305 \n", + "20 6 Incident at Burger 36 448 \n", + "21 6 Incident at Burger 6 111 \n", + "22 6 Incident at Burger 31 295 \n", + "23 6 Incident at Burger 32 305 \n", "\n", - " SHAPE Shape_Length \\\n", - "19 {'paths': [[[-117.19469899999996, 34.063568000... 0.014748 \n", - "20 {'paths': [[[-117.20120099999997, 34.063364000... 0.001528 \n", - "21 {'paths': [[[-117.20120099999997, 34.063364000... 0.005566 \n", - "22 {'paths': [[[-117.20120099999997, 34.063364000... 0.005566 \n", - "23 {'paths': [[[-117.20120099999997, 34.063364000... 0.016599 \n", + " DestinationName Shape_Length \\\n", + "19 Location 32 0.007773 \n", + "20 Location 36 0.001528 \n", + "21 Location 6 0.001413 \n", + "22 Location 31 0.005566 \n", + "23 Location 32 0.005566 \n", "\n", - " Total_Distance Total_Time \n", - "19 1.909752 4.016058 \n", - "20 0.202159 0.665024 \n", - "21 0.684698 1.734902 \n", - "22 0.684698 1.734902 \n", - "23 2.150643 3.899969 " + " SHAPE \n", + "19 {\"paths\": [[[-117.19469899999996, 34.063568000... \n", + "20 {\"paths\": [[[-117.20120099999997, 34.063364000... \n", + "21 {\"paths\": [[[-117.20120099999997, 34.063364000... \n", + "22 {\"paths\": [[[-117.20120099999997, 34.063364000... \n", + "23 {\"paths\": [[[-117.20120099999997, 34.063364000... " ] }, - "execution_count": 9, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -678,10 +630,8 @@ }, { "cell_type": "code", - "execution_count": 10, - "metadata": { - "scrolled": false - }, + "execution_count": 14, + "metadata": {}, "outputs": [ { "data": { @@ -716,193 +666,193 @@ " 0\n", " Incident at Esri\n", " 1\n", - " 245\n", - " 1.103517\n", - " 2.071802\n", + " 295\n", + " 0.87555\n", + " 1.864816\n", " \n", " \n", " 1\n", " Incident at Esri\n", " 1\n", - " 256\n", - " 1.103517\n", - " 2.071802\n", + " 305\n", + " 0.87555\n", + " 1.864816\n", " \n", " \n", " 2\n", " Incident at Esri\n", " 1\n", - " 357\n", - " 1.229031\n", - " 2.671727\n", + " 448\n", + " 1.250166\n", + " 2.45826\n", " \n", " \n", " 3\n", " Incident at Esri\n", " 1\n", - " 23\n", - " 1.710835\n", - " 3.592510\n", + " 111\n", + " 1.249173\n", + " 2.793975\n", " \n", " \n", " 4\n", " Incident at APT\n", " 2\n", - " 65\n", - " 0.692399\n", - " 1.274009\n", + " 137\n", + " 0.434045\n", + " 0.860211\n", " \n", " \n", " 5\n", " Incident at APT\n", " 2\n", - " 41\n", - " 0.431708\n", - " 1.310646\n", + " 162\n", + " 0.703422\n", + " 1.113239\n", " \n", " \n", " 6\n", " Incident at APT\n", " 2\n", - " 90\n", - " 1.093573\n", - " 1.947980\n", + " 195\n", + " 1.261744\n", + " 1.564755\n", " \n", " \n", " 7\n", " Incident at APT\n", " 2\n", - " 98\n", - " 1.332103\n", - " 2.174232\n", + " 187\n", + " 1.091988\n", + " 1.618107\n", " \n", " \n", " 8\n", " Incident at Walmart\n", " 3\n", - " 121\n", - " 1.269695\n", - " 3.007999\n", + " 100\n", + " 0.603005\n", + " 1.710463\n", " \n", " \n", " 9\n", " Incident at Walmart\n", " 3\n", - " 207\n", - " 1.413950\n", - " 3.194782\n", + " 229\n", + " 1.265384\n", + " 2.438137\n", " \n", " \n", " 10\n", " Incident at Walmart\n", " 3\n", - " 357\n", - " 2.099291\n", - " 4.401875\n", + " 104\n", + " 1.297613\n", + " 2.723433\n", " \n", " \n", " 11\n", " Incident at Walmart\n", " 3\n", - " 48\n", - " 1.978585\n", - " 4.644457\n", + " 216\n", + " 1.599973\n", + " 2.878808\n", " \n", " \n", " 12\n", " Incident at High school\n", " 4\n", - " 245\n", - " 1.295173\n", - " 2.218085\n", + " 295\n", + " 1.407225\n", + " 2.88428\n", " \n", " \n", " 13\n", " Incident at High school\n", " 4\n", - " 256\n", - " 1.295173\n", - " 2.218085\n", + " 305\n", + " 1.407225\n", + " 2.88428\n", " \n", " \n", " 14\n", " Incident at High school\n", " 4\n", - " 357\n", - " 1.285388\n", - " 2.442592\n", + " 448\n", + " 1.356377\n", + " 3.078551\n", " \n", " \n", " 15\n", " Incident at High school\n", " 4\n", - " 23\n", - " 1.269365\n", - " 2.524285\n", + " 251\n", + " 1.437629\n", + " 3.297676\n", " \n", " \n", " 16\n", " Incident at Bowling\n", " 5\n", - " 357\n", - " 0.819273\n", - " 2.058579\n", + " 448\n", + " 0.731823\n", + " 1.17324\n", " \n", " \n", " 17\n", " Incident at Bowling\n", " 5\n", - " 245\n", - " 1.137488\n", - " 2.551424\n", + " 111\n", + " 0.73083\n", + " 1.508955\n", " \n", " \n", " 18\n", " Incident at Bowling\n", " 5\n", - " 256\n", - " 1.137488\n", - " 2.551424\n", + " 295\n", + " 1.056159\n", + " 1.718791\n", " \n", " \n", " 19\n", " Incident at Bowling\n", " 5\n", - " 23\n", - " 1.909752\n", - " 4.016058\n", + " 305\n", + " 1.056159\n", + " 1.718791\n", " \n", " \n", " 20\n", " Incident at Burger\n", " 6\n", - " 357\n", - " 0.202159\n", - " 0.665024\n", + " 448\n", + " 0.190786\n", + " 0.563098\n", " \n", " \n", " 21\n", " Incident at Burger\n", " 6\n", - " 245\n", - " 0.684698\n", - " 1.734902\n", + " 111\n", + " 0.189793\n", + " 0.898813\n", " \n", " \n", " 22\n", " Incident at Burger\n", " 6\n", - " 256\n", - " 0.684698\n", - " 1.734902\n", + " 295\n", + " 0.784955\n", + " 1.732952\n", " \n", " \n", " 23\n", " Incident at Burger\n", " 6\n", - " 41\n", - " 2.150643\n", - " 3.899969\n", + " 305\n", + " 0.784955\n", + " 1.732952\n", " \n", " \n", "\n", @@ -910,56 +860,56 @@ ], "text/plain": [ " OriginName OriginOID DestinationOID Total_Distance \\\n", - "0 Incident at Esri 1 245 1.103517 \n", - "1 Incident at Esri 1 256 1.103517 \n", - "2 Incident at Esri 1 357 1.229031 \n", - "3 Incident at Esri 1 23 1.710835 \n", - "4 Incident at APT 2 65 0.692399 \n", - "5 Incident at APT 2 41 0.431708 \n", - "6 Incident at APT 2 90 1.093573 \n", - "7 Incident at APT 2 98 1.332103 \n", - "8 Incident at Walmart 3 121 1.269695 \n", - "9 Incident at Walmart 3 207 1.413950 \n", - "10 Incident at Walmart 3 357 2.099291 \n", - "11 Incident at Walmart 3 48 1.978585 \n", - "12 Incident at High school 4 245 1.295173 \n", - "13 Incident at High school 4 256 1.295173 \n", - "14 Incident at High school 4 357 1.285388 \n", - "15 Incident at High school 4 23 1.269365 \n", - "16 Incident at Bowling 5 357 0.819273 \n", - "17 Incident at Bowling 5 245 1.137488 \n", - "18 Incident at Bowling 5 256 1.137488 \n", - "19 Incident at Bowling 5 23 1.909752 \n", - "20 Incident at Burger 6 357 0.202159 \n", - "21 Incident at Burger 6 245 0.684698 \n", - "22 Incident at Burger 6 256 0.684698 \n", - "23 Incident at Burger 6 41 2.150643 \n", + "0 Incident at Esri 1 295 0.87555 \n", + "1 Incident at Esri 1 305 0.87555 \n", + "2 Incident at Esri 1 448 1.250166 \n", + "3 Incident at Esri 1 111 1.249173 \n", + "4 Incident at APT 2 137 0.434045 \n", + "5 Incident at APT 2 162 0.703422 \n", + "6 Incident at APT 2 195 1.261744 \n", + "7 Incident at APT 2 187 1.091988 \n", + "8 Incident at Walmart 3 100 0.603005 \n", + "9 Incident at Walmart 3 229 1.265384 \n", + "10 Incident at Walmart 3 104 1.297613 \n", + "11 Incident at Walmart 3 216 1.599973 \n", + "12 Incident at High school 4 295 1.407225 \n", + "13 Incident at High school 4 305 1.407225 \n", + "14 Incident at High school 4 448 1.356377 \n", + "15 Incident at High school 4 251 1.437629 \n", + "16 Incident at Bowling 5 448 0.731823 \n", + "17 Incident at Bowling 5 111 0.73083 \n", + "18 Incident at Bowling 5 295 1.056159 \n", + "19 Incident at Bowling 5 305 1.056159 \n", + "20 Incident at Burger 6 448 0.190786 \n", + "21 Incident at Burger 6 111 0.189793 \n", + "22 Incident at Burger 6 295 0.784955 \n", + "23 Incident at Burger 6 305 0.784955 \n", "\n", " Total_Time \n", - "0 2.071802 \n", - "1 2.071802 \n", - "2 2.671727 \n", - "3 3.592510 \n", - "4 1.274009 \n", - "5 1.310646 \n", - "6 1.947980 \n", - "7 2.174232 \n", - "8 3.007999 \n", - "9 3.194782 \n", - "10 4.401875 \n", - "11 4.644457 \n", - "12 2.218085 \n", - "13 2.218085 \n", - "14 2.442592 \n", - "15 2.524285 \n", - "16 2.058579 \n", - "17 2.551424 \n", - "18 2.551424 \n", - "19 4.016058 \n", - "20 0.665024 \n", - "21 1.734902 \n", - "22 1.734902 \n", - "23 3.899969 " + "0 1.864816 \n", + "1 1.864816 \n", + "2 2.45826 \n", + "3 2.793975 \n", + "4 0.860211 \n", + "5 1.113239 \n", + "6 1.564755 \n", + "7 1.618107 \n", + "8 1.710463 \n", + "9 2.438137 \n", + "10 2.723433 \n", + "11 2.878808 \n", + "12 2.88428 \n", + "13 2.88428 \n", + "14 3.078551 \n", + "15 3.297676 \n", + "16 1.17324 \n", + "17 1.508955 \n", + "18 1.718791 \n", + "19 1.718791 \n", + "20 0.563098 \n", + "21 0.898813 \n", + "22 1.732952 \n", + "23 1.732952 " ] }, "metadata": {}, @@ -983,7 +933,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 15, "metadata": {}, "outputs": [ { @@ -999,45 +949,27 @@ " vertical-align: top;\n", " }\n", "\n", - " .dataframe thead tr th {\n", - " text-align: left;\n", - " }\n", - "\n", - " .dataframe thead tr:last-of-type th {\n", + " .dataframe thead th {\n", " text-align: right;\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", @@ -1054,218 +986,146 @@ " \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", + " \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", + " \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", "
Total_Distance...Total_Time
DestinationOID234148659098121207245256...4148659098121207245256357100104111137162187195216229251295305448
OriginOID
11.710835NaNNaNNaNNaNNaNNaNNaN1.1035171.103517...NaNNaNNaNNaNNaNNaNNaN2.0718022.0718022.671727<NA><NA>1.249173<NA><NA><NA><NA><NA><NA><NA>0.875550.875551.250166
2NaN0.431708NaN0.6923991.0935731.332103NaNNaNNaNNaN...1.310646NaN1.2740091.947982.174232NaNNaNNaNNaNNaN<NA><NA><NA>0.4340450.7034221.0919881.261744<NA><NA><NA><NA><NA><NA>
3NaNNaN1.978585NaNNaNNaN1.2696951.41395NaNNaN...NaN4.644457NaNNaNNaN3.0079993.194782NaNNaN4.4018750.6030051.297613<NA><NA><NA><NA><NA>1.5999731.265384<NA><NA><NA><NA>
41.269365NaNNaNNaNNaNNaNNaNNaN1.2951731.295173...NaNNaNNaNNaNNaNNaNNaN2.2180852.2180852.442592<NA><NA><NA><NA><NA><NA><NA><NA><NA>1.4376291.4072251.4072251.356377
51.909752NaNNaNNaNNaNNaNNaNNaN1.1374881.137488...NaNNaNNaNNaNNaNNaNNaN2.5514242.5514242.058579<NA><NA>0.73083<NA><NA><NA><NA><NA><NA><NA>1.0561591.0561590.731823
6NaN2.150643NaNNaNNaNNaNNaNNaN0.6846980.684698...3.899969NaNNaNNaNNaNNaNNaN1.7349021.7349020.665024<NA><NA>0.189793<NA><NA><NA><NA><NA><NA><NA>0.7849550.7849550.190786
\n", - "

6 rows × 22 columns

\n", "" ], "text/plain": [ - " Total_Distance \\\n", - "DestinationOID 23 41 48 65 90 \n", - "OriginOID \n", - "1 1.710835 NaN NaN NaN NaN \n", - "2 NaN 0.431708 NaN 0.692399 1.093573 \n", - "3 NaN NaN 1.978585 NaN NaN \n", - "4 1.269365 NaN NaN NaN NaN \n", - "5 1.909752 NaN NaN NaN NaN \n", - "6 NaN 2.150643 NaN NaN NaN \n", - "\n", - " ... \\\n", - "DestinationOID 98 121 207 245 256 ... \n", - "OriginOID ... \n", - "1 NaN NaN NaN 1.103517 1.103517 ... \n", - "2 1.332103 NaN NaN NaN NaN ... \n", - "3 NaN 1.269695 1.41395 NaN NaN ... \n", - "4 NaN NaN NaN 1.295173 1.295173 ... \n", - "5 NaN NaN NaN 1.137488 1.137488 ... \n", - "6 NaN NaN NaN 0.684698 0.684698 ... \n", - "\n", - " Total_Time \\\n", - "DestinationOID 41 48 65 90 98 121 \n", + "DestinationOID 100 104 111 137 162 187 \\\n", "OriginOID \n", - "1 NaN NaN NaN NaN NaN NaN \n", - "2 1.310646 NaN 1.274009 1.94798 2.174232 NaN \n", - "3 NaN 4.644457 NaN NaN NaN 3.007999 \n", - "4 NaN NaN NaN NaN NaN NaN \n", - "5 NaN NaN NaN NaN NaN NaN \n", - "6 3.899969 NaN NaN NaN NaN NaN \n", + "1 1.249173 \n", + "2 0.434045 0.703422 1.091988 \n", + "3 0.603005 1.297613 \n", + "4 \n", + "5 0.73083 \n", + "6 0.189793 \n", "\n", - " \n", - "DestinationOID 207 245 256 357 \n", - "OriginOID \n", - "1 NaN 2.071802 2.071802 2.671727 \n", - "2 NaN NaN NaN NaN \n", - "3 3.194782 NaN NaN 4.401875 \n", - "4 NaN 2.218085 2.218085 2.442592 \n", - "5 NaN 2.551424 2.551424 2.058579 \n", - "6 NaN 1.734902 1.734902 0.665024 \n", + "DestinationOID 195 216 229 251 295 305 \\\n", + "OriginOID \n", + "1 0.87555 0.87555 \n", + "2 1.261744 \n", + "3 1.599973 1.265384 \n", + "4 1.437629 1.407225 1.407225 \n", + "5 1.056159 1.056159 \n", + "6 0.784955 0.784955 \n", "\n", - "[6 rows x 22 columns]" + "DestinationOID 448 \n", + "OriginOID \n", + "1 1.250166 \n", + "2 \n", + "3 \n", + "4 1.356377 \n", + "5 0.731823 \n", + "6 0.190786 " ] }, - "execution_count": 11, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# user pivot_table\n", - "od_pivot = od_df.pivot_table(index='OriginOID', columns='DestinationOID')\n", + "od_pivot = od_df.pivot_table(index='OriginOID', columns='DestinationOID', values='Total_Distance')\n", "od_pivot" ] }, @@ -1296,21 +1156,24 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "\"\"\" Define a list of colors/styles for routes;\n", " alternatively, use \"'type': 'simple-line', 'style': 'solid'\"\n", "\"\"\"\n", - "allocation_line_symbol = [{'type': 'esriSLS', 'style': 'esriSLSSolid',\n", - " 'color': [237, 17, 189, 100], 'width': 6},\n", - " {'type': 'esriSLS', 'style': 'esriSLSSolid',\n", - " 'color': [30, 139, 235, 90], 'width': 6},\n", - " {'type': 'esriSLS', 'style': 'esriSLSSolid',\n", - " 'color': [66, 240, 43, 80], 'width': 6},\n", - " {'type': 'esriSLS', 'style': 'esriSLSSolid',\n", - " 'color': [240, 234, 67, 70], 'width': 6}]\n", + "allocation_line_symbol = [SimpleLineSymbolEsriSLS(**{'type': 'esriSLS', 'style': 'esriSLSSolid',\n", + " 'color': [237, 17, 189, 100], 'width': 6}),\n", + " SimpleLineSymbolEsriSLS(**{'type': 'esriSLS', 'style': 'esriSLSSolid',\n", + " 'color': [30, 139, 235, 90], 'width': 6}),\n", + " SimpleLineSymbolEsriSLS(**{'type': 'esriSLS', 'style': 'esriSLSSolid',\n", + " 'color': [66, 240, 43, 80], 'width': 6}),\n", + " SimpleLineSymbolEsriSLS(**{'type': 'esriSLS', 'style': 'esriSLSSolid',\n", + " 'color':[240, 234, 67, 70], 'width': 6})]\n", + " \n", + "\n", + "\n", "\n", "names_list = [\"Incident at Esri\",\n", " \"Incident at APT\",\n", @@ -1337,62 +1200,62 @@ } ], "source": [ - "map2 = my_gis.map('Redlands, CA', zoomlevel=13)\n", - "map2.basemap = \"dark-gray\"\n", + "map2 = my_gis.map('Redlands, CA')\n", + "map2.basemap.basemap = \"arcgis-dark-gray\"\n", "map2" ] }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 26, "metadata": {}, "outputs": [], "source": [ - "map2.draw(result1.output_destinations, symbol=hospital_symbol)" + "map2.content.draw(result1.output_destinations, symbol=hospital_symbol)" ] }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 27, "metadata": {}, "outputs": [], "source": [ - "map2.draw(result1.output_origins, symbol=traffic_accident_symbol)" + "map2.content.draw(result1.output_origins, symbol=traffic_accident_symbol)" ] }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 28, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Incident at Esri ---> Location 27\n", - "Incident at Esri ---> Location 28\n", "Incident at Esri ---> Location 31\n", - "Incident at Esri ---> Location 4\n", - "Incident at APT ---> Location 5\n", - "Incident at APT ---> Location 12\n", - "Incident at APT ---> Location 16\n", - "Incident at APT ---> Location 30\n", - "Incident at Walmart ---> Location 23\n", + "Incident at Esri ---> Location 32\n", + "Incident at Esri ---> Location 36\n", + "Incident at Esri ---> Location 6\n", + "Incident at APT ---> Location 10\n", + "Incident at APT ---> Location 17\n", + "Incident at APT ---> Location 23\n", + "Incident at APT ---> Location 21\n", + "Incident at Walmart ---> Location 4\n", + "Incident at Walmart ---> Location 29\n", + "Incident at Walmart ---> Location 5\n", "Incident at Walmart ---> Location 26\n", - "Incident at Walmart ---> Location 6\n", - "Incident at Walmart ---> Location 31\n", - "Incident at High school ---> Location 27\n", - "Incident at High school ---> Location 28\n", "Incident at High school ---> Location 31\n", - "Incident at High school ---> Location 4\n", + "Incident at High school ---> Location 32\n", + "Incident at High school ---> Location 36\n", + "Incident at High school ---> Location 30\n", + "Incident at Bowling ---> Location 36\n", + "Incident at Bowling ---> Location 6\n", "Incident at Bowling ---> Location 31\n", - "Incident at Bowling ---> Location 27\n", - "Incident at Bowling ---> Location 28\n", - "Incident at Bowling ---> Location 4\n", + "Incident at Bowling ---> Location 32\n", + "Incident at Burger ---> Location 36\n", + "Incident at Burger ---> Location 6\n", "Incident at Burger ---> Location 31\n", - "Incident at Burger ---> Location 27\n", - "Incident at Burger ---> Location 28\n", - "Incident at Burger ---> Location 5\n" + "Incident at Burger ---> Location 32\n" ] } ], @@ -1415,10 +1278,10 @@ " count2+=1\n", "\n", " #set popup\n", - " popup={\"title\": \"OD cost matrix {}\".format(route_name), \n", - " \"content\": \"{} minutes\".format(route.attributes['Total_Time'])}\n", + " popup=PopupInfo(**{\"title\": \"OD cost matrix {}\".format(route_name), \n", + " \"content\": \"{} minutes\".format(route.attributes['Total_Time'])})\n", " \n", - " map2.draw(route.geometry, symbol=fill_symbol, popup=popup, attributes={\"title\": route_name})\n", + " map2.content.draw(route.geometry, symbol=fill_symbol, popup=popup, attributes={\"title\": route_name})\n", " time.sleep(2)" ] }, @@ -1431,7 +1294,7 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 29, "metadata": { "scrolled": true }, @@ -1441,16 +1304,16 @@ "text/html": [ "
\n", "
\n", - " \n", + " \n", " \n", " \n", "
\n", "\n", "
\n", - " OD Cost Matrix from incidents to hospitals in San Bernadino County\n", + " OD Cost Matrix from incidents to hospitals in San Bernadino County\n", " \n", - "
OD Cost Matrix from incidents to hospitals in San Bernadino CountyWeb Map by arcgis_python\n", - "
Last Modified: October 08, 2019\n", + "
OD Cost Matrix from incidents to hospitals in San Bernadino County
Web Map by arcgis_python\n", + "
Last Modified: September 19, 2025\n", "
0 comments, 0 views\n", "
\n", "
\n", @@ -1460,7 +1323,7 @@ "" ] }, - "execution_count": 46, + "execution_count": 29, "metadata": {}, "output_type": "execute_result" } @@ -1513,7 +1376,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 30, "metadata": {}, "outputs": [ { @@ -1521,17 +1384,17 @@ "text/html": [ "
\n", " \n", "\n", "
\n", - " USA Major Cities\n", + " USA Major Cities\n", " \n", - "
This layer presents the locations of cities within the United States with populations of approximately 10,000 or greater, all state capitals, and the national capital.Feature Layer Collection by esri_dm\n", - "
Last Modified: August 22, 2019\n", - "
0 comments, 1,920,648 views\n", + "
This layer presents the locations of major cities within the United States with populations of approximately 10,000 or more, state capitals, and the national capital. It includes 2020 U.S. Census class, codes, and population information.
Feature Layer Collection by esri_dm\n", + "
Last Modified: September 09, 2025\n", + "
10 comments, 21655437 views\n", "
\n", "
\n", " " @@ -1540,7 +1403,7 @@ "" ] }, - "execution_count": 6, + "execution_count": 30, "metadata": {}, "output_type": "execute_result" } @@ -1553,7 +1416,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 31, "metadata": {}, "outputs": [ { @@ -1562,7 +1425,7 @@ "arcgis.features.layer.FeatureLayer" ] }, - "execution_count": 7, + "execution_count": 31, "metadata": {}, "output_type": "execute_result" } @@ -1581,7 +1444,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 32, "metadata": {}, "outputs": [], "source": [ @@ -1589,12 +1452,12 @@ " 'Columbus', 'pittsburgh', 'Buffalo']\n", "values = \"'\" + \"', '\".join(stops_cities) + \"'\"\n", "stops_layer = {'url': sample_cities.layers[0].url, \n", - " 'filter': \"ST in ('IL', 'IN', 'OH', 'PA', 'NY') AND NAME IN ({0})\".format(values)}" + " 'filter': \"STATE_ABBR in ('IL', 'IN', 'OH', 'PA', 'NY') AND NAME IN ({0})\".format(values)}" ] }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 33, "metadata": {}, "outputs": [ { @@ -1603,13 +1466,13 @@ " 6 features" ] }, - "execution_count": 9, + "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "end_cities_fset = cities_fl.query(where=\"ST in ('WI', 'IL', 'IN', 'OH', 'PA', 'NY') AND NAME IN ({0})\".format(values), as_df=False)\n", + "end_cities_fset = cities_fl.query(where=\"STATE_ABBR in ('WI', 'IL', 'IN', 'OH', 'PA', 'NY') AND NAME IN ({0})\".format(values), as_df=False)\n", "end_cities_fset" ] }, @@ -1622,17 +1485,17 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 34, "metadata": {}, "outputs": [], "source": [ "start_layer = {'url': sample_cities.layers[0].url, \n", - " 'filter': \"ST in ('MI') AND NAME IN ('Detroit')\"}" + " 'filter': \"STATE_ABBR in ('MI') AND NAME IN ('Detroit')\"}" ] }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 35, "metadata": {}, "outputs": [ { @@ -1641,13 +1504,13 @@ " 1 features" ] }, - "execution_count": 11, + "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "start_cities_fset = cities_fl.query(where=\"ST in ('MI') AND NAME IN ('Detroit')\", as_df=False)\n", + "start_cities_fset = cities_fl.query(where=\"STATE_ABBR in ('MI') AND NAME IN ('Detroit')\", as_df=False)\n", "start_cities_fset" ] }, @@ -1677,50 +1540,50 @@ } ], "source": [ - "map4a = my_gis.map('Detriot, MI', zoomlevel=8)\n", + "map4a = my_gis.map('Detriot, MI')\n", "map4a" ] }, { "cell_type": "code", - "execution_count": 69, + "execution_count": 37, "metadata": {}, "outputs": [], "source": [ - "map4a.clear_graphics()" + "start_symbol = PictureMarkerSymbolEsriPMS(**{\"type\":\"esriPMS\",\n", + " \"url\":\"http://static.arcgis.com/images/Symbols/AtoZ/redA.png\",\n", + " \"contentType\":\"image/png\",\"width\":15.75,\"height\":21.75, \"angle\":0,\"xoffset\":0,\"yoffset\":8.15621})\n", + "\n", + "end_symbol = PictureMarkerSymbolEsriPMS(**{\"type\":\"esriPMS\",\n", + " \"url\":\"http://static.arcgis.com/images/Symbols/AtoZ/greenB.png\",\n", + " \"contentType\":\"image/png\",\"width\":15.75,\"height\":21.75, \"angle\":0,\"xoffset\":0,\"yoffset\":8.15621})" ] }, { "cell_type": "code", - "execution_count": 70, + "execution_count": 44, "metadata": {}, "outputs": [], "source": [ - "start_symbol = {\"angle\":0,\"xoffset\":0,\"yoffset\":8.15625,\"type\":\"esriPMS\",\n", - " \"url\":\"http://static.arcgis.com/images/Symbols/AtoZ/redA.png\",\n", - " \"contentType\":\"image/png\",\"width\":15.75,\"height\":21.75}\n", - "\n", - "end_symbol = {\"angle\":0,\"xoffset\":0,\"yoffset\":8.15625,\"type\":\"esriPMS\",\n", - " \"url\":\"http://static.arcgis.com/images/Symbols/AtoZ/greenB.png\",\n", - " \"contentType\":\"image/png\",\"width\":15.75,\"height\":21.75}" + "map4a.content.draw(start_cities_fset, symbol=start_symbol)" ] }, { "cell_type": "code", - "execution_count": 71, + "execution_count": 45, "metadata": {}, "outputs": [], "source": [ - "map4a.draw(start_cities_fset, symbol=start_symbol)" + "map4a.content.draw(end_cities_fset, symbol=end_symbol)" ] }, { "cell_type": "code", - "execution_count": 72, + "execution_count": 46, "metadata": {}, "outputs": [], "source": [ - "map4a.draw(end_cities_fset, symbol=end_symbol)" + "map4a.zoom_to_layer(end_cities_fset)" ] }, { @@ -1748,21 +1611,23 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 52, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "Network elements with avoid-restrictions are traversed in the output (restriction attribute names: \"Avoid Unpaved Roads\" \"Through Traffic Prohibited\").\n" + "Network elements with avoid-restrictions are traversed in the output (restriction attribute names: \"Avoid Unpaved Roads\" \"Through Traffic Prohibited\").\n", + "{\"cost\": 0.03}\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ - "Wall time: 51.4 s\n" + "CPU times: total: 2.73 s\n", + "Wall time: 54.5 s\n" ] } ], @@ -1773,13 +1638,13 @@ " destinations_layer=stops_layer,\n", " context={'outSR': {\"wkid\": 4326}},\n", " time_of_day=current_time, \n", - " output_name=\"OD Cost Matrix (Oct 2019)\",\n", + " output_name=\"OD Cost Matrix Sep 2025\",\n", " gis=my_gis)" ] }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 53, "metadata": {}, "outputs": [ { @@ -1787,26 +1652,26 @@ "text/html": [ "
\n", "
\n", - " \n", + " \n", " \n", " \n", "
\n", "\n", "
\n", - " OD Cost Matrix (Oct 2019)\n", + " OD_Cost_Matrix_Sep_2025\n", " \n", - "
Feature Layer Collection by arcgis_python\n", - "
Last Modified: October 24, 2019\n", - "
0 comments, 1 views\n", + "

Feature Layer Collection by arcgis_python\n", + "
Last Modified: September 19, 2025\n", + "
0 comments, 0 views\n", "
\n", "
\n", " " ], "text/plain": [ - "" + "" ] }, - "execution_count": 25, + "execution_count": 53, "metadata": {}, "output_type": "execute_result" } @@ -1824,16 +1689,16 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 54, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "'https://services7.arcgis.com/JEwYeAy2cc8qOe3o/arcgis/rest/services/OD Cost Matrix (Oct 2019)/FeatureServer/0'" + "'https://services7.arcgis.com/JEwYeAy2cc8qOe3o/arcgis/rest/services/OD_Cost_Matrix_Sep_2025/FeatureServer/0'" ] }, - "execution_count": 26, + "execution_count": 54, "metadata": {}, "output_type": "execute_result" } @@ -1845,7 +1710,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 55, "metadata": { "scrolled": true }, @@ -1884,62 +1749,62 @@ " \n", " 0\n", " Route 1 - Detroit - Chicago\n", - " 1533\n", - " 63\n", - " 275.444212\n", - " 2019-10-24 19:56:17\n", - " 2019-10-24 23:17:48\n", - " 261.514763\n", + " 2039\n", + " 1348\n", + " 277.028672\n", + " 2025-09-20 02:55:43.552999973\n", + " 2025-09-20 06:08:06.155999899\n", + " 252.376712\n", " \n", " \n", " 1\n", " Route 2 - Detroit - Columbus\n", - " 1533\n", - " 256\n", - " 326.222952\n", - " 2019-10-24 19:56:17\n", - " 2019-10-25 01:06:55\n", - " 310.638586\n", + " 2039\n", + " 1541\n", + " 313.514949\n", + " 2025-09-20 02:55:43.552999973\n", + " 2025-09-20 08:06:27.578000069\n", + " 310.733747\n", " \n", " \n", " 2\n", " Route 3 - Detroit - Buffalo\n", - " 1533\n", - " 2075\n", - " 259.663696\n", - " 2019-10-24 19:56:17\n", - " 2019-10-25 00:28:21\n", - " 272.074868\n", + " 2039\n", + " 2614\n", + " 257.339779\n", + " 2025-09-20 02:55:43.552999973\n", + " 2025-09-20 07:15:28.631000042\n", + " 259.751292\n", " \n", " \n", " 3\n", " Route 4 - Detroit - Cleveland\n", - " 1533\n", - " 2385\n", - " 168.146931\n", - " 2019-10-24 19:56:17\n", - " 2019-10-24 22:41:58\n", - " 165.690078\n", + " 2039\n", + " 2959\n", + " 168.049155\n", + " 2025-09-20 02:55:43.552999973\n", + " 2025-09-20 05:34:14.578999996\n", + " 158.517101\n", " \n", " \n", " 4\n", " Route 5 - Detroit - Columbus\n", - " 1533\n", - " 256\n", - " 199.968721\n", - " 2019-10-24 19:56:17\n", - " 2019-10-24 23:18:16\n", - " 201.984500\n", + " 2039\n", + " 2961\n", + " 203.151608\n", + " 2025-09-20 02:55:43.552999973\n", + " 2025-09-20 06:09:48.921999931\n", + " 194.089487\n", " \n", " \n", " 5\n", " Route 6 - Detroit - Pittsburgh\n", - " 1533\n", - " 2989\n", - " 285.264445\n", - " 2019-10-24 19:56:17\n", - " 2019-10-25 00:27:18\n", - " 271.010365\n", + " 2039\n", + " 3267\n", + " 285.136397\n", + " 2025-09-20 02:55:43.552999973\n", + " 2025-09-20 07:18:21.240000010\n", + " 262.628116\n", " \n", " \n", "\n", @@ -1947,23 +1812,23 @@ ], "text/plain": [ " RouteName OriginOID DestinationOID Total_Miles \\\n", - "0 Route 1 - Detroit - Chicago 1533 63 275.444212 \n", - "1 Route 2 - Detroit - Columbus 1533 256 326.222952 \n", - "2 Route 3 - Detroit - Buffalo 1533 2075 259.663696 \n", - "3 Route 4 - Detroit - Cleveland 1533 2385 168.146931 \n", - "4 Route 5 - Detroit - Columbus 1533 256 199.968721 \n", - "5 Route 6 - Detroit - Pittsburgh 1533 2989 285.264445 \n", + "0 Route 1 - Detroit - Chicago 2039 1348 277.028672 \n", + "1 Route 2 - Detroit - Columbus 2039 1541 313.514949 \n", + "2 Route 3 - Detroit - Buffalo 2039 2614 257.339779 \n", + "3 Route 4 - Detroit - Cleveland 2039 2959 168.049155 \n", + "4 Route 5 - Detroit - Columbus 2039 2961 203.151608 \n", + "5 Route 6 - Detroit - Pittsburgh 2039 3267 285.136397 \n", "\n", - " StartTime EndTime Total_Minutes \n", - "0 2019-10-24 19:56:17 2019-10-24 23:17:48 261.514763 \n", - "1 2019-10-24 19:56:17 2019-10-25 01:06:55 310.638586 \n", - "2 2019-10-24 19:56:17 2019-10-25 00:28:21 272.074868 \n", - "3 2019-10-24 19:56:17 2019-10-24 22:41:58 165.690078 \n", - "4 2019-10-24 19:56:17 2019-10-24 23:18:16 201.984500 \n", - "5 2019-10-24 19:56:17 2019-10-25 00:27:18 271.010365 " + " StartTime EndTime Total_Minutes \n", + "0 2025-09-20 02:55:43.552999973 2025-09-20 06:08:06.155999899 252.376712 \n", + "1 2025-09-20 02:55:43.552999973 2025-09-20 08:06:27.578000069 310.733747 \n", + "2 2025-09-20 02:55:43.552999973 2025-09-20 07:15:28.631000042 259.751292 \n", + "3 2025-09-20 02:55:43.552999973 2025-09-20 05:34:14.578999996 158.517101 \n", + "4 2025-09-20 02:55:43.552999973 2025-09-20 06:09:48.921999931 194.089487 \n", + "5 2025-09-20 02:55:43.552999973 2025-09-20 07:18:21.240000010 262.628116 " ] }, - "execution_count": 27, + "execution_count": 55, "metadata": {}, "output_type": "execute_result" } @@ -1985,7 +1850,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 56, "metadata": {}, "outputs": [ { @@ -2013,21 +1878,23 @@ " \n", " \n", " \n", - " Total_Miles\n", - " Total_Minutes\n", + " Total_Miles\n", + " Total_Minutes\n", " \n", " \n", " DestinationOID\n", - " 63\n", - " 256\n", - " 2075\n", - " 2385\n", - " 2989\n", - " 63\n", - " 256\n", - " 2075\n", - " 2385\n", - " 2989\n", + " 1348\n", + " 1541\n", + " 2614\n", + " 2959\n", + " 2961\n", + " 3267\n", + " 1348\n", + " 1541\n", + " 2614\n", + " 2959\n", + " 2961\n", + " 3267\n", " \n", " \n", " OriginOID\n", @@ -2041,21 +1908,25 @@ " \n", " \n", " \n", + " \n", + " \n", " \n", " \n", " \n", " \n", - " 1533\n", - " 275.444212\n", - " 263.095837\n", - " 259.663696\n", - " 168.146931\n", - " 285.264445\n", - " 261.514763\n", - " 256.311543\n", - " 272.074868\n", - " 165.690078\n", - " 271.010365\n", + " 2039\n", + " 277.028672\n", + " 313.514949\n", + " 257.339779\n", + " 168.049155\n", + " 203.151608\n", + " 285.136397\n", + " 252.376712\n", + " 310.733747\n", + " 259.751292\n", + " 158.517101\n", + " 194.089487\n", + " 262.628116\n", " \n", " \n", "\n", @@ -2063,24 +1934,29 @@ ], "text/plain": [ " Total_Miles \\\n", - "DestinationOID 63 256 2075 2385 2989 \n", + "DestinationOID 1348 1541 2614 2959 2961 \n", "OriginOID \n", - "1533 275.444212 263.095837 259.663696 168.146931 285.264445 \n", + "2039 277.028672 313.514949 257.339779 168.049155 203.151608 \n", + "\n", + " Total_Minutes \\\n", + "DestinationOID 3267 1348 1541 2614 2959 \n", + "OriginOID \n", + "2039 285.136397 252.376712 310.733747 259.751292 158.517101 \n", "\n", - " Total_Minutes \n", - "DestinationOID 63 256 2075 2385 2989 \n", - "OriginOID \n", - "1533 261.514763 256.311543 272.074868 165.690078 271.010365 " + " \n", + "DestinationOID 2961 3267 \n", + "OriginOID \n", + "2039 194.089487 262.628116 " ] }, - "execution_count": 28, + "execution_count": 56, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# user pivot_table\n", - "od_pivot = od_df2.pivot_table(index='OriginOID', columns='DestinationOID')\n", + "od_pivot = od_df2.pivot_table(index='OriginOID', columns='DestinationOID', values=['Total_Miles', 'Total_Minutes'])\n", "od_pivot" ] }, @@ -2093,11 +1969,11 @@ }, { "cell_type": "code", - "execution_count": 73, + "execution_count": 57, "metadata": {}, "outputs": [], "source": [ - "map4a.add_layer(result2)" + "map4a.content.add(result2)" ] }, { @@ -2118,21 +1994,23 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 58, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "Network elements with avoid-restrictions are traversed in the output (restriction attribute names: \"Avoid Unpaved Roads\" \"Through Traffic Prohibited\").\n" + "Network elements with avoid-restrictions are traversed in the output (restriction attribute names: \"Avoid Unpaved Roads\" \"Through Traffic Prohibited\").\n", + "{\"cost\": 0.03}\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ - "Wall time: 37.9 s\n" + "CPU times: total: 156 ms\n", + "Wall time: 30.8 s\n" ] } ], @@ -2148,10 +2026,8 @@ }, { "cell_type": "code", - "execution_count": 13, - "metadata": { - "scrolled": true - }, + "execution_count": 59, + "metadata": {}, "outputs": [ { "data": { @@ -2162,7 +2038,7 @@ " 'route_layer_items': ''}" ] }, - "execution_count": 13, + "execution_count": 59, "metadata": {}, "output_type": "execute_result" } @@ -2189,7 +2065,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 60, "metadata": {}, "outputs": [ { @@ -2226,62 +2102,62 @@ " \n", " 0\n", " Route 1 - Detroit - Chicago\n", - " 1533\n", - " 63\n", - " 275.444212\n", - " 2019-10-31 23:11:30\n", - " 2019-11-01 02:24:14.476999998\n", - " 252.741290\n", + " 2039\n", + " 1348\n", + " 277.028672\n", + " 2025-09-20 02:55:43.552999\n", + " 2025-09-20 06:08:06.155999\n", + " 252.376712\n", " \n", " \n", " 1\n", " Route 2 - Detroit - Columbus\n", - " 1533\n", - " 256\n", - " 322.114356\n", - " 2019-10-31 23:11:30\n", - " 2019-11-01 04:15:55.417999983\n", - " 304.423627\n", + " 2039\n", + " 1541\n", + " 313.514949\n", + " 2025-09-20 02:55:43.552999\n", + " 2025-09-20 08:06:27.578000\n", + " 310.733747\n", " \n", " \n", " 2\n", " Route 3 - Detroit - Buffalo\n", - " 1533\n", - " 2075\n", - " 259.663696\n", - " 2019-10-31 23:11:30\n", - " 2019-11-01 03:38:20.026000023\n", - " 266.833772\n", + " 2039\n", + " 2614\n", + " 257.339779\n", + " 2025-09-20 02:55:43.552999\n", + " 2025-09-20 07:15:28.631000\n", + " 259.751292\n", " \n", " \n", " 3\n", " Route 4 - Detroit - Cleveland\n", - " 1533\n", - " 2385\n", - " 168.146931\n", - " 2019-10-31 23:11:30\n", - " 2019-11-01 01:49:56.456000090\n", - " 158.440937\n", + " 2039\n", + " 2959\n", + " 168.049155\n", + " 2025-09-20 02:55:43.552999\n", + " 2025-09-20 05:34:14.578999\n", + " 158.517101\n", " \n", " \n", " 4\n", " Route 5 - Detroit - Columbus\n", - " 1533\n", - " 256\n", - " 199.968721\n", - " 2019-10-31 23:11:30\n", - " 2019-11-01 02:25:21.056999922\n", - " 193.850944\n", + " 2039\n", + " 2961\n", + " 203.151608\n", + " 2025-09-20 02:55:43.552999\n", + " 2025-09-20 06:09:48.921999\n", + " 194.089487\n", " \n", " \n", " 5\n", " Route 6 - Detroit - Pittsburgh\n", - " 1533\n", - " 2989\n", - " 285.264445\n", - " 2019-10-31 23:11:30\n", - " 2019-11-01 03:36:11.479000092\n", - " 264.691321\n", + " 2039\n", + " 3267\n", + " 285.136397\n", + " 2025-09-20 02:55:43.552999\n", + " 2025-09-20 07:18:21.240000\n", + " 262.628116\n", " \n", " \n", "\n", @@ -2289,23 +2165,23 @@ ], "text/plain": [ " RouteName OriginOID DestinationOID Total_Miles \\\n", - "0 Route 1 - Detroit - Chicago 1533 63 275.444212 \n", - "1 Route 2 - Detroit - Columbus 1533 256 322.114356 \n", - "2 Route 3 - Detroit - Buffalo 1533 2075 259.663696 \n", - "3 Route 4 - Detroit - Cleveland 1533 2385 168.146931 \n", - "4 Route 5 - Detroit - Columbus 1533 256 199.968721 \n", - "5 Route 6 - Detroit - Pittsburgh 1533 2989 285.264445 \n", + "0 Route 1 - Detroit - Chicago 2039 1348 277.028672 \n", + "1 Route 2 - Detroit - Columbus 2039 1541 313.514949 \n", + "2 Route 3 - Detroit - Buffalo 2039 2614 257.339779 \n", + "3 Route 4 - Detroit - Cleveland 2039 2959 168.049155 \n", + "4 Route 5 - Detroit - Columbus 2039 2961 203.151608 \n", + "5 Route 6 - Detroit - Pittsburgh 2039 3267 285.136397 \n", "\n", - " StartTime EndTime Total_Minutes \n", - "0 2019-10-31 23:11:30 2019-11-01 02:24:14.476999998 252.741290 \n", - "1 2019-10-31 23:11:30 2019-11-01 04:15:55.417999983 304.423627 \n", - "2 2019-10-31 23:11:30 2019-11-01 03:38:20.026000023 266.833772 \n", - "3 2019-10-31 23:11:30 2019-11-01 01:49:56.456000090 158.440937 \n", - "4 2019-10-31 23:11:30 2019-11-01 02:25:21.056999922 193.850944 \n", - "5 2019-10-31 23:11:30 2019-11-01 03:36:11.479000092 264.691321 " + " StartTime EndTime Total_Minutes \n", + "0 2025-09-20 02:55:43.552999 2025-09-20 06:08:06.155999 252.376712 \n", + "1 2025-09-20 02:55:43.552999 2025-09-20 08:06:27.578000 310.733747 \n", + "2 2025-09-20 02:55:43.552999 2025-09-20 07:15:28.631000 259.751292 \n", + "3 2025-09-20 02:55:43.552999 2025-09-20 05:34:14.578999 158.517101 \n", + "4 2025-09-20 02:55:43.552999 2025-09-20 06:09:48.921999 194.089487 \n", + "5 2025-09-20 02:55:43.552999 2025-09-20 07:18:21.240000 262.628116 " ] }, - "execution_count": 14, + "execution_count": 60, "metadata": {}, "output_type": "execute_result" } @@ -2341,24 +2217,25 @@ } ], "source": [ - "map4b = my_gis.map('Detroit, MI', zoomlevel=8)\n", - "map4b.basemap = 'dark-gray'\n", + "map4b = my_gis.map('Detroit, MI')\n", + "map4b.basemap.basemap = 'arcgis-dark-gray'\n", "map4b" ] }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 79, "metadata": {}, "outputs": [], "source": [ - "map4b.draw(start_cities_fset, symbol=start_symbol)\n", - "map4b.draw(end_cities_fset, symbol=end_symbol)" + "map4b.content.draw(start_cities_fset, symbol=start_symbol)\n", + "map4b.content.draw(end_cities_fset, symbol=end_symbol)\n", + "map4b.zoom_to_layer(end_cities_fset)" ] }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 80, "metadata": {}, "outputs": [], "source": [ @@ -2379,35 +2256,33 @@ " count2+=1\n", "\n", " #set popup\n", - " popup={\"title\": \"OD cost matrix {}\".format(route.attributes['RouteName']), \n", - " \"content\": \"{} minutes\".format(route.attributes['Total_Minutes'])}\n", + " popup=PopupInfo(**{\"title\": \"OD cost matrix {}\".format(route.attributes['RouteName']), \n", + " \"content\": \"{} minutes\".format(route.attributes['Total_Minutes'])})\n", " \n", - " map4b.draw(route.geometry, symbol=fill_symbol, popup=popup, attributes={\"title\":route.attributes['RouteName']})\n", + " map4b.content.draw(route.geometry, symbol=fill_symbol, popup=popup, attributes={\"title\":route.attributes['RouteName']})\n", " time.sleep(2)" ] }, { "cell_type": "code", "execution_count": 81, - "metadata": { - "scrolled": true - }, + "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "
\n", - " \n", + " \n", " \n", " \n", "
\n", "\n", "
\n", - " OD Cost matrix from Detriot to nearby major cities\n", + " OD Cost matrix from Detriot to nearby major cities\n", " \n", - "
OD Cost Matrix from incidents to hospitals in San Bernadino CountyWeb Map by arcgis_python\n", - "
Last Modified: October 08, 2019\n", + "
OD Cost Matrix from incidents to hospitals in San Bernadino County
Web Map by arcgis_python\n", + "
Last Modified: September 19, 2025\n", "
0 comments, 0 views\n", "
\n", "
\n", @@ -2479,7 +2354,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.11" + "version": "3.12.11" }, "toc": { "base_numbering": 1, @@ -2525,5 +2400,5 @@ } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 }