ZonalStatistics Generates temporary files in scratch workspace and not memory?

333
1
12-30-2011 07:06 AM
MichalisAvraam
New Contributor III
I am attempting to run ZonalStatistics on a number of generated buffers (around 100,000) and record my results in a table.

I have managed to restrict myself to memory mostly, meaning the buffer files are generated in memory, passed on to ZonalStatistics as a memory feature class and it runs great. My problem is that zonal statistics, while it returns a variable to use in Python, also generates files in the scratch workspace. This is a big problem, as I run multiple zonal statistics per buffer (multiple source rasters) and with 100,000 buffers, this becomes a very big bottleneck for me.

Is there any way to set the output of Zonal Statistics to be completely in memory?

Or to set the whole scratch workspace in memory?

I know that the arcpy.gp.ZonalStatistics_sa that is called when you call zonal statistics has an out_raster parameter, but it is hard coded to "#" so i can't change it.

Thank you in advance.

Michalis
Tags (2)
0 Kudos
1 Reply
JakeSkinner
Esri Esteemed Contributor
Hi Michalis,

You should be able to specify the output raster parameter if you call the 'arcpy.gp.ZonalStatistics' function.  Ex:

# Local variables:
int_example1 = "C:\\DATA\\RASTER\\DEM\\int_example1"
example = "C:\\temp\\python\\zones.tif"
ZonalSt_int_1 = "C:\\temp\\python\\zonal_stats.tif"

# Process: Zonal Statistics
arcpy.gp.ZonalStatistics_sa(int_example1, "VALUE", example, ZonalSt_int_1, "MEAN", "DATA")


However, if you call the 'arcpy.sa.ZonalStatistics' function the raster will be written to a scratch workspace.  Ex:

# Local variables:
int_example1 = "C:\\DATA\\RASTER\\DEM\\int_example1"
example = "C:\\temp\\python\\zones.tif"
ZonalSt_int_1 = "C:\\temp\\python\\zonal_stats.tif"

# Process: Zonal Statistics
stats = arcpy.sa.ZonalStatistics(int_example1, "VALUE", example, "MEAN", "NODATA")


The raster will be removed from the scratch workspace if you save a hard copy.  For example you would add the following at the end:
stats.save(r"C:\temp\python\Zonal_Stats.tif")


I would recommend setting 'arcpy.env.overwriteOutput = True' and using the 'arcpy.gp.ZonalStatistics_sa' function.  With this function you can easily specify where you want the raster written to, and you can overwrite the output raster each time.
0 Kudos