Average Nearest Neighbor (Spatial Statistics)


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

Learn more about how Average Nearest Neighbor Distance works


Average Nearest Neighbor illustration



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

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

Feature Layer

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
  • NO_REPORTNo graphical summary will be created (default).
  • GENERATE_REPORTA graphical summary will be created as an HTML file.

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.


Code Sample

AverageNearestNeighbor Example (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 (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"
    # 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]
    # If an error occurred when running the tool, print out the error message.
    print arcpy.GetMessages()


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

ArcView: Yes
ArcEditor: Yes
ArcInfo: Yes