Workflow automation
Building custom model and script tools allows you to not only automate common workflows but also to document them. Presented below are the steps for creating a custom model to regularly check violent crime trends in your study area. As the crime analyst, you will want to run this model tool with updated data every four weeks or so, in order to assess the effectiveness of any remediation strategies you have implemented.
The automation steps shown here use ArcGIS Pro 1.4, but are easily adapted for use with ArcMap or later versions of the software. Additional documentation covering a variety of topics to help you create custom model and script tools in both ArcGIS Pro and ArcMap is available whenever you are ready to learn more.
Create your initial map
The initial map will be the output from Emerging Hot Spot Analysis using twelve months of data prior to implementing your remediation programs. For the purposes of this exercise, your initial map will be based on violent crime data in 2014. You will begin monitoring changes in violent crime trends in January of 2015.
- Open ArcGIS Pro and browse to the BrokenBottlesPkg.ppkx project package.
- Find and open the Create Space Time Cube tool.
- For version 1.4 or later of ArcGIS Pro, if you want the cube output to align with the hot spot output, you must set the Processing Extent to match the Analysis Boundary layer. Click the Environments tab and change the Extent to Analysis Boundary.
- Set the parameters as follows and run the analysis.
- Input Features: Violent Crime 2014
- Output Space Time Cube: the name of your output cube such as ViolentCrime2014.nc
- Time Field: Date
- Time Step Interval: 4 Weeks
- Time Step Alignment: End time
- Distance Interval: 1375 Feet; for version 1.4 of ArcGIS Pro only, use 1375.00275 instead (see note below).
- Find and open the Emerging Hot Spot Analysis tool.
- Set the following parameters and run the analysis.
- Input Space Time Cube: ViolentCrime2014.nc
- Analysis Variable: COUNT
- Output Features: the name of your output feature class such as ViolentCrimeTrends2014
- Neighborhood Distance: 0.5 Miles
- Neighborhood Time Step: 1
- Polygon Analysis Mask: Analysis Boundary
Obtain new crime data to analyze
As the crime analyst you will have access to the newest crime events. Here, for demonstration purposes, you will go through the steps of actually downloading data from the City of Chicago data portal. The FBI Codes for violent crime are 01A, 02, 03, 04A, and 04B. Once you have the new data, you will append it to your existing violent crime data.
- Go to the City of Chicago data portal and locate the data for Crimes, 2001 to present.
- Click on the Filter button and set the following filter conditions:
- Date is after 01/01/2015 12:00:00 AM
- FBI Code is 01A, 02, 03, 04A, or 04B
- Latitude is greater than 0
- Click on the Export button and select CSV for Excel.
- After saving the downloaded file, open it in Excel.
- Remove all but the following fields: ID, Date, Primary_Type, Description, Beat, District, Ward, FBI_Code, Latitude, and Longitude.
- Save the data as a CSV (Comma delimited) file with a descriptive name such as Crimes2015toPresent, and close Excel.
- In ArcGIS Pro add the CSV file to your map (using the Add Data button; you may need to click the Refresh button).
- Find and open the Make XY Event Layer tool and run it with the following parameters.
- XY Table : Crimes2015toPresent.csv
- X Field : Longitude
- Y Field: Latitude
- Layer Name : Crimes2015toPresent_Layer
- Spatial Reference : GCS_WGS_1984
- Append the new data to the existing 2014 violent crime data using the Merge tool. Set the Input Datasets to Violent Crime 2014 and Crimes2015toPresent_Layer. Set the Output Dataset to something descriptive such as ViolentCrime2014toPresent. For the Field Map parameter match any fields that were not automatically matched because of differences in field name or differences in field type:
- Use Add New Source to match Primary_Type in the Violent Crime 2014 dataset with Primary Type in Crimes2015toPresent_Layer.
- Use Add New Source again to match FBI_Code in the Violent Crime 2014 dataset with FBI Code in Crimes2015toPresent_Layer.
- Click on the Properties tab and change the Type parameter for FBI Code to Text.
- Delete the remaining fields without matches.
You now have violent crime data from 2014 through the most current data from the City of Chicago data portal in a single dataset.
Build your model.
You will create a custom model tool that will accept an analysis date, select the data to analyze, and create a crime trend map that you can compare to your base map.
- Open ModelBuilder in ArcGIS Pro from the Analysis tab.
- Begin by creating variables defining the report dates. Right-click in the model canvas, choose Create Variable, and set the variable type to Date. Make this variable a model parameter by right-clicking the variable element and choosing Parameter. Rename the variable to something descriptive such as ReportDate. Double-click the ReportDate variable and initialize the date to December 31, 2014, 11:59:59 PM. Once the model tool is created, you will be able to specify any date you want.
- You want the tool to process violent crime events occurring within a year of whatever report date you provide. Use the Calculate Value model utility to construct the SQL query as follows:
- On the ModelBuilder menu, select Utilities and Calculate Value.
- Double-click the Calculate Value model element and set the Expression parameter to arcpy.time.ParseDateTimeString('%ReportDate%') - datetime.timedelta(days = 365)
- Set the output Data Type parameter to Date.
- Rename the output_value to something descriptive like Starting Report Date
- On the Geoprocessing pane, search for the Select Layer By Attribute tool and drag it onto the model canvas.
- Right-click on the Select Layer By Attribute tool element in the model to create other parameter variables (Create Variable, From Parameter). Choose the Layer Name or Table View parameter.
- Right-click the Layer Name or Table View model element and choose Parameter to make it a model tool parameter. Double-click it and initialize the value to ViolentCrime2014toPresent. Right-click and Rename the model element something descriptive like All Violent Crime. You've made this variable a parameter, so when you run the tool you can change the data source. For now, initializing this parameter allows you to pre-build the expression that will be used to select the 365 days of violent crime incidents prior to the specified report date.
- Double-click on the Select Layer By Attribute tool in the model to open the tool UI. Click the SQL button associated with the Expression parameter. You need to do this when you want to incorporate variables into your expression. Type in the following expression: Date >= timestamp '%Starting Report Date%' AND Date <= timestamp '%ReportDate%'. Right-click and Rename the output tool element to something descriptive such as Violent Crimes within Report Dates. Click the ModelBuilder tab and Validate the model.
- Search for the Create Space-Time Cube tool and drag it onto the model canvas. Connect the Violent Crimes within Report Dates element to the Create Space-Time Cube tool as the Input Features parameter. Right-click and Rename the Output Space Time Cube to Updated Cube Data. Double-click the tool and set the parameters as follows:
- Input Features : ViolentCrime2014toPresent
- Output Space Time Cube : the name of your output cube such as NewViolentCrimeCube
- Time Field : Date
- Time Step Interval : 4 Weeks
- Time Step Alignment : End time
- Distance interval : 1375 Feet; for version 1.4 of ArcGIS Pro only, use 1375.00275 instead.
- For version 1.4 or later of ArcGIS Pro, if you want the cube output to align with the hot spot output, you must set the Processing Extent to match the Analysis Boundary layer. Double-click the Create Space Time Cube model element. When the UI opens, click the Environments tab and change the Extent to Analysis Boundary.
- From the ModelBuilder tab, Run the model. This creates the space time cube so you can fill out the parameters for the Emerging Hot Spot Analysis tool in the next step. From the ModelBuilder tab, Validate the model.
- Search for the Emerging Hot Spot Analysis tool and drag it onto the model canvas. Connect the Updated Cube Data element to the Emerging Hot Spot Analysis tool as Input Space Time Cube. Right-click and Rename the Output Features to Latest Violent Crime Trends. Double-click the tool and set the parameters as follows:
- Input Space Time Cube : Updated Cube Data
- Analysis Variable : COUNT
- Output Features : the name of your violent crime trend map such as LatestViolentCrimeTrends
- Neighborhood Distance : 0.5 Miles
- Neighborhood Time Step : 1
- Polygon Analysis Mask : Analysis Boundary
- Right-click on the Latest Violent Crime Trends element and click both Parameter and Add to display.
- On the ModelBuilder tab, click on Properties. Provide a name and label for your model. Do not include spaces in the model name. For example, you may want to name the model CheckCrimeTrends and label the custom model tool Check Violent Crime Trends. Click Save in the ModelBuilder tab. Additional information is available to help you properly document your custom model tool.
- Click on the Project pane and locate your model under Toolboxes.
- Double-click your model tool to open the tool dialog. The default parameters you set will create a violent crime trend map for 2014. It should match, exactly, the base map you created above. Click on the Map view to activate it. Run the Check Violent Crime Trends model tool. Then compare the new output to your base map.
You will now provide a name and documentation for your model.
Compare the newest crime trends to the base map trends.
You have validated your model tool by creating a violent crime trend map to match your base map. Next you will see how your remediation strategies have impacted crime trends by creating a trend map using your updated violent crime data.
- Run your custom Check Violent Crime Trends model tool again using a ReportDate four weeks later than your base map.
- ReportDate : 1/28/2015 11:59:59 PM
- All Violent Crime : ViolentCrime2014toPresent
- Latest Violent Crime Trends : LastestViolentCrimeTrends1_28_15
- Compare the new trends to the trends in your base map. If your remediation efforts have been effective, you will see fewer intensifying hot spots and will start to see diminishing hot spot areas. If you notice an increase in the number of new hot spot areas, it may indicate crime has been relocated rather than reduced.
Repeat every four weeks.
Every four weeks, repeat the steps above for obtaining new crime data and comparing the newest crime trends to the base map trends. Use these maps to determine how effective your remediation efforts are.