How to access geoprocessing tools and toolboxes


This document was published with and applies to ArcGIS 9.3.
A 9.2 version also exists.

Accessing geoprocessing tools and toolboxes

Each existing geoprocessing toolbox is represented by a managed assembly. You can find these assemblies in the \Dotnet\Toolboxes subfolder of your ArcGIS installation. In each toolbox assembly there are classes representing each geoprocessing tool in the standard ArcGIS geoprocessing toolboxes. You can use these classes to set up and run geoprocessing tools with the geoprocessor class.
 
To set up a geoprocessing tool class, set properties to indicate the inputs to a tool. You must ensure all the properties marked as Required are set; you may also want to set properties marked as Optional. To simplify matters, each class has a parameterized constructor, allowing you to initialize the tool with all the required properties in one line of code. See the following example that shows how to access the Erase tool and set its parameters:
 

[C#]
using ESRI.ArcGIS.Geoprocessor;
using ESRI.ArcGIS.AnalysisTools;

public void SampleEraseTool_1()
{

  // Initialize the geoprocessor. 
  Geoprocessor GP = new Geoprocessor();
  Erase eraseTool = new Erase(@"C:\Data\Input.shp", @"C:\Data\Erase.shp", @
    "C:\Data\Output.shp");

  // TODO: Add your code here...

}

[VB.NET]
Imports ESRI.ArcGIS.Geoprocessor
Imports ESRI.ArcGIS.AnalysisTools

Public Sub SampleEraseTool_1()
    
    ' Initialize the geoprocessor.
    Dim GP As Geoprocessor = New Geoprocessor()
    
    'Note: Erase is a reserved keyword in VB.NET. You can either embed the keyword in brackets [], ie. [Erase]
    'or you can use the fully qualified namespace to avoid ambiguity, ie. ESRI.ArcGIS.AnalysisTools.Erase
    Dim eraseTool As [Erase] = New [Erase]("C:\Data\Input.shp", "C:\Data\Erase.shp", "C:\Data\Output.shp")
    
    'TODO: Add your code here...
    
End Sub
Or use the following code example:
 

[C#]
using ESRI.ArcGIS.Geoprocessor;
using ESRI.ArcGIS.AnalysisTools;

public void SampleEraseTool_2()
{

  Erase eraseTool = new Erase();
  eraseTool.in_features = @"C:\Data\Input.shp";
  eraseTool.erase_features = @"C:\Data\Erase.shp";
  eraseTool.out_feature_class = @"C:\Data\output.shp";

  // TODO: Add your code here...

}

[VB.NET]
Imports ESRI.ArcGIS.Geoprocessor
Imports ESRI.ArcGIS.AnalysisTools

Public Sub SampleEraseTool_2()
    
    'Note: Erase is a reserved keyword in VB.NET. You can either embed the keyword in brackets [], ie. [Erase]
    'or you can use the fully qualified namespace to avoid ambiguity, ie. ESRI.ArcGIS.AnalysisTools.Erase
    Dim eraseTool As [Erase] = New [Erase]()
    eraseTool.in_features = "C:\Data\Input.shp"
    eraseTool.erase_features = "C:\Data\Erase.shp"
    eraseTool.out_feature_class = "C:\Data\output.shp"
    
    'TODO: Add your code here...
    
End Sub