Extract by Rectangle (Spatial Analyst)

Available with Spatial Analyst license.

Summary

Extracts the cells of a raster based on a rectangle by specifying the rectangle's extent.

Illustration

Extract by Rectangle tool illustration
OutRas = ExtractByRectangle(InRas1, Extent(1, 0, 5, 5), "INSIDE")

Usage

  • Additional attributes from the input raster, if any, will be carried over as-is to the output raster attribute table. Depending on the property being recorded, some of the attribute values may need to be recalculated.

  • When a multiband raster is specified as the Input Raster (in_raster in Python) value, all bands will be used.

    To process a selection of bands from a multiband raster, first create a raster dataset composed of those particular bands using the Composite Bands tool. Then use the result as the Input Raster (in_raster in Python) value.

    The default output format is a geodatabase raster. If an Esri Grid stack is specified as the output format, the name of the stack cannot start with a number, use spaces, or be more than nine characters in length.

  • 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 are outside the rectangle.

  • Cell locations that are not selected are assigned a value of NoData.

  • 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.

Parameters

LabelExplanationData Type
Input raster

The input raster from which cells will be extracted.

Raster Layer
Extent

A rectangle that defines the area to be extracted.

  • Current Display Extent Map View—The extent will be based on the active map or scene. This option is only available when there is an active map.
  • Draw Extent Square and Finish—The extent will be based on a rectangle drawn on the map or scene. This option will create a feature class in the project geodatabase and add a layer to the map. The feature class will have the same coordinate system as the map.
    Note:

    This option is not available in the Environments dialog box. It is only available from a tool parameter with an extent data type or from the Environments tab on a tool dialog box.

    Note:

    When the Enable and disable editing from the Edit tab editing option is checked, you must enable editing on the Edit ribbon tab to draw the extent.

  • Extent of a Layer Layer—The extent will be based on an active map layer. Use the drop-down list to choose an available layer or use the Extent of data in all layers option to get the combined extent of all active map layers, excluding the basemap. This option is only available when there is an active map with layers.

    Each map layer has the following options:

    • All Features Select All—The extent of all features in the layer.
    • Selected Features Area from Selected Features—The extent of the selected features in the layer.
    • Visible Features Extent Indicator—The extent of the visible features in the layer.
      Note:

      The extents from the Selected Features Area from Selected Features and Visible Features Extent Indicator options are only available for feature layers.

  • Browse Browse—The extent will be based on an existing dataset.
  • Clipboard Paste—The extent can be copied to and pasted from the clipboard.
    • Copy Extent Copy—Copies the extent coordinates and coordinate system to the clipboard.
    • Use Paste Extent Paste—Pastes the extent coordinates and, optionally, the coordinate system from the clipboard. If the clipboard values do not include a coordinate system, the extent will use the map’s coordinate system.
    Note:

    The extent coordinates are copied to and pasted from the clipboard using the same formatting and order as the ArcPy Extent object: x-min, y-min, x-max, y-max, and the spatial reference.

  • Reset Extent Reset—The extent will be reset to the default value.
  • Manually entered coordinates—The coordinates must be numeric values and in the active map's coordinate system.
    Caution:

    The map may use different display units than the entered coordinates. The use of a cardinal direction (N, S, E, W) is not supported. Use a negative value sign for south and west coordinates.

The coordinates are specified in the same map units as the input raster.

Extent
Extraction area
(Optional)

Specifies whether cells inside or outside the input rectangle will be selected and written to the output raster.

  • InsideCells inside the input rectangle will be selected and written to the output raster. All cells outside the rectangle will receive NoData values on the output raster.
  • OutsideCells outside the input rectangle will be selected and written to the output raster. All cells inside the rectangle will receive NoData values on the output raster.
String

Return Value

LabelExplanationData Type
Output raster

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

Raster

ExtractByRectangle(in_raster, rectangle, {extraction_area})
NameExplanationData 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.

  • MAXOF—The maximum extent of all inputs will be used.
  • MINOF—The minimum area common to all inputs will be used.
  • DISPLAY—The extent is equal to the visible display.
  • Layer name—The extent of the specified layer will be used.
  • Extent object—The extent of the specified object will be used.
  • Space delimited string of coordinates—The extent of the specified string will be used. Coordinates are expressed in the order of x-min, y-min, x-max, y-max.

The coordinates are specified in the same map units as the input raster.

Extent
extraction_area
(Optional)

Specifies whether cells inside or outside the input rectangle will be selected and written to the output raster.

  • INSIDECells inside the input rectangle will be selected and written to the output raster. All cells outside the rectangle will receive NoData values on the output raster.
  • OUTSIDECells outside the input rectangle will 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)

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

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

Licensing information

  • Basic: Requires Spatial Analyst
  • Standard: Requires Spatial Analyst
  • Advanced: Requires Spatial Analyst

Related topics