FAQ: Why must arcpy.sa functions be assigned to a variable?
Why must arcpy.sa functions be assigned to a variable?
The arcpy.sa functions are temporary, therefore, the arcpy.sa function must be assigned to a variable. Otherwise, the output does not persist, and is unusable in scripts.
A variable holds references to data. In this example, the raster object created with an arcpy.sa function is stored in a variable named Solar.
from arcpy.sa import *;
arcpy.CheckoutExtension ("Spatial"); #Code used to check the extension in ArcMap
Solar = arcpy.sa.AreaSolarRadiation (inRaster, latitude, time);
# the code segment uses the arcpy.sa
The output raster is temporary by default. Due to the volatile nature of the output raster, it must be assigned to a variable to retain the output raster value.
- ArcGIS Web Help: The interaction of the Raster object in ArcGIS
- ArcGIS Web Help: Using in-memory workspace
- ArcGIS Web Help: Extending geoprocessing through Python modules