This document is archived and information here might be outdated.  Recommended version.


How to clip a raster dataset with an envelope or a dataset (ArcObjects .NET 10.4 SDK)

How to clip a raster dataset with an envelope or a dataset


Summary
This topic shows an easy way to clip a raster dataset with a given envelope or another dataset.

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:
  1. Create a Clip tool class object.
  2. Set the required tool input and output parameters.
  3. Set the template dataset parameter if clipping with a dataset.
  4. Set the clipping envelope parameter if clipping with an envelope.
  5. 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):
Development licensing Deployment licensing
ArcGIS for Desktop Basic ArcGIS for Desktop Basic
ArcGIS for Desktop Standard ArcGIS for Desktop Standard
ArcGIS for Desktop Advanced ArcGIS for Desktop Advanced
Engine Developer Kit Engine