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. This is the 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
    print "The nearest neighbor index is: " + nn_output[0]
    print "The z-score of the nearest neighbor index is: " + nn_output[1]
    print "The p-value of the nearest neighbor index is: " + nn_output[2]
    print "The expected mean distance is: " + nn_output[3]
    print "The observed mean distance is: " + nn_output[4]
    print "The path of the HTML report: " + nn_output[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. When the Output Coordinate System is based on degrees, minutes, and seconds, geodesic distances are estimated using chordal distances.

Related Topics

Licensing Information

ArcGIS for Desktop Basic: Yes
ArcGIS for Desktop Standard: Yes
ArcGIS for Desktop Advanced: Yes
8/26/2014