This repository contains the set of Python scripts that were developed to create a custom ArcGIS geoprocessing tool to assit the Cumberland County, PA Department of Public Safety with their SARA Tier II reporting.
The goal of this repository to is to provide a starting point for similar analyses. The dataset and geodatabase variables will need to be updated to the specifications of your project. You will also need to create your own ArcGIS toolbox for your implementation of this tool.
While created for a specific purpose, the scripts can be refactored to perform a proximity analysis for a location that is defined by latitude/longitude. It can estimate the popluation within a certain distance of that facility (buffer), and select features from other layers that are within the buffer.
Summary of Tool
This tool consists of four Python scripts.
SARAReportTool.py is the script that the custom tool is built from. The other three scripts are modules which are imported into
SARAReportTool.py. I will provide a summary of what each script does.
Each module uses try-except statements and logs errors to the tool window.
This tool collects parameters from the ArcGIS tool's form using the
arcpy.GetParameterAsText() method. All inputs are required.
- Latitude (double format) - the latitude in decimal degrees of the SARA facility.
- Longitude (double format) - the longitude in decimal degrees of the SARA facility.
- PATTS ID (string format) - an unique identifier for each SARA facility
- Distances for Risk Radius (double format, multiple values allowed) - the distance(s) for each risk radius buffer
- Risk Radius Units (string format) - the units for the risk radius buffers
- Folder location (folder format) - the folder location for the Microsoft Excel spreadsheets created that list the vulnerable facilities that intersect each risk radius.
These inputs are used in the three analyses. The first analysis calculate a multi-ring buffer around the SARA facility using the distances and units provided in the form.
The second analysis clips a Census geography (blocks) to each risk radius using a
Search Cursor (more info). A proportional population value is calculated for each Census block, and the sum of the proportional population is added to a table.
The third analysis performs a Select by Location analysis on each vulnerable facility for each risk radius. If any vulnerable facilities intersect the risk radius, those features are exported to a Microsoft Excel file.
This tool creates the risk radii for the SARA facility using a function that is imported into
Next, the Project tool is run to convert the point from WGS 1984 to Pennsylvania State Plane South (ft). You will need to update the script to use the coordinate system in your locale.
Finally, the multi-ring buffer tool is run against the projected point using the distances and units provided in the form. The output for this tool is defined in a geodatabase, and the naming convetion uses the unique PATTS ID in the naming convetion.
The output layer is also returned from the function, as the layer is used as an input for the other tools.
This tool estimates the population located within each risk radius generated from
riskRadius.py. The tool is a function that is imported into
You will need to update the variable that stores the Census geography used in your implementation of this tool. You will also need to create a double field called ORAREA to store the original (pre-clippped) area of each census geography.
The tool uses a Search Cursor on the output layer from the multi-ring buffer tool. For each record in this layer, the Census geography layer is clipped.
The ratio of original area to clipped area for each feature is calculated. The population field for the Census geography is multiplied by the ratio value to create a proportional value.
That is, if 50% of the Census block is within the risk radius, then we will assume 50% of that block's population is within the risk radius. This is a limitation of using aggregate data such as Census blocks.
Each output from the Clip operation is output into a geodatabase that you will need to update the variable for. The name of the feature class is created using PATTS ID, buffer distance and units, and a count variable to help avoid duplicate names.
Lastly, a table for each output of the Clip operation is created that calculates the sum of the proportional popluation.
This tool identifies any vulnerable facilities that intersect each risk radius. The tool is a function that is imported into
The tool uses a Search Cursor on the output layer from the multi-ring buffer tool. You will need to update the variables for vulnerable facilities.
For any vulnerable facilities that are within the risk radius, the selected features are exported to a Microsoft Excel file using the
arcpy.TableToExcel_conversion() method. If no features are selected, a message is added to the ArcGIS tool window.