Available with Spatial Analyst license.
Summary
Extracts the cells of a raster based on a rectangle by specifying the rectangle's extent.
Illustration
Usage
The center of the cell is used to determine whether a cell is inside or outside a rectangle. If the center is within the outline of a rectangle, the cell is considered fully inside even if portions of the cell fall outside the rectangle.
Cell locations that are not selected are assigned a value of NoData.
When a multiband raster is specified as input, a new multiband raster will be created as output. Each individual band in the input multiband raster will be analyzed accordingly.
The default output format is a geodatabase raster. If an Esri Grid stack is specified as the output format, note that the name cannot start with a number, use spaces, or be more than nine characters in length.
If the input is a layer created from a multiband raster with more than three bands, the extraction operation will only consider the bands that were loaded (symbolized) by the layer. As a result, the output multiband raster can only have three bands, corresponding to those used in the display of the input layer.
If the input raster is integer, the output raster will be integer. If the input is floating point, the output will be floating point.
See Analysis environments and Spatial Analyst for additional details on the geoprocessing environments that apply to this tool.
Syntax
ExtractByRectangle (in_raster, rectangle, {extraction_area})
Parameter | Explanation | Data 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:
The coordinates are specified in the same map units as the input raster. | Extent |
extraction_area (Optional) | Identifies whether to extract cells inside or outside the input rectangle.
| String |
Return Value
Name | Explanation | Data 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
Licensing information
- ArcGIS Desktop Basic: Requires Spatial Analyst
- ArcGIS Desktop Standard: Requires Spatial Analyst
- ArcGIS Desktop Advanced: Requires Spatial Analyst