<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Average Nearest Neighbour results table? in Spatial Statistics Questions</title>
    <link>https://community.esri.com/t5/spatial-statistics-questions/average-nearest-neighbour-results-table/m-p/299801#M1003</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I found a toolbox and python script that someone had helpfully created on an archived forum from 2007; it creates a csv. file (&lt;/SPAN&gt;&lt;A href="http://forums.esri.com/Thread.asp?c=93&amp;amp;f=983&amp;amp;t=233103"&gt;http://forums.esri.com/Thread.asp?c=93&amp;amp;f=983&amp;amp;t=233103&lt;/A&gt;&lt;SPAN&gt;). 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?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Or if there are any other ideas I'd appreciate it!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;A&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 08 Dec 2011 16:00:36 GMT</pubDate>
    <dc:creator>AnnaScott</dc:creator>
    <dc:date>2011-12-08T16:00:36Z</dc:date>
    <item>
      <title>Average Nearest Neighbour results table?</title>
      <link>https://community.esri.com/t5/spatial-statistics-questions/average-nearest-neighbour-results-table/m-p/299801#M1003</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I found a toolbox and python script that someone had helpfully created on an archived forum from 2007; it creates a csv. file (&lt;/SPAN&gt;&lt;A href="http://forums.esri.com/Thread.asp?c=93&amp;amp;f=983&amp;amp;t=233103"&gt;http://forums.esri.com/Thread.asp?c=93&amp;amp;f=983&amp;amp;t=233103&lt;/A&gt;&lt;SPAN&gt;). 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?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Or if there are any other ideas I'd appreciate it!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;A&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Dec 2011 16:00:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-statistics-questions/average-nearest-neighbour-results-table/m-p/299801#M1003</guid>
      <dc:creator>AnnaScott</dc:creator>
      <dc:date>2011-12-08T16:00:36Z</dc:date>
    </item>
    <item>
      <title>Re: Average Nearest Neighbour results table?</title>
      <link>https://community.esri.com/t5/spatial-statistics-questions/average-nearest-neighbour-results-table/m-p/299802#M1004</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;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!&lt;BR /&gt;&lt;BR /&gt;I found a toolbox and python script that someone had helpfully created on an archived forum from 2007; it creates a csv. file (&lt;A href="http://forums.esri.com/Thread.asp?c=93&amp;amp;f=983&amp;amp;t=233103" rel="nofollow noopener noreferrer" target="_blank"&gt;http://forums.esri.com/Thread.asp?c=93&amp;amp;f=983&amp;amp;t=233103&lt;/A&gt;). 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?&lt;BR /&gt;&lt;BR /&gt;Or if there are any other ideas I'd appreciate it!&lt;BR /&gt;&lt;BR /&gt;A&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hello Anna.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Like you, i need to run ANN for multiple layers in a fc datasets. As you remark, Luke Pinner's script &lt;/SPAN&gt;&lt;A href="http://forums.esri.com/Thread.asp?c=93&amp;amp;f=983&amp;amp;t=233103" rel="nofollow noopener noreferrer" target="_blank"&gt;http://forums.esri.com/Thread.asp?c=93&amp;amp;f=983&amp;amp;t=233103&lt;/A&gt;&lt;SPAN&gt;, was very helpful for the task to export results in csv file, after some modifications for my data, i wrote this script:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# 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: 
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Search for feature classes name start with "Biometric"
&amp;nbsp;&amp;nbsp;&amp;nbsp; FileList=arcpy.ListFeatureClasses("Biometric*", "", dataset) #
&amp;nbsp;&amp;nbsp;&amp;nbsp; FileList.sort()
&amp;nbsp;&amp;nbsp;&amp;nbsp; 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:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; valueList.append(row.getValue(field))
 uniqueSet = set(valueList)
 uniqueList = list(uniqueSet)
 uniqueList.sort()
 List = uniqueList
 del rows
 del row
 print uniqueList
 
 NoSelectCount = 0
&amp;nbsp; 
 outFile = open(path+str(File)+"_ANN"+".csv", 'a')
 outFile.write('FC,UP,ANN_INDEX,ZSCORE,PSCORE,EMEAN,OMEAN,CA\n') 
 for row in uniqueList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Class " + str(row)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Layer feature class
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layername = str(File) + '_'+ str(row)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NoSelectCount=NoSelectCount+1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where = " \"UP\" = " + "'" + row + "'"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where2 = ' "UP" = ' + '"' + row + '"'
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management(File, layername, where) 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Create search cursor
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows1 = arcpy.SearchCursor(layername)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Class Area from landscape
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CA= 0
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; shapeName = arcpy.Describe(layername).shapeFieldName
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row1 in rows1:
&amp;nbsp; feat = row1.getValue(shapeName)
&amp;nbsp; CA += feat.area
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; nn_output = arcpy.AverageNearestNeighbor_stats(layername, "EUCLIDEAN_DISTANCE", "GENERATE_REPORT", "#")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; index = nn_output[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; zscore = nn_output[1]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pscore = nn_output[2]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; emean = nn_output[3]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; omean = nn_output[4]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print arcpy.GetMessages()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outFile.write('%s,%s,%s,%s,%s,%s,%s,%s\n' %(str(File),str(row),index,zscore,pscore,emean,omean,CA))
 outFile.close()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
print ("Done ......") &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope work for you.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:22:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-statistics-questions/average-nearest-neighbour-results-table/m-p/299802#M1004</guid>
      <dc:creator>OmarBarrantes</dc:creator>
      <dc:date>2021-12-11T14:22:54Z</dc:date>
    </item>
  </channel>
</rss>

