1

I have a problem using Zonal statistics in python using ArcMap 10.4. This is a completely random error, and I have no idea what to do. Some back ground is that I have been running a script doing batch processing work with zonal stats and extracting values etc. and it worked fine for various areas. All of a sudden the zonal statistics stopped working. There is no error, the program just ends abruptly.

I have tried to debug it in many ways (different environmental settings etc.) but here is the core of my problem:

A simple version of the program is as follow:

import os

import arcpy

from arcpy import env

from arcpy.sa import *

arcpy.CheckOutExtension("Spatial")

from decimal import Decimal

location = "C:/Users/Me/"

shapefile = "C:/Users/Me/My_shapefile.shp"

raster = "//server_location/raster_location/raster_file.tif"

print "Start Zonal"

outZonalStatistics = ZonalStatistics(shapefile, "Valid_ID", raster, "MEAN", "DATA")

print "Done"

print "Saving"

outZonalStatistics.save(location + "mean_zonal")

print "Done"

Then the output is as follow:

>>> Start Zonal
>>> ================================ RESTART =================================
>>>

Thus the program just abruptly ends when Zonal Stats is being called.

1

I have found the solution. It is a low level problem that I do not understand in full, however just changing the scratch workspace fixes the bug. Perhaps the default scratch workspace has a certain limit that is reached, then it needs to change. Here is a read for more information: https://geonet.esri.com/thread/86027

The code I used is the standard for changing the scratch workspace:

arcpy.env.scratchWorkspace = "C:/Users/Me/ArcMap_scratch"

  • This matches the clue that it worked for several areas then suddenly stopped working. Good work. – alexGIS Jun 1 '16 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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