Skip to main content

Since you have the Python tag, the following example is how you would accomplish this task using raster algebra in Python. Here I am assuming you have a variety of rasters in one GDB with a unique ID for each pair. The output is written to a separate folder in .tif format.

import arcpy, os
from arcpy.sa import *
arcpy.CheckOutExtension ("Spatial")

arcpy.env.workspace = r'C:\temp\temp.gdb'
inws  = arcpy.env.workspace
outws = r'C:\temp\out'

# List all of the "forestmask" rasters
rasters = arcpy.ListRasters("*forestmask*")

# 1) Assuming there is a "loss" counterpart with a unique ID
# 2) Loop through your raster list
for r in rasters:
    # Extract prefix and suffix for naming purposes later
    prefix = r.split("_")[0] + "_"  # Get just the prefix
    suffix = "_" + r.split("_")[2] + "_" + r.split("_")[3] # Get just the suffix

    # Define the "forestmask" and "loss" paths
    forestmask = os.path.join(inws, r)
    loss       = os.path.join(inws, r.replace("forestmask", "loss")) # Replace "forestmask" with "loss"

    # Convert these to raster objects
    r1 = Raster(forestmask)
    r2 = Raster(loss)

    # perform the raster algebra
    mycalc = r1 * r2

    # Save to disk (write to .tif)
    mycalc.save(os.path.join(outws, prefix + "deforestation" + suffix + ".tif"))
arcpy.CheckInExtension ("Spatial")

      
Aaron
  • 51.8k
  • 29
  • 157
  • 322