Clipping a raster dataset with an envelope or a dataset
The input raster dataset and output raster dataset can be in any format. The benefit of using the Clip geoprocessing tool is that the output raster dataset will be automatically cell aligned to the input raster dataset even though the specified clipping envelope does not cell align with the input raster dataset.
To clip a raster dataset with an envelope or a template dataset, follow these steps:
-
Create a Clip tool class object.
-
Set the required tool input and output parameters.
-
Set the template dataset parameter if clipping with a dataset.
-
Set the clipping envelope parameter if clipping with an envelope.
-
Initialize the geoprocessor, then execute the Clip tool.
See the following code example:
[C#] //Initialize the Clip tool class.
Clip clip=new Clip();
//Set the parameters.
clip.in_raster=@"c:\input\test.img";
clip.out_raster=@"c:\output\clip_test.img";
//The template dataset; its extent will be used to clip the input raster.
//Comment this line out if clipping with a given envelope.
clip.in_template_dataset=@"c:\base\clip_template.img";
//The clipping envelope.
//Comment this line out if clipping with a given dataset.
clip.rectangle="423850 5324600 423900 5324800";
//Initialize the geoprocessor and execute the Clip tool.
Geoprocessor geoprocessor=new Geoprocessor();
object outRaster=geoprocessor.Execute(clip, null);
[VB.NET] 'Initialize the Clip tool class.
Dim clip As Clip=New Clip()
'Set the parameters.
clip.in_raster="c:\input\test.img"
clip.out_raster="c:\output\clip_test.img"
'The template dataset; its extent will be used to clip the input raster.
'Comment this line out if clipping with a given envelope.
clip.in_template_dataset="c:\base\clip_template.img"
'The clipping envelope.
'Comment this line out if clipping with a given dataset.
clip.rectangle="423850 5324600 423900 5324800"
'Initialize the geoprocessor and execute the Clip tool.
Dim geoprocessor As Geoprocessor=New Geoprocessor()
Dim outRaster As Object=geoprocessor.Execute(clip, Nothing)
To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
- ESRI.ArcGIS.Geoprocessor
- ESRI.ArcGIS.System (ESRI.ArcGIS.esriSystem)
Development licensing | Deployment licensing |
---|---|
ArcGIS Desktop Basic | ArcGIS Desktop Basic |
ArcGIS Desktop Standard | ArcGIS Desktop Standard |
ArcGIS Desktop Advanced | ArcGIS Desktop Advanced |
Engine Developer Kit | Engine |