Managing output from Spatial Analyst tools in Map Algebra

The primary raster output of a Spatial Analyst Map Algebra expression is a Raster object. One of the most important behaviors of a Raster object is that when it is created as primary output from a Spatial Analyst Map Algebra expression, it references a temporary raster. Temporary data, unless it is explicitly saved, will be removed when the ArcGIS session or script ends.

Saving a temporary raster

A temporary raster can be permanently saved by using the save method on the Raster object. If the temporary data has a layer associated with it, the data can also be saved through the layer's context menu or by saving the map document. These three methods of saving are expounded below:

  1. A temporary raster can be saved by using the save method. In the example below, the temporary output from the Slope tool is saved to the specified output folder.
    outraster = Slope("C:/Data/elevation") 
    outraster.save("C:/output/sloperaster")
    
    • Where the data is saved depends on what you enter in the save method and what workspace environments you have set.

      1. When the full path, with dataset name, is specified, then this location is where the permanent data will be saved.
      2. If only a dataset name is specified, then the location of the saved data is determined by the geoprocessing workspace environments.
        • If the scratch or the current workspace is set, then the saved data will be saved to the location of the set workspace.
        • If both the current workspace and scratch workspace are set, then the saved data will be saved to the current workspace.
        • If no workspace is set, an error will be returned.

    • If you simply want to persist the data where it is with its default name, then call the save method without specifying a name, as shown in the example below:
      outraster.save()
    • The save method supports all raster formats supported by Spatial Analyst. In the example below the raster save method is used to save data to a file geodatabase raster and to IMAGINE format.
      outraster.save("C:/output/file_gdb.gdb/sloperaster")
      outraster.save("C:/output/sloperaster.img")
  2. To save a temporary dataset associated with a map layer, right-click the layer and select Data > Make Permanent and provide an output location and name.
  3. To persist a temporary raster dataset associated with a map layer, save the Map Document. When the Map Document is saved, the raster dataset persists to disk at its current location with its autogenerated name.

Interaction of a Raster object, layer, and dataset

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.

For more information on the interaction of Raster objects, see The interaction of the raster object in ArcGIS.

Related Topics


6/28/2013