The interaction of the Raster object in ArcGIS

A Raster object references a raster dataset and, if used in ArcMap, may be associated with a raster layer in the table of contents. The relationships between the raster dataset, the Raster object, and the raster layer are maintained in most cases, but it is important to understand these relationships to work productively with Spatial Analyst Map Algebra.

Raster objects are created in two ways:

In some cases, a Raster object is associated with a raster layer. When working in the Python window, with the geoprocessing option Add result of the geoprocessing operations to the display checked on, the result of a Map Algebra expression is added to the table of contents with the same name as the Raster object. When a dataset is cast as a raster, no layer is added to the table of contents.

Saving temporary rasters

When data associated with the Raster object is temporary, it will be deleted when the ArcGIS session ends (the object goes out of scope, or the script completes). That is, unless the data is saved. When a raster is saved, the layer and object reflect the updated raster properties including name, path, catalogPath, and the isTemporary status of the dataset. There are several ways to save a temporary dataset.

Reusing a Raster object

Object names must be unique. When an object name is reused, then the original object is overwritten. In the example below, the output of Slope is replaced when outRas is reused as output of the Aspect expression.

outRas = Slope("inRas1") 
outRas = Aspect("inRas2")

Layers are added to the table of contents with the same name as the Raster object. When a Raster object name is reused, multiple layers with the same name will be added to the table of contents. In the example above, outRas is added to the table of contents twice. The first time is when the Slope expression is executed. This first outRas layer references the result of Slope and can be used in the Python window until the Aspect expression is executed. When Aspect is executed, a second layer called outRas is added to the table of contents, and the object will be overwritten and now references the dataset and layer resulting from Aspect.

TipTip:

If the Raster object referencing a dataset has been overwritten, the raster dataset can be recast as a Raster object by using the layer or dataset name.

Deleting a Raster object

When a Raster object is deleted, what happens to the associated dataset (and possible layer) depends on the status of the data. If the data is permanent, deleting the Raster object has no bearing on the associated dataset or layer. If a dataset is temporary, the effects of deleting the Raster object depend on if there is a layer also referencing the raster dataset. If there is no layer associated with the temporary dataset and the object is deleted, then the dataset is deleted. If there is a layer associated with the temporary dataset and the object is deleted, then the temporary data remains.

CautionCaution:
Temporary data referenced by a layer is not deleted when the Raster object is deleted; however, all temporary data is deleted when the application is closed, unless it is saved, regardless of existing layers or objects.

Below is an example of how to delete a Raster object called outRas .

outRas = Slope("C:/Data/elevation") 
del outRas

Assign the Raster object to a new Raster object

Assigning a Raster object to a new Raster object does not copy the associated dataset or layer. Assigning a Raster object to a new Raster object creates a second object that references the original object. In the example below, both outRas1 and outRas2 reference the same raster dataset.

outRas1 = Slope("elevation")  

# Assigns Raster object to a new Raster object and save the raster dataset
outRas2 = outRas1
outRas2.save("C:/output/outslope")

In the above example, both outRas1 and outRas2 reference the same dataset. Therefore, when outRas2 is saved, both objects will reflect the permanent status, the new location, and the new name of the saved dataset, outslope. If outRas1 is a layer in your table of contents and you persist the data through the layer property or by saving your map document, then both objects, outRas1 and outRas2, will reference the saved dataset.

Related Topics

3/7/2014