Geoprocessor managed assembly



About the Geoprocessor managed assembly

The Geoprocessing ArcObjects library has hundreds of classes and interfaces (components) to develop applications based on the geoprocessing framework. The GeoProcessor coclass is the most important class in this library. The IGeoProcessor2 interface of this coclass has all the methods and properties to perform most of your geoprocessing tasks. This GeoProcessor coclass is converted to a .NET wrapper assembly called Geoprocessor (the letter "p" is lowercase).
There are also managed assemblies for system toolboxes. This set of wrapper assemblies is available for geoprocessing in .NET. These assemblies are managed code as they implement the requirements to run in the common language runtime (CLR) and you have all the benefits of developing in a managed environment.
As most geoprocessing tasks work the same way—whether you use the managed assembly or the Geoprocessing library—this topic focuses only on functionalities exclusive to the wrapper assemblies.

Creating the geoprocessor object

Although you can do with most typical geoprocessing tasks with the wrappers, only the tool classes within the toolbox assemblies, and the methods and properties of the Geoprocessor
assembly are available through the wrappers. For any other functionality, for example, getting tool messages and listing data, you need the Geoprocessing library application programming interfaces (APIs).
To access the Geoprocessor assembly, you must reference the ESRI.ArcGIS.Geoprocessor namespace. The Geoprocessor class in this namespace is the wrapper of the IGeoProcessor2 interface of the GeoProcessor cocass of the Geoprocessing assembly. Create the Geoprocessor object as shown in the following code example:
[C#]
ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor
    ();
[VB.NET]
Dim gp As ESRI.ArcGIS.Geoprocessor.Geoprocessor = New ESRI.ArcGIS.Geoprocessor.Geoprocessor()
Remember that 'p' in Geoprocessor is lowercase.

Toolbox assemblies

ArcGIS comes with a set of toolboxes. Each ArcGIS extension also comes with its own toolbox. In .NET, each geoprocessing system toolbox is represented by a managed assembly. You must reference the managed toolbox assembly in your project to use a tool for that toolbox. For example, to use the Near tool of the Analysis toolbox, add the ESRI.ArcGIS.AnalysisTools toolbox namespace as a reference to your application. The following table shows the namespaces for the toolboxes:
Toolbox name
Namespace
3D Analyst tools
ESRI.ArcGIS.Analyst3DTools
Analysis tools
ESRI.ArcGIS.AnalysisTools
Conversion tools
ESRI.ArcGIS.ConversionTools
Data Management tools
ESRI.ArcGIS.DataManagementTools
Editing tools
ESRI.ArcGIS.EditingTools
Cartography tools
ESRI.ArcGIS.CartographyTools
Coverage tools
ESRI.ArcGIS.CoverageTools
Geocoding tools
ESRI.ArcGIS.GeocodingTools
Geostatistical Analyst tools
ESRI.ArcGIS.GeostatisticalAnalystTools
Linear Referencing tools
ESRI.ArcGIS.LinearReferencingTools
Multidimension tools
ESRI.ArcGIS.MultidimensionTools
Network Analyst tools
ESRI.ArcGIS.NetworkAnalystTools
Parcel Fabric tools
ESRI.ArcGIS.ParcelFabricTools
Spatial Analyst tools
ESRI.ArcGIS.SpatialAnalystTools
Spatial Statistics tools
ESRI.ArcGIS.SpatialStatisticsTools
If you expand the toolsets in the Spatial Statistics toolbox in Desktop you will notice that all but two tools in this toolbox look different - instead of a hammer there is a scroll paper or ModelBuilder icon next to each tool. These tools are created using python scripts or by ModelBuilder. The toolbox is then converted to a managed assembly and the tools are now available to you in a .NET to run in the CLR.

Tool classes

In each toolbox assembly, there are classes representing each geoprocessing tool for that toolbox. To run a tool, create a tool object by instantiating the tool class as shown in the following code example:
[C#]
// Instantiate the Near tool class for the Analysis Tools toolbox.
// Add ESRI.ArcGIS.AnalysisTools reference to your project.

Near nearTool = new Near();
[VB.NET]
' Instantiate the Near tool class for the Analysis Tools toolbox.
' Add ESRI.ArcGIS.AnalysisTools reference to your project.

Dim nearTool As Near = New Near()
All tool parameters become properties of the tool class. Set the parameter values by using the setter method for the tool object. You can get the available names for the parameters from the IntelliSense as shown in the following screen shot:
This .NET-like behavior is easy to follow. Another advantage is that you do not need to maintain the order of the parameters. Make sure all required parameters are set. On the preceding screen shot you can see an out_feature_class parameter, although you do not see it on the tool's dialog box because the output is derived and does not need to be set. For more information on how to determine a parameter type, see Interpreting a tool reference page. You can populate the tool parameters by setting their values as shown in the following code example:
[C#]
nearTool.in_feautures = @"C:\data\hospitals.shp";
nearTool.near_features = @"C:\data\houses.shp";
[VB.NET]
nearTool.in_feautures = "C:\data\hospitals.shp"
nearTool.near_features = "C:\data\houses.shp"
To simplify matters, each tool class also has a parameterized constructor, allowing you to initialize the tool with all the required properties in one line of code. See the following code example that shows how to access the Erase tool and set its parameters:
[C#]
gp.SetEnvironmentValue("workspace", @"C:/data/Habitat_Analysis.gdb");
Erase eraseTool = new Erase("suitableVeg", "roadsBuffer", "eraseOutput");
[VB.NET]
gp.SetEnvironmentValue("workspace", "C:/data/Habitat_Analysis.gdb")
Dim eraseTool As [Erase] = New [Erase]("suitableVeg", "roadsBuffer", "eraseOutput")

Working with tool names and avoiding name conflicts

A tool name must be unique within a toolbox. A program typically uses tools from more than one toolbox. When using multiple toolboxes, it is possible that two or more toolboxes will contain a tool with the same name. When this happens, the geoprocessor is unable to determine which tool in which toolbox should be executed when the tool is referenced in a program. For example, there are two tools named Clip, one in the Analysis toolbox and one in the Data Management toolbox. In these cases, use the namespace to set the tool. See the following code example:
[C#]
ESRI.ArcGIS.AnalysisTools.Clip clipTool = new ESRI.ArcGIS.AnalysisTools.Clip();

ESRI.ArcGIS.DataManagementTools.Clip clipDM = new
    ESRI.ArcGIS.DataManagementTools.Clip();
[VB.NET]
Dim clipTool As ESRI.ArcGIS.AnalysisTools.Clip = New ESRI.ArcGIS.AnalysisTools.Clip()

Dim clipDM As ESRI.ArcGIS.DataManagementTools.Clip = New ESRI.ArcGIS.DataManagementTools.Clip()
If you use the list methods, such as ListFeatureClasses, add the ESRI.ArcGIS.Geoprocessing namespace as a reference because the returned enumeratioin is an IGpEnumList object, which is not available through the managed assembly.


See Also:

Executing tools
How to run a geoprocessing tool
Running a geoprocessing tool using background geoprocessing




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):