Workflow using ArcGIS Pro
Explore space-time patterns
- If you haven't done so already, download and unzip the data package provided at the top of this workflow.
- Double-click the CrashAnalysis.ppkx to open it.
- Right-click the AllCrashes10to15 layer in the Contents pane and select Attribute Table.
- Notice the CRASH_DT (date) field. If you sort on this field (double-click the field header), you will notice the data range from January 1, 2010 to December 31, 2015. You will use this date field to structure the crash data into space-time hexagon bins. Close the table.
- Find and open the Create Space Time Cube tool and run it with the parameters below. The cube is a netCDF file so it must be created in a folder rather than inside a file geodatabase. With this quick exploration of traffic accident trends between 2010 and 2015, you will look at 2-mile hexagons using 16-week time periods. You could certainly spend a lot of time here experimenting with different hexagon sizes and time periods, but since this isn't your final analysis (your final analysis will be more refined), these parameters will work well.
- Input Features : AllCrashes10to15
- Output Space Time Cube : the name of your output cube such as AllCrashes.nc
- Time Field : CRASH_DT
- Time Step Interval : 16 Weeks
- Time Step Alignment : End time
- Distance Interval : 2 Miles
- Aggregation Shape Type : Hexagon grid
- When the tool finishes, hover over the tool name in the progress bar to display the messages. Click the pop-out button
to examine details about the cube you created.
Expanding the message window - Click the back arrow on the Geoprocessing pane. Find and open the Emerging Hot Spot Analysis tool.
Clicking the back arrow to begin a new search - Run the Emerging Hot Spot Analysis tool with the parameters below. You will take the default values for the Neighborhood Distance and Neighborhood Time Step parameters.
- Input Space Time Cube : AllCrashes.nc
- Analysis Variable : COUNT
- Output Features : the name of your output feature class such as CrashTrends
- Examine the results. There is a specific definition for each trend category on the map. If you hover over the tool name in the progress bar and click the pop-out button
, you will see a Summary of Results table indicating there are three New Hot Spots, nineteen Consecutive Hot Spots, and a number of Diminishing Cold Spots. Look up the definitions for each of these trend patterns.
Crash rate space-time trends
Identify crash hot spots on the road network
The crash trend analysis above is a great exploratory workflow. Unfortunately, the analysis is not based on the road network. In this next analysis, you will associate each crash with the underlying road network and look for crash hot spot locations.
- You are going to snap the crash points to the roads. The Snap tool changes feature geometry, so begin by creating a copy of the crash data. Click the back arrow on the Geoprocessing pane, then find and run Copy Features:
- Input Features : AllCrashes10to15
- Output Feature Class : the name of the new feature class such as Crash_Points
- Find and open the Snap tool and run it with the following parameters to make sure all crash points fall on a road.
- Input Features : Crash_Points
- Snap Environment :
- Features : RoadSegments
- Type : Edge
- Distance : 0.25 Miles
- Once all points are located on a road, you can use the Spatial Join tool to count the number of accidents associated with each road segment. Find and open the Spatial Join tool. Use the parameters shown below. You will remove all but the UniqID and Fatalities attributes from the Field Map (by clicking the red X that appears when you hover over a field you want to remove). You will use the summed Fatalities data later in the workflow.
- Target Features : RoadSegments
- Join Features : Crash_Points
- Output Feature Class : the name of your output feature class such as Road_Crash_Counts
- Field Map of Join Features : UniqID, First; Fatalities, Sum
- Find and open the Add Field tool and use it to create a new double precision rate field:
- Input Table : Road_Crash_Counts
- Field Name : CrashRate
- Field Type : Double
- Field Alias : Average crashes per mile per year
- Find and open the Calculate Field tool and use it to compute the crash rate. The numerator for the crash rate calculation is the number of crashes associated with each road segment (the Join_Count field) and the denominator is the number of years of data (6 years) times the length of the road segment (Shape_Length).
- Input Table : Road_Crash_Counts
- Field Name : Average crashes per mile per year
- Expression : !Join_Count! / (6 * !Shape_Length!)
- Run hot spot analysis on the road crash rates. Find and open the Hot Spot Analysis tool and run it with the following parameters.
- Input Feature Class : Road_Crash_Counts
- Input Field : Average crashes per mile per year
- Output Feature Class : the name of your output feature class such as Road_Crash_HotSpots
- Conceptualization of Spatial Relationships : Get spatial weights from file
- Weights Matrix File : CrshNtw360ft30.swm included with the case study data package
- Apply False Discovery Rate (FDR) Correction : checked
Statistically significant clusters of high crash rates along the Brevard County road network
Compare crash hot spots
Next you will compare the locations of hot spots for all traffic accidents (the map above) to the locations of hot spots for fatal traffic accidents.
- Use the Add Field tool, again, to create a second crash rate field for fatalities.
- Input Table : Road_Crash_Counts
- Field Name : FatalityRate
- Field Type : Double
- Field Alias : Average fatalities per mile per year
- Use the Calculate Field tool to compute the number of fatalities per year per mile.
- Input Table : Road_Crash_Counts
- Field Name : Average fatalities per mile per year
- Expression : 0 if not !Fatalities! else !Fatalities! / (6 * !Shape_Length!)
- To facilitate comparison of the crash hot spots for all vehicle accidents with the hot spots for crashes involving fatalities, create a new map view. Click on the Insert tab and click New Map.
Inserting a new map - This creates a new map view called Map1. Change the Basemap to match your other map view by clicking the Map tab in the main menu (next to the Insert tab) and selecting the Basemap button.
- With Map1 active, open the Hot Spot Analysis tool from the Project pane. This is a short cut. It will put the output into the active map view but look for inputs in the original Map view.
Opening a previously run tool from the Project pane - Run Hot Spot Analysis using the following parameters:
- Input Feature Class : Road_Crash_Counts
- Input Field : Average number of fatalities per mile per year
- Output Feature Class : the name of your output feature class such as FatalityHotSpots
- Conceptualization of Spatial Relationships : Get spatial weights from file
- Weights Matrix File : CrshNtw360ft30.swm included with the case study data package
- Apply False Discovery Rate (FDR) Correction : checked
- View the crash hot spots next to the fatality hot spots by dragging Map1 to the center of the map view and placing it in the right position.
Positioning two maps side by side - Link the side by side maps by clicking on the View tab, Link Views, and selecting Center And Scale.
Linking the scale and focus of two side by side maps - Zoom in and pan around the map. Notice where the locations for fatal crash rate hot spots differ from the hot spot locations for all crash rates. The red areas on the left side map below are traffic accident (crash rate) hot spots. The red areas on the right side map are fatality crash rate hot spots.
Comparing hot spots for all crash rates (left) to fatality crash rate hot spots (right)
Identifying the most dangerous hours and days of the week
While the analyses above are now based on the underlying road network, an improvement, in the act of aggregating the crash point data to the roads you have stripped away all temporal attributes. In this next section of the workflow, you will summarize the crash data by day of the week (DOW) and by hour of the day (HOD) to understand peak days and time periods for traffic accidents.
- Drag Map1 back to the center of the display and activate the original Map view.
Re-centering the map views - Right-click on the AllCrashes10to15 layer and select Attribute Table. Notice there are fields for hour of the day (CRASH_HOD) and day of the week (CRASH_DOW). Close the attribute table.
- Right-click on the AllCrashes10to15 layer again and select Create Chart. Click on Line Chart.
Creating a line chart - In the Chart pane, set the Data parameters as follows.
- X-Axis: Date or Number : CRASH_HOD
- Aggregation : COUNT
- Data series : From one field split into series
- Split by : CRASH_DOW
- Set the chart titles on the General tab.
- Chart title : Traffic Accidents
- X axis title : Hour of the Day (24 hour clock)
- Y axis title : Number of Crashes
- Undock the chart and resize it as appropriate.
Line chart showing traffic accidents by day of the week and hour of the day - You may turn lines off within the graph by clicking on their entries in the legend. To focus on the lines associated with the workweek, for example, click on Saturday and Sunday to turn them off.
Focusing on the workweek - Close the line chart. If you want to open it again later, click the chart button on the Contents pane.
Existing charts may be reopened from the Contents pane.
![Setting chart fields, order, and colors Setting chart fields, order, and colors](GUID-4D92C0B4-F7F7-4C51-9265-37C75128B838-web.png)
Compare peak crash days and times to the overall pattern of crashes
To create the rate variable for crashes occurring weekdays between 3:00 and 5:00 p.m., you could follow the same steps you used above to create the fatality rate hot spot map. Instead, however, you are going to create a model tool that will allow you to examine any subset of crashes such as: Fridays between 11:00 AM and 1:00 p.m., or weekends between 1:00 and 3:00 AM.
- From the Analysis tab, click the ModelBuilder button to open a new model view canvas.
Creating a new model - Give your model a name by clicking the Properties button in the ModelBuilder tab and setting the following:
- Name : CreateDayTimeHotSpotMap
- Label : Create Day/Time Hot Spot Map
- Add data inputs to your model:
- Add the crash data.
- Drag AllCrashes10to15 from the Contents pane onto the model canvas.
- Right-click on the AllCrashes10to15 model element and select Rename. Change the name to Crash Data.
- Right-click on Crash Data and select Parameter. This labels the element with a P and will allow you to pass selected records to this model later in the workflow.
- Create a file variable.
- Right-click on the model canvas and select Create Variable. From the drop down, select File for the Variable Data Type.
- Double-click the File model element to bring up the browse dialog. Navigate to the CrshNtw360ft30.swm file included with the data package.
Adding model inputs
- Create a day of the week variable.
- Right-click on the model canvas and, again, select Create Variable. Check the Mulitple values check box. This variable will be type String.
- Right-click this multiple value string variable and select Rename. Name this element Days. Right-click the Days variable and select Parameter.
- Create starting and ending hour of the day variables.
- Right-click on the model canvas and select Create Variable. Create two variables of type Long. These two variables are not multiple value.
- Rename one of the variables to be Beginning Hour and the other one to be Ending Hour. Right-click both of these again and select Parameter.
- Define valid variable values.
- Click on the Properties button above the model canvas and select the Parameters tab.
Accessing variable properties - Click inside the Filter column for the Beginning Hour parameter. Select Range and indicate an appropriate value range from 0 to 23 (0 is midnight, and 23 is 11:00 p.m.). Repeat for the Ending Hour parameter.
Setting a range for the beginning and ending hour variables - Click inside the Filter column for the Days variable, select Value List, and provide the day of the week values as shown:
Creating a value list for the Days variable
- Click on the Properties button above the model canvas and select the Parameters tab.
- Set default variable values.
- Double-click the beginning and ending hour model elements and set default values (such as 1 for beginning and 3 for ending).
- Double-click the Days element and set a default value such as Monday and Tuesday.
- Save the model.
Model inputs
- Add the crash data.
- Following the steps below, use the Calculate Value model utility to create an SQL expression for selecting records based on days of the week and hours of the day. You will define a new function called p which takes three arguments: Days, Beginning Hour, and Ending Hour. The function will build the SQL string based on the values of these three arguments.
- On the ModelBuilder menu, select Utilities and Calculate Value.
Adding model utility tools to your model - Double-click the Calculate Value tool in the model and set the parameters as follows:
- Expression : p("%Days%", %Beginning Hour%, %Ending Hour%)
- Code Block :
def p (days, start, end): # define a function called p sStart = str(start) # convert the start hour to a string sEnd = str(end) # convert the end hour to a string d = days.split(";") # get the day strings into a list called d ss = "(CRASH_DOW = '" + d[0] # select CRASH_DOW equal to d[0] for i in range (1, len(d)): # loop through list of other days, if any ss = ss + "' OR CRASH_DOW = '" + d[i] # tag on any additional days in the list ss = ss + "') AND (CRASH_HOD >= " + sStart # add the HOD search ss = ss + " AND CRASH_HOD <= " + sEnd + ")" # finish the SQL statement return ss
- Data Type : SQL Expression
Creating an SQL expression to select crashes by day of week and hour of day
- Right-click the output_value model element and Rename it SQL Expression
- In the Geoprocessing pane, search for Select Layer By Attribute. Right-click on it in the Search Results and select Add To Model.
Adding a geoprocessing tool to your model - Create a connection from the Crash Data element to the Select Layer By Attribute tool, setting the connection to Layer Name or Table View.
Connecting model elements - Create a connection for the Expression parameter from the SQL Expression model element to the Select Layer By Attribute tool.
- Rename the Updated Layer or Table View element to Selected Crashes. Save the model.
Model components for creating an SQL statement to select the crash points for analysis
- On the ModelBuilder menu, select Utilities and Calculate Value.
- Extend the model to snap the selected crash points to the roads.
- Add the Copy Features tool to the model canvas (search for Copy Features in the Geoprocessing pane, then right-click on it in the Search Results, and select Add to Model).
- Add the Snap tool to the model canvas.
- Add the Spatial Join tool to the model canvas.
- Connect the Selected Crashes model element to Copy Features. It is important to create a copy of your data before using Snap because Snap changes feature geometry. Rename the Copy Features Output Feature Class to Crash Points.
- Connect Crash Points to the Snap tool as Input Features. Rename the output from the Snap tool (the element called Snapped Input Features) to Crash Points Snapped to Roads.
- Double-click the Snap tool in the model and set the parameters as follows.
- Input Features : Crash Points
- Snap Environment
- Features : RoadSegments
- Type : EDGE
- Distance : 0.25 Miles
- Connect RoadSegments to the Spatial Join tool as the Target Features. Connect Crash Points Snapped to Roads to the Spatial Join tool as the Join Features. Rename the spatial join output to Road Segment Crash Counts.
Model component for snapping selected crash point to roads
- Extend the model to create a crash rate field.
- Drag the Add Field and Calculate Field tools on the model canvas (or right-click them in the Geoprocessing search pane and select Add To Model).
- Right-click the Add Field tool and select Create Variable From Parameter where the parameter is Field Name.
Creating model variables from tool parameters - Double-click the Field Name variable and set the default value to be CrashRate. Rename the Field Name variable to New Rate Field Name. Make the New Rate Field Name model element a parameter by right-clicking it and selecting Parameter. Making it a parameter will allow the user to provide a name for the rate field.
- Connect Road Segment Crash Counts to the Add Field tool as the Input Table.
- Double-click the Add Field tool and set the Field Type to Double.
- Rename the output element coming from the Add Field tool to be Crash Counts. Rename the output element coming from the Calculate Field tool to be Crash Rates.
- Connect Crash Counts to the Calculate Field tool as the Input Table.
- Double-click the Calculate Field tool model element and set the parameters as follows.
- Input Table : Crash Counts
- Field Name : %New Rate Field Name%
- Expression : !Join_Count! / (6 * !Shape_Length!)
Model components for calculating a crash rate
- Extend the model to perform a hot spot analysis.
- Add the Hot Spot Analysis tool to the model canvas.
- Connect CrshNtw360ft30.swm to the Hot Spot Analysis tool as the Weights Matrix File. Connect the Crash Rates model element to the Hot Spot Analysis tool as the Input Feature Class.
- Rename the Hot Spot Analysis tool output to Selected Crash Hot Spot Map.
- Double-click the Hot Spot Analysis tool and set the parameters as follows.
- Input Feature Class : Crash Rates
- Input Field : %New Rate Field Name%
- Output Feature Class : the name of your output feature class such as SelectedCrashHotSpots
- Conceptualization of Spatial Relationships : Get spatial weights from file
- Weights Matrix File : CrshNtw360ft30.swm
- Apply False Discovery Rate (FDR) : checked
- Right-click Selected Crash Hot Spots and select both the Parameter and the Add to Display options. Your model should look similar to the one below. Save the model.
The grouping shown (yellow boxes) matches the steps above but isn't necessary for the model to run. To group elements within the model, select them and click on the Group button in the ModelBuilder tab.
Model to create day/time hot spot maps
- From the Create Day/Time Hot Spot Map model view, Validate and Run the model one time through to make sure there are no errors. Running once in the model view not only checks the model tool's integrity, but also ensures the output rendering is connected correctly. Remove the output from the Contents pane before moving on to the next step.
- Activate the Map view and run your model tool again from the Geoprocessing pane (either search for the new model tool like you would any geoprocessing tool, or locate the model tool in the Project pane under Toolboxes). Select all weekday crashes occurring between 3:00 and 5:00 p.m..
- Crash Data : AllCrashes10to15
- Days : Monday; Tuesday; Wednesday; Thursday; Friday
- Beginning Hour : 15
- Ending Hour : 17
- New Rate Field Name : a rate field name such as WrkWk3to5
- Selected Crash Hot Spot Map : an output feature class name such as WrkWk3to5HotSpots
- Copy the WrkWk3to5HotSpots layer from the Contents pane of the Map view to the Contents pane of the Map1 view.
- View the hot spot map of all crashes (Road_Crash_ HotSpots on the Map view) side by side with the hot spot map of workweek 3:00 to 5:00 p.m. crashes (WrkWk3to5HotSpots on the Map1 view). Turn off drawing for all other layers. Below, for example, notice there is a crash rate hot spot for weekdays 3:00 to 5:00 p.m. on US Route 1 just north of Florida State Road 404 (Pineda Causeway). This hot spot is particular to the workweek afternoon commute.
Crash rate hot spots for all day and times (left) compared to crash rate hot spots for the afternoon workweek commute (right) - Activate the Map view. All of the data you will need to build the model tools below are in this view.
Create yearly space-time hot spot maps
Next you will modify the Create Day/Time Hot Spot Map model to create yearly road network hot spot maps for particular days of the week and particular hours during the day.
- Click the New button on the ModelBuilder tab.
Creating a new model - This new model is going to call a second model to run the hot spot tool on yearly subsets of the selected crashes. Click the Properties button and set the General model attributes as follows. Save the model.
- Name : DayTimeAnalysis
- Label : Analyze Day/Time Hot Spot Trends
- If not already open, open your Create Day/Time Hot Spot Map model tool or the xCreate Day/Time Hot Spot Map model tool that came with the data package. Do this by expanding Toolboxes and the project toolbox in the Project pane, right-clicking on the model tool and selecting Edit.
- Copy to your new model canvas the model elements for selecting crashes associated with particular days of the week and hours of the day. Include the Days, Beginning Hour, Ending Hour, Crash Data, Calculate Value, and Select Layer By Attribute model elements.
- You may need to reset the value ranges and value list for the copied parameters. Check this by following the steps below.
- Activate the Analyze Day/Time Hot Spot Trends model view.
- Click the Properties button and select the Parameters tab.
- Check that the Days parameter has a complete value list (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, and Sunday).
- Check that the Beginning Hour and Ending Hour variables have value ranges from 0 to 23.
- Save the model.
- Open another new model (click the New Model button).
- Click the Properties button and set the Name and Label values as shown below, then save the model.
- Name : YearlyHotSpotMaps
- Label : Yearly Hot Spot Maps
- Add the Iterate Feature Selection iterator to the blank model canvas.
Adding an iterator to your model - Double-click the Iterate Feature Selection model element and set the parameters as follows, then right-click AllCrashes10to15 and make it a model Parameter.
- In Features : AllCrashes10to15 (it may show as AllCrashes10to15:1)
- Field : CRASH_YEAR
Setting the iterator parameters to process each year of crash data
- Copy the rest of the first model (Create Day/Time Hot Spot Map), beginning with Copy Features and ending with the Hot Spot Analysis tool, and paste it underneath Iterate Feature Selection. Connect the output from Iterate Feature Selection to Copy Features.
- Remove (uncheck) the Parameter and Add To Display setting for the output from Hot Spot Analysis.
Neither Parameter nor Add To Display should be checked. - Add the Parameter setting to the RoadSegments model element.
Reuse the components of your previous model - Drag the Add Field and Calculate Field tools to the bottom of the model (or find them in the Geoprocessing search pane, right-click, and select Add To Model).
- Set the parameters for Add Field as follows.
- Input Table : Selected Crash Hot Spot Map
- Field Name : AnalysisYear
- Field Type : Long
- Connect the output from Add Field to be the input to Calculate Field, and set the Calculate Field parameters as shown below.
- Input Table : SelectedCrashHotSpots
- Field Name : AnalysisYear
- Expression : %Value%
- Double-click the output from the Hot Spot Analysis tool (called Selected Crash Hot Spot Map) and set the default value to CrashHotSpots%Value%.
- Add the Collect Values model utility to the end of your model.
Adding the Collect Values utility to your model - Connect the output from Calculate Field to be the input to Collect Values.
- Rename the output from Collect Values to Crash Hot Spot Maps. Also make this output a Parameter.
- Validate and save the model.
- Click on the Analyze Day/Time Hot Spot Trends model view to activate it.
- From the Project Pane, under Toolboxes, drag the Yearly Hot Spot Maps model onto the Analyzing Day/Time Hot Spot Trends model canvas. Connect the Selected Crashes output from the first part of the model to the Yearly Hot Spot Maps model tool in the second part of the model. Delete the extra AllCrashes10to15 element from the model.
Building the Analyze Day/Time Hot Spot Trends model tool - Add the Merge tool to the end of the model. Connect the output from the Yearly Hot Spot Maps model to the Merge tool.
- Rename the output from the Merge tool to be Space Time Hot Spots. Make it a model tool Parameter. Double-click the Merge tool model element and set a default name for the tool output such as CrashTrends.
Analyze Day/Time Hot Spot Trends model tool - Click the Properties button and make sure the model tool parameters are in the right order and have the value list (Monday through Sunday) and value range settings (0 to 23) expected.
Setting the model tool parameter properties - Validate and save the model.
- Activate the Map view and run the Analyze Day/Time Hot Spot Trends model from the Project pane (double-click on the model tool to launch it in the Geoprocessing pane).
- Crash Data : AllCrashes10to15
- Days : Monday; Tuesday; Wednesday; Thursday; Friday
- Beginning Hour : 15 (3:00 p.m.)
- Ending Hour : 17 (5:00 p.m.)
- Space Time Hot Spots : the name of your output feature class such as WrkWk3to5CrashTrends
![Model to create yearly hot spot maps Model to create yearly hot spot maps](GUID-77C511B2-0EAC-466D-B906-CB8FA6E91005-web.png)
Use 3D visualization to explore yearly crash hot spot trends
The output from the Analyze Day/Time Hot Spot Trends model is six years of stacked road segments attributed with hot spot analysis results. Consequently, you can only see the trends in the data by viewing the output in 3D. The steps below guide you through creating a 3D visualization that will allow you to assess space-time crash hot spot trends intersection by intersection and roadway by roadway.
- Find and open the Apply Symbology From Layer tool and run it with the following parameters:
- Input Layer : WrkWk3to5CrashTrends
- Symbology Layer : Road_Crash_HotSpots
- From the Insert tab select to create a New Scene view. Change the Basemap if you wish.
Creating a new scene - Copy the WrkWk3to5CrashTrends layer from the Map view to the Scene view (right-click the layer in the Contents pane for the Map view and select Copy, then right-click on the Scene in the Scene view and select Paste). The layer will be added to the scene as a 2D layer. Drag the layer up to the 3D Layers group. The layer may not draw yet; that's okay.
- Right-click the Scene in the Contents pane and select Properties.
Accessing scene properties - On the Elevation Surface tab, expand Elevation sources and remove any that appear there.
Disabling elevation sources on the scene - Zoom in to an area of the map to speed up drawing (zoom in to Melbourne, for example).
- Right-click on the WrkWk3to5CrashTrends layer and select Properties.
- On the General tab, set the Out beyond distance to 2,000,000 ft.
- On the Elevation tab, set the following.
- Features are : At an absolute height
- Additional feature elevation using : An expression ([AnalysisYear]-2010) * 100
Setting the layer elevation properties
- Click the Appearance tab to extrude the road segments. Set the Type to Base Height. Click the Expression button and set the height to 95.
Extruding the road segments Building the 3D visualization - To better focus on the hot spot areas, click on the symbol associated with crash rates that aren't statistically significant and set the color to No color.
Setting No color for road segments that aren't statistically significant - Tilt and zoom into the map to focus in on road segments with persistently high crash rates. The map below shows an area near Eau Gallie, just north of Melbourne.
Afternoon commute crash trends along Highway 1 near Montreal Avenue, Eau Gallie
Opportunities
With the Analyze Day/Time Hot Spot Trends model tool, Lixin can explore other days of the week and hours of the day. Understanding the spatial and temporal patterns of traffic accidents will help him recommend very specific remediation strategies to help prevent future crashes. Knowing which roadways and intersections are associated with persistently high rates for crashes involving alcohol, for example, may direct the locations of DUI check points.