# Hot Spot Analysis of 911 calls in a metropolitan area
# using the Incremental Spatial Autocorrelation and Hot Spot Analysis Tool
# Import system modules
import arcpy
import os
import arcpy.stats as SS
# Set property to overwrite existing output, by default
arcpy.env.overwriteOutput = True
# Local variables
workspace = r"C:\ISA"
try:
# Set the current workspace (to avoid having to specify the full path to the feature classes each time)
arcpy.env.workspace = workspace
# Copy the input feature class and integrate the points to snap together at 30 feet
# Process: Copy Features and Integrate
cf = arcpy.CopyFeatures_management("911Calls.shp", "911Copied.shp","#", 0, 0, 0)
integrate = arcpy.Integrate_management("911Copied.shp #", "30 Feet")
# Use Collect Events to count the number of calls at each location
# Process: Collect Events
ce = SS.CollectEvents("911Copied.shp", "911Count.shp")
# Use Incremental Spatial Autocorrelation to get the peak distance
# Process: Incremental Spatial Autocorrelation
isa = SS.IncrementalSpatialAutocorrelation(ce, "ICOUNT", "20", "", "", "EUCLIDEAN",
"ROW_STANDARDIZATION", "outTable.dbf", "outReport.pdf")
# Hot Spot Analysis of 911 Calls
# Process: Hot Spot Analysis (Getis-Ord Gi*)
distance = isa.getOutput(2)
hs = SS.HotSpots(ce, "ICOUNT", "911HotSpots.shp", "Fixed Distance Band",
"Euclidean Distance", "None", distance, "", "")
except arcpy.ExecuteError:
# If an error occurred when running the tool, print out the error message.
print(arcpy.GetMessages())