Using python I'm having problems when trying to attempt a FOR LOOP with the ZonalHistogram function of ArcGIS 10.1. It works fine if I use it only for one image but it gives me this error while for looping:

ExecuteError: ERROR 999999: Error executing function.
Create output table failed
Failed to execute (ZonalHistogram)

Here is my very simple script:

import arcpy
from arcpy.sa import *

arcpy.env.workspace = 'G:\\Chile_2012\\MODIS10A2.V005\\prova'

elev_ranges = 'G:\\Chile_2012\\MODIS10A2.V005\\DEM\\elev_ranges'
list = arcpy.ListRasters ()
out_dir = 'G:\\Chile_2012\\MODIS10A2.V005\\prova\\hypso\\'

arcpy.CheckOutExtension ('Spatial')

for raster in list:
    ZonalHistogram (raster, 'Value', elev_ranges, out_dir+ raster+ '.dbf')
  • Ok I found out that this is a problem of the service pack (downloads2.esri.com/support/downloads/other_/…). I then tried to save it as an in_memory object without specifying any name as suggested in the link above and it worked, but then how could I make this files permanent?
    – umbe1987
    Commented Sep 14, 2012 at 17:51

2 Answers 2



The problem was assigning a name to the output table (as specified in the "SP5 announcement" of ESRI). I created "in_memory" files by appending an 'in_memory' string at the end of the pathname, and made a list on the temporary tables created in this way to merge them with the "Merge" tool. Tyhen I deleted all the temporary files by using the "arcpy.Delete_management ('in_memory')" tool and it worked fine. Hope this could help someone in the future. Here is the link with some bugs of ESRI. http://downloads2.esri.com/support/downloads/other_/185410.0_SP5_Announcement.pdf

  • Anyway, it doesn't work properly, it gives a strange result that has nothing to do with the result coming from a single application of the Zonal tool. Something doesn't work when looping...
    – umbe1987
    Commented Sep 14, 2012 at 19:19

I have a vector with 23k polygons, and a raster with 8 class. Result: how many classes I have in each polygon?

This code is very simple and working for me.

from rasterstats import zonal_stats
stats = zonal_stats('myvector.shp','myraster.tif',categorical=True)
{0: 2, 1: 1, 2: 31, 3: 2, 4: 528, 7: 61}

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.