Extracts the cells of a raster based on a polygon.
To extract based on a polygon in a featureclass instead of providing a series of x,y pairs you can use the Extract By Mask tool
If the input raster is integer, the output raster will be integer. If the input is floating point, the output will be floating point.
The center of the cell is used to determine whether a cell is inside or outside a polygon. If the center is within the arcs of the polygon, the cell is considered fully inside even if portions of the cell fall outside the polygon.
The polygon has a limit of 1,000 vertices. Polygon vertices must be entered in a clockwise order. The first and last vertex must be the same to close the polygon. The arcs of the polygon can cross one another, but convoluted polygons are not recommended.
Cell locations that are not selected are assigned values 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 an ESRI grid stack. Note that the name of an ESRI grid stack cannot start with a number, use spaces, or be more than 9 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.
| 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.
|
String |
# 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()