How To: Clip a raster using the Clipping Geometry option
Instructions provided describe how to call the Clip tool in Python when a feature class or template raster is used as clipping geometry.
From ArcGIS 9.3, the Clip (management) tool allows a template feature class or raster dataset to be specified as the extent for clipping.
However, because the 'rectangle' parameter of this tool is required, when the tool is called in Python, a value must be specified, even though the tool uses the extent of the clipping feature. The correctness of the extent does not matter when the clipping feature is used.
In ArcGIS 9.3 and 9.3.1, any 'rectangle' can be specified in the Clip tool when a template is specified. The tool uses the extent of the template.
Starting in ArcGIS 10.0, if the ArcPy Python package is used, write "#" for the 'rectangle' parameter, instead of assigning a dummy extent.
Depending on the Python package, select the appropriate script below.
- For the arcgisscripting package:
##Clip Raster Dataset with feature geometry import arcgisscripting gp = arcgisscripting.create() gp.Clip_management("c:/image.tif", "0 0 1 1", "c:/clip.tif","c:/feature.shp", "0", "ClippingGeometry")
- For the ArcPy package:
##Clip Raster Dataset with feature geometry import arcpy arcpy.Clip_management("c:/image.tif", "#", "c:/clip.tif","c:/feature.shp", "0", "ClippingGeometry")