Average Nearest Neighbor (Spatial Statistics)

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

Learn more about how Average Nearest Neighbor Distance works


Illustration

Average Nearest Neighbor illustration

Usage Tips

Syntax

AverageNearestNeighbor_stats (Input_Feature_Class, Distance_Method, Display_Output_Graphically, Area)
Parameter Explanation Datatype
Input Feature Class (Required)

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

Feature Layer
Distance Method (Required)

Specifies how distances are calculated in the nearest neighbor calculation.

  • Euclidean (as the crow flies)—The straight-line distance between two points.
  • Manhattan (city block)—The distance between two points measured along axes at right angles. Calculated by summing the (absolute) differences between point coordinates.

String
Display Output Graphically (Required)

Specifies whether the tool will display the nearest neighbor index graphically.

  • True—The output will be displayed graphically.
  • False—The output will not be displayed graphically.

Boolean
Area (Optional)

The area of the nearest neighbor analysis. The default area value is the area of the minimum enclosing rectangle. The units of this parameter are the input feature class' coordinate system's units squared.

Double
Data types for geoprocessing tool parameters

Script Example

# Analyze crime data to determine if spatial patterns are statistically significant

# Import system modules
import arcgisscripting

# Create the Geoprocessor object
gp = arcgisscripting.create()

# Local variables...
workspace = "C:/project93/data"
crime_data = "burglaries.shp"

try:
    # Set the current workspace (to avoid having to specify the full path to the feature classes each time)
    gp.workspace = workspace

    # Obtain Nearest Neighbor Ratio and Z Score
    # Process: Average Nearest Neighbor...
    nn_output = gp.AverageNearestNeighbor_stats(crime_data, "Euclidean Distance", "false", "#")
    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]

except:
    # If an error occurred when running the tool, print out the error message.
    print gp.GetMessages()

See Also

  • Spatial Autocorrelation (Morans I) (Spatial Statistics)
  • High/Low Clustering (Getis-Ord General G) (Spatial Statistics)
  • Modeling spatial relationships