Average Nearest Neighbor (Spatial Statistics)

License Level:BasicStandardAdvanced

Summary

Calculates a nearest neighbor index based on the average distance from each feature to its nearest neighboring feature.

You can access the results of this tool (including the optional report file) from the Results window. If you disable background processing, results will also be written to the Progress dialog box.

Learn more about how Average Nearest Neighbor Distance works

Illustration

Average Nearest Neighbor illustration

Usage

Syntax

AverageNearestNeighbor_stats (Input_Feature_Class, Distance_Method, {Generate_Report}, {Area})
ParameterExplanationData Type
Input_Feature_Class

The feature class, typically a point feature class, for which the average nearest neighbor distance will be calculated.

Feature Layer
Distance_Method

Specifies how distances are calculated from each feature to neighboring features.

  • EUCLIDEAN_DISTANCEThe straight-line distance between two points (as the crow flies)
  • MANHATTAN_DISTANCEThe distance between two points measured along axes at right angles (city block); calculated by summing the (absolute) difference between the x- and y-coordinates
String
Generate_Report
(Optional)
  • NO_REPORTNo graphical summary will be created (default).
  • GENERATE_REPORTA graphical summary will be created as an HTML file.
Boolean
Area
(Optional)

A numeric value representing the study area size. The default value is the area of the minimum enclosing rectangle that would encompass all features (or all selected features). Units should match those for the Output Coordinate System.

Double

Code Sample

AverageNearestNeighbor example 1 (Python window)

The following Python window script demonstrates how to use the AverageNearestNeighbor tool.

import arcpy
arcpy.env.workspace = r"C:\data"
arcpy.AverageNearestNeighbor_stats("burglaries.shp", "EUCLIDEAN_DISTANCE", "NO_REPORT", "#")
AverageNearestNeighbor example 2 (stand-alone Python script)

The following stand-alone Python script demonstrates how to use the AverageNearestNeighbor tool.

# Analyze crime data to determine if spatial patterns are statistically significant
 
# Import system modules
import arcpy
 
# Local variables...
workspace = "C:/data"
crime_data = "burglaries.shp"
 
try:
    # Set the current workspace (to avoid having to specify the full path to the feature classes each time)
    arcpy.env.workspace = workspace
 
    # Obtain Nearest Neighbor Ratio and z-score
    # Process: Average Nearest Neighbor...
    nn_output = arcpy.AverageNearestNeighbor_stats(crime_data, "EUCLIDEAN_DISTANCE", "NO_REPORT", "#")
    
    # Create list of Average Nearest Neighbor output values by splitting the result object
    nn_values = nn_output.split(";")
    print "The nearest neighbor index is: " + nn_values[0]
    print "The z-score of the nearest neighbor index is: " + nn_values[1]
    print "The p-value of the nearest neighbor index is: " + nn_values[2]
    print "The expected mean distance is: " + nn_values[3]
    print "The observed mean distance is: " + nn_values[4]
    print "The path of the HTML report: " + nn_values[5]
 
except:
    # If an error occurred when running the tool, print out the error message.
    print arcpy.GetMessages()

Environments

Output Coordinate System

Feature geometry is projected to the Output Coordinate System prior to analysis. All mathematical computations are based on the Output Coordinate System spatial reference.

Related Topics

Licensing Information

ArcGIS for Desktop Basic: Yes
ArcGIS for Desktop Standard: Yes
ArcGIS for Desktop Advanced: Yes
4/18/2013