English

FAQ: Why must arcpy.sa functions be assigned to a variable?

Question

Why must arcpy.sa functions be assigned to a variable?

Answer

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.


Code:
import arcpy;
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.

Related Information