diff --git a/samples/04_gis_analysts_data_scientists/safe_streets_to_schools.ipynb b/samples/04_gis_analysts_data_scientists/safe_streets_to_schools.ipynb index 28b081571..22ee07707 100644 --- a/samples/04_gis_analysts_data_scientists/safe_streets_to_schools.ipynb +++ b/samples/04_gis_analysts_data_scientists/safe_streets_to_schools.ipynb @@ -88,7 +88,7 @@ "\n", "from arcgis.gis import GIS\n", "from arcgis.features.analyze_patterns import calculate_density, find_hot_spots\n", - "from arcgis.mapping.symbol import create_symbol\n", + "from arcgis.map import renderers, symbols\n", "from arcgis.features.use_proximity import create_drive_time_areas\n", "from arcgis.features.summarize_data import summarize_within" ] @@ -104,7 +104,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Connect to the GIS via an existing profile or creating a new connection by e.g. gis = GIS(\"https://www.arcgis.com\", \"arcgis_python\", \"P@ssword123\")" + "Connect to the GIS via an existing profile." ] }, { @@ -113,7 +113,7 @@ "metadata": {}, "outputs": [], "source": [ - "gis = GIS('home')" + "gis = GIS(profile='your_online_profile')" ] }, { @@ -149,17 +149,17 @@ "text/html": [ "
\n", "
\n", - " \n", + " \n", " \n", " \n", "
\n", "\n", "
\n", - " Traffic Collisions\n", + " Traffic Collisions\n", " \n", - "
Traffic collisions in Pasadena, California, since 2008.Feature Layer Collection by api_data_owner\n", - "
Last Modified: April 26, 2019\n", - "
0 comments, 24 views\n", + "
Traffic collisions in Pasadena, California, since 2008.
Feature Layer Collection by api_data_owner\n", + "
Last Modified: May 20, 2024\n", + "
0 comments, 7733 views\n", "
\n", "
\n", " " @@ -224,7 +224,7 @@ ], "source": [ "for lyr in item.layers:\n", - " print(lyr.properties.name)" + " print(lyr.properties['name'])" ] }, { @@ -245,25 +245,26 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 8, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "m1 = gis.map('Pasadena, California', 13)\n", + "m1 = gis.map('Pasadena, California')\n", + "m1.basemap.basemap = 'topo-vector'\n", "m1" ] }, @@ -280,28 +281,36 @@ "metadata": {}, "outputs": [], "source": [ - "m1.add_layer(collisions)" + "m1.content.add(collisions)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The `zoom` level for a map object is set after the map is rendered. We set the desired zoom level for this map and also display the legend on the map." ] }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ - "m1.legend = True" + "m1.zoom = 13\n", + "m1.legend.enabled = True" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "As the layer does not only contain information about location, but it also has other attributes that cannot be seen on map. So using `query` method, we can query the features on a feature layer. `sdf` property of `featureSet` class is a powerful tool to visualize all the features as Pandas `DataFrame`." + "The `collisions` layer does not only contain information about location, but it also has other attributes that cannot be seen on the map. So using `query` method, we can query the features of a feature layer. The `sdf` property of `featureSet` class is a powerful tool to visualize all the features as a Pandas `DataFrame`." ] }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -321,7 +330,7 @@ " dtype='object')" ] }, - "execution_count": 11, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -332,19 +341,23 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "array(['Other Motor Vehicle', 'Pedestrian', 'Fixed Object', 'Bicycle',\n", - " 'Parked Motor Vehicle', 'Other Object',\n", - " 'Motor Vehicle on Other Roadway', 'Non-Collision', 'Train',\n", - " 'Animal', 'Not Stated', 'Other'], dtype=object)" + "\n", + "[ 'Other Motor Vehicle', 'Pedestrian',\n", + " 'Fixed Object', 'Bicycle',\n", + " 'Parked Motor Vehicle', 'Other Object',\n", + " 'Motor Vehicle on Other Roadway', 'Non-Collision',\n", + " 'Train', 'Animal',\n", + " 'Not Stated', 'Other']\n", + "Length: 12, dtype: string" ] }, - "execution_count": 12, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -362,7 +375,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -384,12 +397,12 @@ "\n", "Different ways to find patterns in data includes point clustering, heat maps, hot spot analysis and [calculate density](https://pro.arcgis.com/en/pro-app/tool-reference/spatial-analyst/how-kernel-density-works.htm). These methods reveal where accidents are happening at abnormal rates.\n", "\n", - "First, we will apply `calculate_density` tool to get better insights on data." + "First, we will apply `calculate_density` tool to get better insights of this data." ] }, { "cell_type": "code", - "execution_count": 14, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -399,7 +412,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -407,26 +420,26 @@ "text/html": [ "
\n", "
\n", - " \n", + " \n", " \n", " \n", "
\n", "\n", "
\n", - " density_of_incidents660540\n", + " density_of_incidents238558\n", " \n", - "
Feature Layer Collection by arcgis_python\n", - "
Last Modified: September 13, 2019\n", + "

Feature Layer Collection by MMajumdar_geosaurus\n", + "
Last Modified: December 03, 2024\n", "
0 comments, 0 views\n", "
\n", "
\n", " " ], "text/plain": [ - "" + "" ] }, - "execution_count": 15, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -437,27 +450,26 @@ }, { "cell_type": "code", - "execution_count": 16, - "metadata": { - "scrolled": false - }, + "execution_count": 23, + "metadata": {}, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 16, + "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "m2 = gis.map('Pasadena, California', 13)\n", + "m2 = gis.map('Pasadena, California')\n", + "m2.basemap.basemap = 'topo-vector'\n", "m2" ] }, @@ -465,25 +477,34 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Areas with large number of accidents show up as more densely colored as compared to other areas." + "Areas with large number of accidents show up more densely colored as compared to other areas." ] }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 19, "metadata": {}, "outputs": [], "source": [ - "m2.add_layer(collision_density)" + "m2.content.add(collision_density)" ] }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 20, "metadata": {}, "outputs": [], "source": [ - "m2.legend = True" + "m2.zoom_to_layer(collision_density)" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [], + "source": [ + "m2.legend.enabled = True" ] }, { @@ -495,7 +516,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -506,36 +527,34 @@ }, { "cell_type": "code", - "execution_count": 20, - "metadata": { - "scrolled": true - }, + "execution_count": 14, + "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "
\n", - " \n", + " \n", " \n", " \n", "
\n", "\n", "
\n", - " collision_hexagon_hot_spots539052\n", + " collision_hexagon_hot_spots995425\n", " \n", - "
Feature Layer Collection by arcgis_python\n", - "
Last Modified: September 13, 2019\n", + "

Feature Layer Collection by MMajumdar_geosaurus\n", + "
Last Modified: December 03, 2024\n", "
0 comments, 0 views\n", "
\n", "
\n", " " ], "text/plain": [ - "" + "" ] }, - "execution_count": 20, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -546,27 +565,26 @@ }, { "cell_type": "code", - "execution_count": 21, - "metadata": { - "scrolled": false - }, + "execution_count": 35, + "metadata": {}, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 21, + "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "m3 = gis.map('Pasadena, California', 13)\n", + "m3 = gis.map('Pasadena, California')\n", + "m3.basemap.basemap = 'arcgis-dark-gray'\n", "m3" ] }, @@ -579,20 +597,29 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 32, "metadata": {}, "outputs": [], "source": [ - "m3.add_layer(collision_hot_spots)" + "m3.content.add(collision_hot_spots)" ] }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 33, + "metadata": {}, + "outputs": [], + "source": [ + "m3.zoom_to_layer(collision_hot_spots)" + ] + }, + { + "cell_type": "code", + "execution_count": 34, "metadata": {}, "outputs": [], "source": [ - "m3.legend = True" + "m3.legend.enabled = True" ] }, { @@ -606,32 +633,31 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "We will use `HeatmapRenderer` to display generalized point pattern locations." + "We will use the Smart Mapping `HeatmapRenderer` to display generalized point pattern locations." ] }, { "cell_type": "code", - "execution_count": 24, - "metadata": { - "scrolled": false - }, + "execution_count": 36, + "metadata": {}, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 24, + "execution_count": 36, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "m4 = gis.map('Pasadena, California', 13)\n", + "m4 = gis.map('Pasadena, California')\n", + "m4.basemap.basemap = 'topo-vector'\n", "m4" ] }, @@ -644,23 +670,30 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 32, "metadata": {}, "outputs": [], "source": [ - "m4.add_layer({\"type\": \"FeatureLayer\",\n", - " \"url\": collisions.url, \n", - " \"renderer\": \"HeatmapRenderer\",\n", - " \"opacity\": 0.75})" + "m4.content.add(collisions, options={\"opacity\": 0.8})" ] }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 33, "metadata": {}, "outputs": [], "source": [ - "m4.legend = True" + "sm_manager = m4.content.renderer(0).smart_mapping()\n", + "sm_manager.heatmap_renderer()" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [], + "source": [ + "m4.legend.enabled = True" ] }, { @@ -686,7 +719,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 15, "metadata": { "scrolled": true }, @@ -697,7 +730,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 16, "metadata": {}, "outputs": [], "source": [ @@ -706,7 +739,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 17, "metadata": {}, "outputs": [ { @@ -755,7 +788,7 @@ " \n", " \n", " \n", - " 1\n", + " 1\n", " 2\n", " 10407211603116\n", " Other Hazardous Movement\n", @@ -776,10 +809,10 @@ " Clear\n", " 6517494\n", " 1875480\n", - " {'x': -13151952.7988482, 'y': 4048399.24990493...\n", + " {\"x\": -13151952.7988482, \"y\": 4048399.24990493...\n", " \n", " \n", - " 11\n", + " 11\n", " 12\n", " 10409075901001\n", " Auto R/W Violation\n", @@ -800,10 +833,10 @@ " Clear\n", " 6516612\n", " 1876820\n", - " {'x': -13152278.024718883, 'y': 4048894.055900...\n", + " {\"x\": -13152278.024718883, \"y\": 4048894.055900...\n", " \n", " \n", - " 26\n", + " 26\n", " 27\n", " 10411184701852\n", " Unsafe Speed\n", @@ -824,10 +857,10 @@ " Clear\n", " 6511556\n", " 1881787\n", - " {'x': -13154141.264326861, 'y': 4050727.197689...\n", + " {\"x\": -13154141.264326861, \"y\": 4050727.197689...\n", " \n", " \n", - " 29\n", + " 29\n", " 30\n", " 10412131002035\n", " Ped R/W Violation\n", @@ -848,10 +881,10 @@ " Clear\n", " 6517482\n", " 1879853\n", - " {'x': -13151959.551540626, 'y': 4050015.650237...\n", + " {\"x\": -13151959.551540626, \"y\": 4050015.650237...\n", " \n", " \n", - " 58\n", + " 58\n", " 59\n", " 10418170105652\n", " Other Hazardous Movement\n", @@ -872,11 +905,11 @@ " Clear\n", " 6525309.99742721\n", " 1885626.50722028\n", - " {'x': -13149081.688380858, 'y': 4052153.917797...\n", + " {\"x\": -13149081.688380858, \"y\": 4052153.917797...\n", " \n", " \n", "\n", - "

5 rows × 57 columns

\n", + "

5 rows × 57 columns

\n", "" ], "text/plain": [ @@ -909,16 +942,16 @@ "58 22517 Clear 6525309.99742721 1885626.50722028 \n", "\n", " SHAPE \n", - "1 {'x': -13151952.7988482, 'y': 4048399.24990493... \n", - "11 {'x': -13152278.024718883, 'y': 4048894.055900... \n", - "26 {'x': -13154141.264326861, 'y': 4050727.197689... \n", - "29 {'x': -13151959.551540626, 'y': 4050015.650237... \n", - "58 {'x': -13149081.688380858, 'y': 4052153.917797... \n", + "1 {\"x\": -13151952.7988482, \"y\": 4048399.24990493... \n", + "11 {\"x\": -13152278.024718883, \"y\": 4048894.055900... \n", + "26 {\"x\": -13154141.264326861, \"y\": 4050727.197689... \n", + "29 {\"x\": -13151959.551540626, \"y\": 4050015.650237... \n", + "58 {\"x\": -13149081.688380858, \"y\": 4052153.917797... \n", "\n", "[5 rows x 57 columns]" ] }, - "execution_count": 29, + "execution_count": 17, "metadata": {}, "output_type": "execute_result" } @@ -949,7 +982,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 18, "metadata": {}, "outputs": [], "source": [ @@ -969,7 +1002,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 19, "metadata": {}, "outputs": [ { @@ -978,7 +1011,7 @@ "\"\\nvar acc_type = $feature.InvWith;\\nvar fatal = $feature.Nokilled;\\nvar injured = $feature.NoInjured;\\nvar result = When( \\n acc_type == 'Pedestrian' && fatal == '1' , 'PedestrianFatality',\\n acc_type == 'Pedestrian' && injured != '0', 'PedestrianInjury',\\n acc_type == 'Bicycle' && injured != '0', 'BicycleInjury',\\n acc_type == 'Bicycle' && fatal == '1', 'BicycleFatality',\\n 'null');\\nreturn result;\\n\"" ] }, - "execution_count": 31, + "execution_count": 19, "metadata": {}, "output_type": "execute_result" } @@ -996,18 +1029,21 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 20, "metadata": {}, "outputs": [], "source": [ "def get_symbol(color, size):\n", - " return create_symbol(geometry_type='point',\n", - " symbol_type='simple',\n", - " symbol_style='o',\n", - " colors=color,\n", - " marker_size=size,\n", - " outline_style='s',\n", - " outline_color=[153,153,153,255], line_width=0.375)\n", + " outline = symbols.SimpleLineSymbolEsriSLS(\n", + " color=[153,153,153,255],\n", + " style=symbols.SimpleLineSymbolStyle.esri_sls_solid,\n", + " width=0.375)\n", + " symbol = symbols.SimpleMarkerSymbolEsriSMS(\n", + " color=color,\n", + " style = symbols.SimpleMarkerSymbolStyle.esri_sms_circle,\n", + " size=size,\n", + " outline=outline)\n", + " return symbol\n", "\n", "\n", "def get_unique_values(color_list, values):\n", @@ -1016,37 +1052,73 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 79, "metadata": {}, "outputs": [], "source": [ - "color_list = [ [255, 0, 0, 255], [0, 255, 0, 255], [0, 0, 255, 255], [0 , 255, 255, 255] ] \n", + "color_list = [ [255, 0, 0, 255], [0, 255, 0, 255], [255, 172, 28, 255], [0 , 255, 255, 255] ] \n", "values = ['PedestrianFatality', 'PedestrianInjury', 'BicycleInjury', 'BicycleFatality']\n", "sizes = [15, 3, 3, 15]\n", - "uv = get_unique_values(color_list, values)" + "unique_value_list = get_unique_values(color_list, values)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Let us take a look at the `unique_value_list` list that we built to generate unique values for the collision types. We will use this to build our custom `UniqueValueRenderer`." ] }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 80, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[{'label': 'PedestrianFatality', 'symbol': SimpleMarkerSymbolEsriSMS(angle=None, color=[255, 0, 0, 255], outline=SimpleLineSymbolEsriSLS(color=[153, 153, 153, 255], marker=None, style='esriSLSSolid', type='esriSLS', width=0.375), size=15, style='esriSMSCircle', type='esriSMS', xoffset=None, yoffset=None), 'value': 'PedestrianFatality'}, {'label': 'PedestrianInjury', 'symbol': SimpleMarkerSymbolEsriSMS(angle=None, color=[0, 255, 0, 255], outline=SimpleLineSymbolEsriSLS(color=[153, 153, 153, 255], marker=None, style='esriSLSSolid', type='esriSLS', width=0.375), size=3, style='esriSMSCircle', type='esriSMS', xoffset=None, yoffset=None), 'value': 'PedestrianInjury'}, {'label': 'BicycleInjury', 'symbol': SimpleMarkerSymbolEsriSMS(angle=None, color=[255, 172, 28, 255], outline=SimpleLineSymbolEsriSLS(color=[153, 153, 153, 255], marker=None, style='esriSLSSolid', type='esriSLS', width=0.375), size=3, style='esriSMSCircle', type='esriSMS', xoffset=None, yoffset=None), 'value': 'BicycleInjury'}, {'label': 'BicycleFatality', 'symbol': SimpleMarkerSymbolEsriSMS(angle=None, color=[0, 255, 255, 255], outline=SimpleLineSymbolEsriSLS(color=[153, 153, 153, 255], marker=None, style='esriSLSSolid', type='esriSLS', width=0.375), size=15, style='esriSMSCircle', type='esriSMS', xoffset=None, yoffset=None), 'value': 'BicycleFatality'}]\n" + ] + } + ], + "source": [ + "print(unique_value_list)" + ] + }, + { + "cell_type": "code", + "execution_count": 81, + "metadata": {}, + "outputs": [], + "source": [ + "accident_renderer = renderers.UniqueValueRenderer(\n", + " valueExpression = arcade_expression,\n", + " unique_value_infos = unique_value_list)" + ] + }, + { + "cell_type": "code", + "execution_count": 88, "metadata": {}, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 34, + "execution_count": 88, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "m5 = gis.map('Pasadena, California', 13)\n", + "m5 = gis.map('Pasadena, California')\n", + "m5.basemap.basemap = 'topo-vector'\n", "m5" ] }, @@ -1059,108 +1131,79 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 86, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 35, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "filtered_df.spatial.plot(map_widget=m5,\n", - " renderer_type='u-a',\n", - " unique_values=uv,\n", - " arcade_expression=arcade_expression)" + "m5.content.add(filtered_df, drawing_info={\"renderer\": accident_renderer})" ] }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 87, "metadata": {}, "outputs": [], "source": [ - "m5.legend = True" + "m5.zoom = 13\n", + "m5.legend.enabled = True" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "The points are competing with the the basemap colors. So let's change the basemap to dark-gray." + "The points are blending in with the the basemap colors. So let's change the basemap to dark-gray." ] }, { "cell_type": "code", - "execution_count": 37, - "metadata": { - "scrolled": false - }, + "execution_count": 89, + "metadata": {}, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 37, + "execution_count": 89, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "m6 = gis.map('Pasadena, California', 13)\n", + "m6 = gis.map('Pasadena, California')\n", + "m6.basemap.basemap = 'arcgis-dark-gray'\n", "m6" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": 83, "metadata": {}, + "outputs": [], "source": [ - "Now, the accidents stand out because the points are not competing with the basemap colors. There is also a clear distinction between bicycle and pedestrian accidents." + "m6.content.add(filtered_df, drawing_info={\"renderer\": accident_renderer})" ] }, { "cell_type": "code", - "execution_count": 38, - "metadata": { - "scrolled": true - }, + "execution_count": 84, + "metadata": {}, "outputs": [], "source": [ - "m6.basemap = 'dark-gray'" + "m6.zoom = 13\n", + "m6.legend.enabled = True" ] }, { - "cell_type": "code", - "execution_count": 39, + "cell_type": "markdown", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 39, - "metadata": {}, - "output_type": "execute_result" - } - ], "source": [ - "filtered_df.spatial.plot(map_widget=m6,\n", - " renderer_type='u-a',\n", - " unique_values=uv,\n", - " arcade_expression=arcade_expression)" + "Now, the accidents stand out because the points are not competing with the basemap colors. There is also a clear distinction between bicycle and pedestrian accidents." ] }, { @@ -1179,16 +1222,16 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 90, "metadata": {}, "outputs": [], "source": [ - "schools = gis.content.search('PUSD schools, owner:Learn_ArcGIS', 'Feature Layer',outside_org=True)[0]" + "schools = gis.content.search('PUSD schools, owner:Esri_Tutorials', 'Feature Layer',outside_org=True)[0]" ] }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 91, "metadata": {}, "outputs": [ { @@ -1204,18 +1247,18 @@ "
\n", " PUSD Schools\n", " \n", - "
Schools in the Pasadena Unified School DistrictFeature Layer Collection by Learn_ArcGIS\n", - "
Last Modified: October 17, 2018\n", - "
0 comments, 7,643 views\n", + "
Schools in the Pasadena Unified School District
Feature Layer Collection by Esri_Tutorials\n", + "
Last Modified: October 14, 2024\n", + "
0 comments, 108279 views\n", "
\n", " \n", " " ], "text/plain": [ - "" + "" ] }, - "execution_count": 41, + "execution_count": 91, "metadata": {}, "output_type": "execute_result" } @@ -1228,114 +1271,81 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "By default, the schools have red point symbols that can be difficult to distinguish from the accident points. We'll change the symbol so the schools stand out more. The square shape will be distinguishable from the circle shapes of the accidents. We'll also change the color to white so the symbols stand out against the dark basemap." + "By default, the schools have red point symbols that can be difficult to distinguish from the accident points. We'll change the symbol so the schools stand out more. The square shape will be distinguishable from the circle shapes of the accidents. We'll also change the color to platinum (light shade of gray) so the symbols stand out against the dark basemap." ] }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 148, "metadata": {}, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 42, + "execution_count": 148, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "m7 = gis.map('Pasadena, California', 13)\n", + "m7 = gis.map('Pasadena, California')\n", + "m7.basemap.basemap = 'arcgis-dark-gray'\n", "m7" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The layer of schools is added to the map. The schools now stand out and can be distinguished from the accidents." - ] - }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 144, "metadata": {}, "outputs": [], "source": [ - "m7_renderer = {\"renderer\": \"autocast\",\n", - " \"type\": \"simple\"}\n", - "def get_symbol(color):\n", - " return create_symbol(geometry_type='point',\n", - " symbol_type='simple',\n", - " symbol_style='s',\n", - " colors=color,\n", - " marker_size=13,\n", - " outline_style='s',\n", - " outline_color=[153,153,153,255],\n", - " line_width=0.375)\n", + "outline = symbols.SimpleLineSymbolEsriSLS(\n", + " color=[229,228,226,255],\n", + " style=symbols.SimpleLineSymbolStyle.esri_sls_solid,\n", + " width=0.375)\n", "\n", - "symbol = get_symbol([153,153,153,255])\n", - "m7_renderer['symbol'] = symbol" + "school_renderer = renderers.SimpleRenderer(\n", + " symbol = symbols.SimpleMarkerSymbolEsriSMS(\n", + " color = [229,228,226,255],\n", + " style = symbols.SimpleMarkerSymbolStyle.esri_sms_square,\n", + " size = 13,\n", + " outline = outline\n", + " )\n", + ")\n", + " " ] }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 145, "metadata": {}, "outputs": [], "source": [ - "m7.basemap = 'dark-gray'" - ] - }, - { - "cell_type": "code", - "execution_count": 45, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 45, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "filtered_df.spatial.plot(map_widget=m7,\n", - " renderer_type='u-a',\n", - " unique_values=uv,\n", - " arcade_expression=arcade_expression)" + "m7.content.add(schools.layers[0], drawing_info={\"renderer\": school_renderer})\n", + "m7.content.add(filtered_df, drawing_info={\"renderer\": accident_renderer})" ] }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 147, "metadata": {}, "outputs": [], "source": [ - "m7.add_layer({ \"type\": \"FeatureLayer\",\n", - " \"url\": schools.layers[0].url,\n", - " \"transparency\": 75,\n", - " \"renderer\": m7_renderer\n", - " })\n" + "m7.zoom_to_layer(schools.layers[0])\n", + "m7.legend.enabled = True" ] }, { - "cell_type": "code", - "execution_count": 47, + "cell_type": "markdown", "metadata": {}, - "outputs": [], "source": [ - "m7.legend = True" + "The layer of schools is added to the map. The schools now stand out and can be distinguished from the accidents." ] }, { @@ -1356,7 +1366,7 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -1369,36 +1379,34 @@ }, { "cell_type": "code", - "execution_count": 49, - "metadata": { - "scrolled": true - }, + "execution_count": 100, + "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "
\n", - " \n", + " \n", " \n", " \n", "
\n", "\n", "
\n", - " psud_schools_drivetime224021\n", + " psud_schools_drivetime398437\n", " \n", - "
Feature Layer Collection by arcgis_python\n", - "
Last Modified: September 13, 2019\n", + "

Feature Layer Collection by MMajumdar_geosaurus\n", + "
Last Modified: December 03, 2024\n", "
0 comments, 0 views\n", "
\n", "
\n", " " ], "text/plain": [ - "" + "" ] }, - "execution_count": 49, + "execution_count": 100, "metadata": {}, "output_type": "execute_result" } @@ -1409,27 +1417,26 @@ }, { "cell_type": "code", - "execution_count": 50, - "metadata": { - "scrolled": false - }, + "execution_count": 153, + "metadata": {}, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 50, + "execution_count": 153, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "m8 = gis.map('Pasadena, California', 13)\n", + "m8 = gis.map('Pasadena, California')\n", + "m8.basemap.basemap = 'arcgis-dark-gray'\n", "m8" ] }, @@ -1442,74 +1449,39 @@ }, { "cell_type": "code", - "execution_count": 51, - "metadata": {}, - "outputs": [], - "source": [ - "m8.basemap = 'dark-gray'" - ] - }, - { - "cell_type": "code", - "execution_count": 52, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 52, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "filtered_df.spatial.plot(map_widget=m8,\n", - " renderer_type='u-a',\n", - " unique_values=uv,\n", - " arcade_expression=arcade_expression)" - ] - }, - { - "cell_type": "code", - "execution_count": 53, + "execution_count": 150, "metadata": {}, "outputs": [], "source": [ - "m8.add_layer({ \"type\": \"FeatureLayer\",\n", - " \"url\": schools.layers[0].url,\n", - " \"transparency\": 75,\n", - " \"renderer\": m7_renderer\n", - " })\n" + "m8.content.add(schools.layers[0], drawing_info={\"renderer\": school_renderer})\n", + "m8.content.add(filtered_df, drawing_info={\"renderer\": accident_renderer})" ] }, { "cell_type": "code", - "execution_count": 54, + "execution_count": 151, "metadata": {}, "outputs": [], "source": [ - "m8.add_layer(walk_dist_from_schools)" + "m8.content.add(walk_dist_from_schools, options={\"opacity\": 0.6})" ] }, { "cell_type": "code", - "execution_count": 55, + "execution_count": 152, "metadata": {}, "outputs": [], "source": [ - "m8.legend = True" + "m8.zoom = 13" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "We could stop your analysis here, and use this map as grounds to implement a policy that encompasses all school zones. Changing street signs and adding bicycle lanes in these areas may reduce accidents near schools.\n", + "You could stop your analysis here, and use this map as grounds to implement a policy that encompasses all school zones. Changing street signs and adding bicycle lanes in these areas may reduce accidents near schools.\n", "\n", - "However, sometimes a city does not have enough funds to enact new policy for every location. Many Pasadena school zones have few accidents, so policies in these areas may have little effect. Instead, policymakers want to focus their efforts on areas that need it most.\n", + "However, sometimes a city does not have enough funds to enact new policy for every location. Many Pasadena school zones have few accidents, so policies in these areas may have little effect. Instead, policymakers want to focus their efforts on areas that need it the most.\n", "\n", "We'll calculate the number of accidents within each school zone and filter the layer to show only the five most dangerous zones. Then, policymakers can prioritize these zones over zones that are already relatively safe." ] @@ -1530,7 +1502,7 @@ }, { "cell_type": "code", - "execution_count": 56, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -1541,7 +1513,7 @@ }, { "cell_type": "code", - "execution_count": 57, + "execution_count": 109, "metadata": {}, "outputs": [ { @@ -1549,26 +1521,26 @@ "text/html": [ "
\n", "
\n", - " \n", + " \n", " \n", " \n", "
\n", "\n", "
\n", - " accident_count_within_school_zone169811\n", + " accident_count_within_school_zone162401\n", " \n", - "
Feature Layer Collection by arcgis_python\n", - "
Last Modified: September 13, 2019\n", + "

Feature Layer Collection by MMajumdar_geosaurus\n", + "
Last Modified: December 03, 2024\n", "
0 comments, 0 views\n", "
\n", "
\n", " " ], "text/plain": [ - "" + "" ] }, - "execution_count": 57, + "execution_count": 109, "metadata": {}, "output_type": "execute_result" } @@ -1579,7 +1551,7 @@ }, { "cell_type": "code", - "execution_count": 58, + "execution_count": 110, "metadata": {}, "outputs": [], "source": [ @@ -1588,7 +1560,7 @@ }, { "cell_type": "code", - "execution_count": 59, + "execution_count": 111, "metadata": {}, "outputs": [ { @@ -1613,7 +1585,6 @@ " \n", " \n", " OBJECTID\n", - " Point_Count\n", " Name\n", " FromBreak\n", " ToBreak\n", @@ -1626,197 +1597,208 @@ " AdditionalTime\n", " AdditionalDistance\n", " AnalysisArea\n", + " Point_Count\n", " SHAPE\n", " \n", " \n", " \n", " \n", - " 10\n", - " 11\n", - " 110\n", + " 7\n", + " 8\n", + " Madison Elementary : 0 - 0.5\n", + " 0.0\n", + " 0.5\n", + " 8\n", + " Madison Elementary\n", + " 515 ASHTABULA ST\n", + " PASADENA\n", + " ELEMENTARY\n", + " <NA>\n", + " 0.0\n", + " 0.0\n", + " 0.529728\n", + " 117\n", + " {\"rings\": [[[-13151389.2187, 4051086.8635], [-...\n", + " \n", + " \n", + " 8\n", + " 9\n", " McKinley School : 0 - 0.5\n", - " 0\n", + " 0.0\n", " 0.5\n", " 9\n", " McKinley School\n", " 325 S OAK KNOLL AVE\n", " PASADENA\n", " ELEMENTARY/MIDDLE\n", - " None\n", - " 0\n", - " 0\n", - " 1.492772\n", - " {'rings': [[[-13150773.7838, 4048681.8554], [-...\n", + " <NA>\n", + " 0.0\n", + " 0.0\n", + " 0.61083\n", + " 114\n", + " {\"rings\": [[[-13150764.2216, 4048700.1758], [-...\n", " \n", " \n", - " 11\n", - " 12\n", - " 106\n", + " 19\n", + " 20\n", " Rose City High Alternative : 0 - 0.5\n", - " 0\n", + " 0.0\n", " 0.5\n", " 20\n", " Rose City High Alternative\n", " 351 S HUDSON AVE\n", " PASADENA\n", " HIGH\n", - " None\n", - " 0\n", - " 0\n", - " 1.355013\n", - " {'rings': [[[-13150623.7846, 4048651.6474], [-...\n", + " <NA>\n", + " 0.0\n", + " 0.0\n", + " 0.502756\n", + " 84\n", + " {\"rings\": [[[-13150764.2216, 4048549.1365], [-...\n", " \n", " \n", - " 14\n", - " 15\n", - " 104\n", - " Madison Elementary : 0 - 0.5\n", - " 0\n", + " 10\n", + " 11\n", + " Washington Accelerated Elementary : 0 - 0.5\n", + " 0.0\n", " 0.5\n", - " 8\n", - " Madison Elementary\n", - " 515 ASHTABULA ST\n", + " 11\n", + " Washington Accelerated Elementary\n", + " 1520 N RAYMOND AVE\n", " PASADENA\n", " ELEMENTARY\n", - " None\n", - " 0\n", - " 0\n", - " 1.273972\n", - " {'rings': [[[-13151398.781, 4051098.7538], [-1...\n", + " <NA>\n", + " 0.0\n", + " 0.0\n", + " 0.572369\n", + " 64\n", + " {\"rings\": [[[-13152314.2145, 4052990.531], [-1...\n", " \n", " \n", + " 6\n", " 7\n", - " 8\n", - " 63\n", - " Washington Middle : 0 - 0.5\n", - " 0\n", - " 0.5\n", - " 18\n", - " Washington Middle\n", - " 1505 N MARENGO AVE\n", - " PASADENA\n", - " MIDDLE\n", - " None\n", - " 0\n", - " 0\n", - " 1.292630\n", - " {'rings': [[[-13151998.7782, 4052730.4508], [-...\n", - " \n", - " \n", - " 16\n", - " 17\n", - " 62\n", " Longfellow Elementary : 0 - 0.5\n", - " 0\n", + " 0.0\n", " 0.5\n", " 7\n", " Longfellow Elementary\n", " 1065 E WASHINGTON BLVD\n", " PASADENA\n", " ELEMENTARY\n", - " None\n", - " 0\n", - " 0\n", - " 1.418004\n", - " {'rings': [[[-13149873.788, 4052398.0492], [-1...\n", + " <NA>\n", + " 0.0\n", + " 0.0\n", + " 0.57478\n", + " 61\n", + " {\"rings\": [[[-13149814.2259, 4052416.3755], [-...\n", " \n", " \n", "\n", "" ], "text/plain": [ - " OBJECTID Point_Count Name FromBreak \\\n", - "10 11 110 McKinley School : 0 - 0.5 0 \n", - "11 12 106 Rose City High Alternative : 0 - 0.5 0 \n", - "14 15 104 Madison Elementary : 0 - 0.5 0 \n", - "7 8 63 Washington Middle : 0 - 0.5 0 \n", - "16 17 62 Longfellow Elementary : 0 - 0.5 0 \n", + " OBJECTID Name FromBreak ToBreak \\\n", + "7 8 Madison Elementary : 0 - 0.5 0.0 0.5 \n", + "8 9 McKinley School : 0 - 0.5 0.0 0.5 \n", + "19 20 Rose City High Alternative : 0 - 0.5 0.0 0.5 \n", + "10 11 Washington Accelerated Elementary : 0 - 0.5 0.0 0.5 \n", + "6 7 Longfellow Elementary : 0 - 0.5 0.0 0.5 \n", "\n", - " ToBreak FacilityOID Name_1 ADDRESS \\\n", - "10 0.5 9 McKinley School 325 S OAK KNOLL AVE \n", - "11 0.5 20 Rose City High Alternative 351 S HUDSON AVE \n", - "14 0.5 8 Madison Elementary 515 ASHTABULA ST \n", - "7 0.5 18 Washington Middle 1505 N MARENGO AVE \n", - "16 0.5 7 Longfellow Elementary 1065 E WASHINGTON BLVD \n", + " FacilityOID Name_1 ADDRESS \\\n", + "7 8 Madison Elementary 515 ASHTABULA ST \n", + "8 9 McKinley School 325 S OAK KNOLL AVE \n", + "19 20 Rose City High Alternative 351 S HUDSON AVE \n", + "10 11 Washington Accelerated Elementary 1520 N RAYMOND AVE \n", + "6 7 Longfellow Elementary 1065 E WASHINGTON BLVD \n", "\n", " CITY SCHOOLTYPE Breaks AdditionalTime AdditionalDistance \\\n", - "10 PASADENA ELEMENTARY/MIDDLE None 0 0 \n", - "11 PASADENA HIGH None 0 0 \n", - "14 PASADENA ELEMENTARY None 0 0 \n", - "7 PASADENA MIDDLE None 0 0 \n", - "16 PASADENA ELEMENTARY None 0 0 \n", + "7 PASADENA ELEMENTARY 0.0 0.0 \n", + "8 PASADENA ELEMENTARY/MIDDLE 0.0 0.0 \n", + "19 PASADENA HIGH 0.0 0.0 \n", + "10 PASADENA ELEMENTARY 0.0 0.0 \n", + "6 PASADENA ELEMENTARY 0.0 0.0 \n", + "\n", + " AnalysisArea Point_Count \\\n", + "7 0.529728 117 \n", + "8 0.61083 114 \n", + "19 0.502756 84 \n", + "10 0.572369 64 \n", + "6 0.57478 61 \n", "\n", - " AnalysisArea SHAPE \n", - "10 1.492772 {'rings': [[[-13150773.7838, 4048681.8554], [-... \n", - "11 1.355013 {'rings': [[[-13150623.7846, 4048651.6474], [-... \n", - "14 1.273972 {'rings': [[[-13151398.781, 4051098.7538], [-1... \n", - "7 1.292630 {'rings': [[[-13151998.7782, 4052730.4508], [-... \n", - "16 1.418004 {'rings': [[[-13149873.788, 4052398.0492], [-1... " + " SHAPE \n", + "7 {\"rings\": [[[-13151389.2187, 4051086.8635], [-... \n", + "8 {\"rings\": [[[-13150764.2216, 4048700.1758], [-... \n", + "19 {\"rings\": [[[-13150764.2216, 4048549.1365], [-... \n", + "10 {\"rings\": [[[-13152314.2145, 4052990.531], [-1... \n", + "6 {\"rings\": [[[-13149814.2259, 4052416.3755], [-... " ] }, - "execution_count": 59, + "execution_count": 111, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "top_5_dangerous_areas[:5]" + "top_5_dangerous_areas_df = top_5_dangerous_areas[:5]\n", + "top_5_dangerous_areas_df" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "The table is sorted so that school zones with more accidents are shown first. The first five school zones have accidents totaling 109, 106, 104, 63, and 62, respectively.\n", + "The table is sorted so that school zones with more accidents are shown first. The first five school zones have accidents totaling 117, 114, 84, 64, and 61, respectively.\n", "\n", - "The sixth-highest school zone has 59 accidents, which is almost the same as the fifth highest. With this information, you might consider expanding policy to include this school zone as well. Alternatively, depending on the city's resources, we want to limit policy to focus only on the three most dangerous school zones, which have a much higher number of accidents than the fourth.\n", + "The sixth-highest school zone has 58 accidents, which is almost the same as the fifth highest. With this information, you might consider expanding policy to include this school zone as well. Alternatively, depending on the city's resources, we want to limit policy to focus only on the three most dangerous school zones, which have a much higher number of accidents than the fourth.\n", "\n", "For this scenario, we'll continue to focus on the five most dangerous school zones. We'll filter the layer to show only these zones." ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "All five of the most dangerous school zones are relatively close to one another. Two of the most dangerous zones almost overlap entirely, which means the city can increase safety for both schools with many of the same policy decisions." + ] + }, { "cell_type": "code", - "execution_count": 60, + "execution_count": 160, "metadata": {}, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 60, + "execution_count": 160, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "m9 = gis.map('Pasadena, California', 13)\n", + "m9 = gis.map('Pasadena, California')\n", + "m9.basemap.basemap = 'arcgis-dark-gray'\n", "m9" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "All five of the most dangerous school zones are relatively close to one another. Two of the most dangerous zones almost overlap entirely, which means the city can increase safety for both schools with many of the same policy decisions." - ] - }, { "cell_type": "code", - "execution_count": 61, + "execution_count": 157, "metadata": {}, "outputs": [], "source": [ - "m9.basemap = 'dark-gray'" + "m9.content.add(schools.layers[0], drawing_info={\"renderer\": school_renderer})\n", + "m9.content.add(filtered_df, drawing_info={\"renderer\": accident_renderer})" ] }, { "cell_type": "code", - "execution_count": 62, + "execution_count": 158, "metadata": {}, "outputs": [ { @@ -1825,42 +1807,22 @@ "True" ] }, - "execution_count": 62, + "execution_count": 158, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "filtered_df.spatial.plot(map_widget=m9,\n", - " renderer_type='u-a',\n", - " unique_values=uv,\n", - " arcade_expression=arcade_expression)" - ] - }, - { - "cell_type": "code", - "execution_count": 63, - "metadata": {}, - "outputs": [], - "source": [ - "m9.add_layer({\"type\": \"FeatureLayer\", \n", - " \"url\": dangerous_areas.layers[0].url,\n", - " \"definition_expression\" : \"Point_Count>=61\",\n", - " \"opacity\": 0.7\n", - " })" + "top_5_dangerous_areas_df.spatial.plot(map_widget = m9)" ] }, { "cell_type": "code", - "execution_count": 64, + "execution_count": 159, "metadata": {}, "outputs": [], "source": [ - "m9.add_layer({ \"type\": \"FeatureLayer\",\n", - " \"url\": schools.layers[0].url,\n", - " \"transparency\": 75,\n", - " \"renderer\": m7_renderer\n", - " })\n" + "m9.zoom_to_layer(schools.layers[0])" ] }, { @@ -1874,7 +1836,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "We've created a map that highlights five school zones that would benefit from policy intervention. \n", + "We have created a map that highlights five school zones that would benefit from policy intervention. \n", "The city officials can now identify the most dangerous school zones in order to reduce the likelihood of future accidents." ] } @@ -1885,7 +1847,7 @@ "notebookRuntimeVersion": "9.0" }, "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -1899,9 +1861,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.9" + "version": "3.11.10" } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 }