Extract by Polygon

Extracts the cells of a raster based on a polygon.


Usage Tips

Syntax

ExtractByPolygon_sa (in_raster, polygon, out_raster, extraction_area)
Parameter Explanation Datatype
Input raster (Required)

Input raster.

Composite Geodataset
Polygon (Required)

Polygon that defines the area to be extracted.

X,Y coordinates define the vertices of the polygon.

Point
Output raster (Required)

The raster to be created.

Raster Dataset
Extraction area (Optional)

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

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

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

String
Data types for geoprocessing tool parameters

Script Example

# ExtractByPolygon_sample.py
# Description:
#   Extracts the cells of a raster based on a polygon.
# Requirements: None
# Author: ESRI
# Date: Sept 6, 2005

# Import system modules
import arcgisscripting

# Create the Geoprocessor object
gp = arcgisscripting.create()

try:
    # Set local variables
    InRaster = "C:/data/raster1"
    InPolygon = "0 0;1 1;2 2;3 3;4 4;5 3;6 2;7 1;8 0"
    OutRaster = "C:/data/final_1"

    # Check out Spatial Analyst extension license
    gp.CheckOutExtension("Spatial")

    # Process: ExtractByPolygon
    gp.ExtractByPolygon_sa(InRaster, InPolygon, OutRaster, "OUTSIDE")

except:
    # If an error occurred while running a tool, then print the messages.
    print gp.GetMessages()

Map Algebra syntax

See SelectPolygon


ArcObjects syntax

See Polygon


See Also

  • Extract by Attributes
  • Extract by Mask
  • An overview of the Extraction tools