Average Nearest Neighbor (Spatial Statistics)

Summary

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

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
  • 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 (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"
 
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

ArcView: Yes
ArcEditor: Yes
ArcInfo: Yes

3/7/2012