I am running an iterator in ModelBuilder that ultimately takes the output from each iteration (a point feature class) and runs the spatial auto-correlation tool (global Moran's I). I have about 450 output feature classes, and what I would like to have is the feature class name, index value, z-score, and p-value from each iteration (of Moran's I) added as a new record in a table. These values are reported in the .HTML report and the model run summary window, but I can't figure out how to extract them and add them to a table.

If I were doing this with a statistical model in R, I could simply call the model output values (index, p-value, etc.). But Ideally I would like to do this in ModelBuilder. I'm not opposed to writing a Python script, but before I go down that road I'm wondering if there's a more direct way to do it with existing geoprocessing or ModelBuilder tools.

As an additional note, I would also like to get the default calculated bandwith from the Kernel density tool output to a table similar to the Moran's I values.

I am running ArcGIS Pro 2.3.

1 Answer 1


Using the arcpy implementation of the spatial autocorrelation tool, you can get this information. Albeit, in a somewhat roundabout way.

Firstly, as per the documentation (example 2), if you set a variable called moransI to the actual call of the tool such as:

moransI = arcpy.SpatialAutocorrelation_stats("olsResults.shp", "Residual",
                        "NO_REPORT", "GET_SPATIAL_WEIGHTS_FROM_FILE", 
                        "EUCLIDEAN_DISTANCE", "NONE", "#", 

You'll get access to the getMessages function. This contains the full output text of the tool. And it's ugly:

"Start Time: Thursday, 21 March 2019 3:32:00 PM\nRunning script SpatialAutocorrelation...\nWARNING 001605: Distances for Geographic Coordinates (degrees, minutes, seconds) are analyzed using Chordal Distances in meters.\nWARNING 000846: 58 feature(s) had no neighbors which generally invalidates the statistical properties of a test.\nWARNING 000847: Features with no neighbors (only includes first 30): FID = 1186, 6475, 6634, 6712, 7563, 10078, 13157, 13518, 13941, 14496, 15894, 17155, 17156, 17195, 17363, 17365, 20442, 20986, 21047, 21171, 21350, 23587, 26744, 28141, 28153, 28615, 28982, 30519, 30520, 30768.\n\n Global Moran's I Summary \nMoran's Index: 0.210751 \nExpected Index: -0.000018 \nVariance: 0.000001 \nz-score: 176.055455\np-value: 0.000000 \n\nDistance measured in Meters\n\nCompleted script Spatial Autocorrelation (Global Moran's I)...\nSucceeded at Thursday, 21 March 2019 3:32:26 PM (Elapsed Time: 26.01 seconds)"

However, you can create a list for each line of text like so:

moranList = moransI.getMessages().split('\n')

Then, you can get all the summary values by accessing those items in the list:

moranIndex = moranList[-10]
ExpectedIndex = moranList[-9]
Variance = moranList[-8]
zScore = moranList[-7]
pValue = moranList[-6]

Of course, this will have some unwanted text, which I'll leave as an exercise. You'll just want to pull out the numbers from the strings.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.