Extract by Mask (Spatial Analyst)

License Level:BasicStandardAdvanced

Summary

Extracts the cells of a raster that correspond to the areas defined by a mask.

Illustration

Extract by Mask illustration
OutRas = ExtractByMask(InRas1, InRas2)

Usage

Syntax

ExtractByMask (in_raster, in_mask_data)
ParameterExplanationData Type
in_raster

The input raster from which cells will be extracted.

Raster Layer
in_mask_data

Input mask data defining areas to extract.

This is a raster or feature dataset.

When the input mask data is a raster, NoData cells on the mask will be assigned NoData values on the output raster.

Raster Layer | Feature Layer

Return Value

NameExplanationData Type
out_raster

The output raster containing the cell values extracted from the input raster.

Raster

Code Sample

ExtractByMask example 1 (Python window)

This example extracts cells from a raster within a mask defined by an input polygon shapefile feature class.

import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
outExtractByMask = ExtractByMask("elevation", "mask.shp")
outExtractByMask.save("C:/sapyexamples/output/maskextract")
ExtractByMask example 2 (stand-alone script)

This example extracts cells from a raster within a mask defined by an input polygon shapefile feature class.

# Name: ExtractByMask_Ex_02.py
# Description: Extracts the cells of a raster that correspond with the areas
#    defined by a mask.
# Requirements: Spatial Analyst Extension

# Import system modules
import arcpy
from arcpy import env
from arcpy.sa import *

# Set environment settings
env.workspace = "C:/sapyexamples/data"

# Set local variables
inRaster = "elevation"
inMaskData = "mask.shp"

# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")

# Execute ExtractByMask
outExtractByMask = ExtractByMask(inRaster, inMaskData)

# Save the output 
outExtractByMask.save("C:/sapyexamples/output/extractmask")

Environments

Related Topics

Licensing Information

ArcGIS for Desktop Basic: Requires Spatial Analyst
ArcGIS for Desktop Standard: Requires Spatial Analyst
ArcGIS for Desktop Advanced: Requires Spatial Analyst
11/8/2012