Extract by Rectangle (Spatial Analyst)

License Level:BasicStandardAdvanced

Summary

Extracts the cells of a raster based on a rectangle.

Usage

Syntax

ExtractByRectangle (in_raster, rectangle, {extraction_area})
ParameterExplanationData Type
in_raster

The input raster from which cells will be extracted.

Raster Layer
rectangle
extent

A rectangle that defines the area to be extracted. An Extent object is used to specify the coordinates.

The form of the object is:

  • Extent(XMin, YMin, XMax, YMax)

    where XMin and YMin define the lower-left coordinates of the area to be extracted, and XMax and YMax define the upper-right coordinates.

The coordinates are specified in the same map units as the in_raster.

Extent
extraction_area
(Optional)

Identifies whether to extract cells inside or outside the input rectangle.

  • INSIDE A keyword specifying that the cells inside the input rectangle should be selected and written to the output raster. All cells outside the rectangle will receive NoData values on the output raster.
  • OUTSIDE A keyword specifying that the cells outside the input rectangle should be selected and written to the output raster. All cells inside the rectangle will receive NoData values on the output raster.
String

Return Value

NameExplanationData Type
out_raster

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

Raster

Code Sample

ExtractByRectangle example 1 (Python window)

This example extracts cells outside a rectangular extent to a new raster.

import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
rectExtract = ExtractByRectangle("elevation", 
                                 Extent(477625, 213900, 486400, 224200), 
                                 "OUTSIDE")
rectExtract.save("c:/sapyexamples/output/extrect")
ExtractByRectangle example 2 (stand-alone script)

This example extracts cells inside a rectangular extent to a new raster.

# Name: ExtractByRectangle_Ex_02.py
# Description: 
# 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"
inRectangle = Extent(477625, 213900, 486400, 224200)

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

# Execute ExtractByRectangle
rectExtract = ExtractByRectangle(inRaster, inRectangle, "INSIDE")

# Save the output 
rectExtract.save("c:/sapyexamples/output/extrect02")

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
4/10/2014