Hello,I'd like to run an Average Nearest Neighbour analysis for a number of different layers (multiple habitat types). The Average Nearest Neighbour tool seems to fit what I want to do, except that it only runs one at a time, and the only way to access the results is through the results window. I have to go through all of the results and write down the answers so that I can put them into a table. Is there any way to get the tool to write the results to a table? I've go quite a few of these to do!I found a toolbox and python script that someone had helpfully created on an archived forum from 2007; it creates a csv. file (http://forums.esri.com/Thread.asp?c=93&f=983&t=233103). But it won't run properly -it was possibly intended for an earlier version of Arc (I'm running ArcGIS 10). I don't know much about python script etc so I don't know how to fix it. Can anyone help?Or if there are any other ideas I'd appreciate it!A
# Name: ANN [AverageNearestNeighbor].py # Description: AverageNearestNeighbor for FC in Datasets. Also export results to csv file. # Created by: Omar Barrantes; obarrantes@gmail.com import arcinfo, arcpy, glob, os, string, sys, arcgisscripting, math from arcpy import env, mapping, conversion, sa # Workspace arcpy.env.workspace = r"D:/Data/Landscape.gdb" out_feature_class = r"D:/Data/Landscape.gdb" # Display workspace print 'workspace: ' + out_feature_class # Geoprocessor object gp = arcgisscripting.create() gp.overwriteoutput = True # Tables output path path = r"D:/Data/Tables/ANN/" # Search for feature classes datasets name start with "Land" datasetList = arcpy.ListDatasets("Land*", "All") for dataset in datasetList: # Search for feature classes name start with "Biometric" FileList=arcpy.ListFeatureClasses("Biometric*", "", dataset) # FileList.sort() for File in FileList: print "File: " + str(File) desc = arcpy.Describe(File) SFR = desc.featureType # Example "Simple" SST = desc.shapeType # Example "Polygon", "Polyline", "Point" #List of unique landscape codes from [UP] Field field = "UP" valueList = [] List = [] rows = arcpy.SearchCursor(File) for row in rows: valueList.append(row.getValue(field)) uniqueSet = set(valueList) uniqueList = list(uniqueSet) uniqueList.sort() List = uniqueList del rows del row print uniqueList NoSelectCount = 0 outFile = open(path+str(File)+"_ANN"+".csv", 'a') outFile.write('FC,UP,ANN_INDEX,ZSCORE,PSCORE,EMEAN,OMEAN,CA\n') for row in uniqueList: print "Class " + str(row) # Layer feature class layername = str(File) + '_'+ str(row) NoSelectCount=NoSelectCount+1 where = " \"UP\" = " + "'" + row + "'" where2 = ' "UP" = ' + '"' + row + '"' arcpy.MakeFeatureLayer_management(File, layername, where) # Create search cursor rows1 = arcpy.SearchCursor(layername) # Class Area from landscape CA= 0 shapeName = arcpy.Describe(layername).shapeFieldName for row1 in rows1: feat = row1.getValue(shapeName) CA += feat.area nn_output = arcpy.AverageNearestNeighbor_stats(layername, "EUCLIDEAN_DISTANCE", "GENERATE_REPORT", "#") index = nn_output[0] zscore = nn_output[1] pscore = nn_output[2] emean = nn_output[3] omean = nn_output[4] print arcpy.GetMessages() outFile.write('%s,%s,%s,%s,%s,%s,%s,%s\n' %(str(File),str(row),index,zscore,pscore,emean,omean,CA)) outFile.close() print ("Done ......")
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.