Python Won't Run Spatial Autocorrelation Script Twice

10-09-2012 10:38 AM
New Contributor II

I'm trying to calculate a Global Moran's I statistic on a [long] list of point files using python.  I have set up my code to loop through the arcpy.SpatialAutocorrelation_stats script as shown below.  The loop runs through the first shapefile without a problem and prints out the Moran's I Summary Table.  When it gets to the second shapefile, it crashes with a strange error. 

I can manually run the Spatial Autocorrelation Script in batch form without a problem from ArcCatalog.  However, I don't want to parse through the Results window later. 

I am using ArcGIS 10.1 with Python XY (Spyder) 2.7 on a Windows 7 64-bit machine.

Has anyone encountered this error or found any solutions?


import arcpy
dataPath = r"c:\data"
elevationPoints = ["elevPts1.shp", "elevPts2.shp"]
elevationPoints = ["id_1pt.shp","id_11pt.shp"]
dataPath = r"C:\Users\Andy\Desktop\BlackbirdKnob_WV\tempPts"
for i in range(len(elevationPoints)):
    arcpy.SpatialAutocorrelation_stats (dataPath+"\\"+elevationPoints, "GRID_CODE", "NO_REPORT" , "FIXED_DISTANCE_BAND", "EUCLIDEAN_DISTANCE" ,"NONE","15")

This is the error message that comes up:
Traceback (most recent call last):
  File "C:\Users\Andy\Desktop\", line 20, in <module>
    arcpy.SpatialAutocorrelation_stats (dataPath+"\\"+elevationPoints, "GRID_CODE", "NO_REPORT" , "FIXED_DISTANCE_BAND", "EUCLIDEAN_DISTANCE" ,"NONE","15")
  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\", line 403, in SpatialAutocorrelation
    raise e
Traceback (most recent call last):
  File "c:\program files (x86)\arcgis\desktop10.1\ArcToolbox\Scripts\", line 21, in <module>
    import SSReport as REPORT
  File "c:\program files (x86)\arcgis\desktop10.1\ArcToolbox\Scripts\", line 17, in <module>
    import pylab as PYLAB
  File "C:\Python27\lib\site-packages\", line 1, in <module>
    from matplotlib.pylab import *
  File "C:\Python27\lib\site-packages\matplotlib\", line 264, in <module>
    from matplotlib.pyplot import *
  File "C:\Python27\lib\site-packages\matplotlib\", line 23, in <module>
    from matplotlib.figure import Figure, figaspect
  File "C:\Python27\lib\site-packages\matplotlib\", line 18, in <module>
    from axes import Axes, SubplotBase, subplot_class_factory
  File "C:\Python27\lib\site-packages\matplotlib\", line 338, in <module>
    class Axes(martist.Artist):
  File "C:\Python27\lib\site-packages\matplotlib\", line 2051, in Axes
    def grid(self, b=None, which='major', axis='both', **kwargs):
  File "C:\Python27\lib\site-packages\matplotlib\", line 103, in dedent_interpd
    return interpd(dedent(func))
  File "C:\Python27\lib\site-packages\matplotlib\", line 36, in __call__
    func.__doc__ = func.__doc__ and func.__doc__ % self.params
KeyError: 'Line2D'

Failed to execute (SpatialAutocorrelation).
Tags (2)
0 Kudos
2 Replies
New Contributor II
Found a temporary fix.  Since it seems that the the first few errors were being derived from the module within the SpatialAutocorrelation_stat tool, it was re-loaded in the script with hopes that it would resolve the problem.  It worked, but is still a bit of an odd work-around.  See the below code that allowed the Spatial Autocorrelation tool to be iteratively executed:

import arcpy
dataPath = r"c:\data"
elevationPoints = ["elevPts1.shp", "elevPts2.shp"]
for i in range(len(elevationPoints)):
    import MoransI
    arcpy.SpatialAutocorrelation_stats (dataPath+"\\"+elevationPoints, "GRID_CODE", "#" , "FIXED_DISTANCE_BAND", "EUCLIDEAN_DISTANCE" ,"NONE","15")

0 Kudos
New Contributor

i have an error also regarding spatial autocorrelation (moran;s I):

Executing: SpatialAutocorrelation calculationdepth FID_tmhous NO_REPORT INVERSE_DISTANCE EUCLIDEAN_DISTANCE NONE # #

Start Time: Tue Jul 08 15:35:41 2014

Running script SpatialAutocorrelation...

WARNING 000853: The default neighborhood search threshold was 7349.512418 Meters.

Traceback (most recent call last):

  File "c:\program files\arcgis\desktop10.1\ArcToolbox\Scripts\", line 610, in <module>


  File "c:\program files\arcgis\desktop10.1\ArcToolbox\Scripts\", line 88, in setupGlobalI

    threshold = threshold, exponent = exponent)

  File "c:\program files\arcgis\desktop10.1\ArcToolbox\Scripts\", line 157, in __init__


  File "c:\program files\arcgis\desktop10.1\ArcToolbox\Scripts\", line 361, in construct

    nhVals, weights)

  File "c:\program files\arcgis\desktop10.1\ArcToolbox\Scripts\", line 405, in processRow

    self.wij[ij] = w


Failed to execute (SpatialAutocorrelation).

Failed at Tue Jul 08 15:36:01 2014 (Elapsed Time: 20.00 seconds)

i already looked the same error in the internet but nobody tried to answer this question (from other people)..

i hope someone could help me...-.- please

0 Kudos