I am using python script tools for ArcGIS 10.2, under Windows 8.1 64bit.
When I am using the arcpy.GetRasterProperties_management() command, it's very slow to process the data.
For example. I tried to get the maximum value for 14 rasters, if I use the batch mode of the system tool: Get Raster Properties, it uses only 0.19 seconds.
But when I am using python script tools to do this, it basically takes 1 second to print 1 value on the screen. So it takes 15 seconds to get the maximum value of the 14 rasters. So when I have hundreds of rasters to process, it takes too much time.
And this is when the CPU usage is 20%, which is the maximum usage when running ArcGIS on my laptop, sometimes the CPU couldn't even get there, when the usage is only 5 or 6%, it takes one minute to get all the values.
this is the code I use for this part:
for out_raster in out_rasters:
try:
raster_min = arcpy.GetRasterProperties_management(out_raster,"MINIMUM")
raster_min = raster_min.getOutput(0)
arcpy.AddMessage(raster_min)
except:
arcpy.AddMessage("No_data")
Is there any way I can increase the speed?
Best Answer
You ask, 'so is there any way I can increase the speed?'
Geoprocessing calls like
arcpy.GetRasterProperties_management()
are slow calls. Using thearcpy
objects, in this caseRaster
and accessing its propertyminimum
will generally (most likely always) be faster.Specifically one way to speed your script up would be to use:
to get the minimum value. Quick testing on my machine in looping over raster paths and using your method:
took twice as long to complete each call as the
Raster
object method.