声明:仅做自己学习整理用,内容拷贝自ArcEngine SDK开发文档

Geoprocessing assembly overview

In this topic

  • About the Geoprocessing assembly
  • Creating tools

About the Geoprocessing assembly

The Geoprocessing assembly is Component Object Model (COM)-based unmanaged code. The .NET Framework interacts with the Geoprocessing library through COM interop. ESRI supplies the primary interop assemblies (PIAs) for this type library (along with the PIAs of all other type libraries). The Geoprocessing interop assembly enables a .NET client to seamlessly create instances of COM types and call its methods as though they were native .NET instances.
The Geoprocessing library is imported as the ESRI.ArcGIS.Geoprocessing namespace. All COM coclasses are converted to managed classes—for example, the GeoProcessor coclass is converted to GeoProcessorClass ("Class" is appended to the original name). The Geoprocessing library has hundreds of coclasses, all of which are available in .NET once you reference the ESRI.ArcGIS.Geoprocessing namespace to your project. Once the namespace is added to your project, you can seamlessly interact with those classes.
Of the hundreds of coclasses and interfaces in the Geoprocessing library, the most important one is the IGeoProcessor2 interface of the GeoProcessor coclass. You need a reference to IGeoProcessor2 if you're using the geoprocessing tools. The following are other commonly used interfaces:
  • IGeoProcessorResult2—used to interrogate the result object.
  • IGPUtilities3—A helper coarse-grained ArcObjects component that simplifies workflow.
  • IGpEnumList—Some IGeoProcessor2 methods return IGpEnumList.
  • IGPServer2—Works with geoprocessing services.
You will need to reference various other interfaces for atypical geoprocessing tasks, such as the following:
  • IGpValueTableObject to work with value tables.
  • IGPToolCommandHelper to launch a tool from a button.
  • IDataElement and data element objects to access dataset properties.
  • IGPFieldMapping and IGPFieldMap to map fields.
With the exception of the IGeoProcessor2 interface, none of the coclasses and interfaces is available through Geoprocessor (lowercase p) managed assembly. If you're using the Geoprocessor managed assembly, you also need to reference the ESRI.ArcGIS.Geoprocessing namespace to access the above mentioned interfaces. For more information, see Geoprocessor managed assembly.

Creating tools

You can leverage the full power of the geoprocessing framework by creating your own function tool by implementing the IGPFunction2 and IGPFunctionFactory interfaces. For more information, see Custom geoprocessing function tools. Before you create your own function tool, read Using geoprocessing to develop applications first.
You can also create a script tool using an executable as the source of the tool. For more information, see How to create a script tool that runs an EXE.

Geoprocessor managed assembly

In this topic

  • About the Geoprocessor managed assembly
  • Creating the geoprocessor object
  • Toolbox assemblies
  • Tool classes
  • Working with tool names and avoiding name conflicts

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 = newESRI.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.

GP学习整理(一)—Geoprocessing assembly and Geoprocessor managed assembly相关推荐

  1. GP学习(三)—How to run a geoprocessing tool

    声明:仅做自己学习整理用,内容拷贝自ArcEngine SDK开发文档 How to run a geoprocessing tool In this topic Running a geoproce ...

  2. GP学习(四)—Running a geoprocessing tool using background geoprocessing

    声明:仅做自己学习整理用,内容拷贝自ArcEngine SDK开发文档 Running a geoprocessing tool using background geoprocessing Summ ...

  3. GP学习(九)—Working with geodatabases and the geoprocessor

    声明:仅做自己学习整理用,内容拷贝自ArcEngine SDK开发文档 Working with geodatabases and the geoprocessor Working with geod ...

  4. GP学习(五)—ArcGIS Toolbox Reference dialog box

    声明:仅做自己学习整理用,内容拷贝自ArcEngine SDK开发文档 ArcGIS Toolbox Reference dialog box Summary The ArcGIS Toolbox R ...

  5. GP学习(二)—Executing tools and Accesubg licensing0

    声明:仅做自己学习整理用,内容拷贝自ArcEngine SDK开发文档 Executing tools In this topic About roadmap to executing tools C ...

  6. GP学习(十)-Mosaic raster datasets to a file raster format

    <span style="color: rgb(255, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; font ...

  7. Java设计模式(学习整理)---命令模式

    设计模式之Command(学习整理) 1.Command定义 不少Command模式的代码都是针对图形界面的,它实际就是菜单命令,我们在一个下拉菜单选择一个命令时,然后会执行一些动作. 将这些命令封装 ...

  8. 2019.07.30 学习整理

    2019.07.30 学习整理 数据类型 1. 什么是数据类型 数据类型指的就是变量值的不同类型 2. 为何对数据分类? 变量的是用来反映状态以及状态变化的,毫无疑问针对不同的状态就应该用不同类型的数 ...

  9. java基础学习整理(一)

    java基础学习整理(一) lesson1: D0s命令: 1.回到根目录,>cd \ 2.复制命令行下的内容,右击标记所要复制的内容,这样就已经复制好了,右击粘贴就可以了. 3.查看,设置环境 ...

最新文章

  1. Git本地仓库与远程仓库关联
  2. Steeltoe 2.4新增代码生成工具、全新入门指南等,助力.NET微服务开发
  3. shell 编程 : 函数
  4. SonicWall 防火墙曝严重漏洞,有些设备仍无补丁
  5. 阶段3 1.Mybatis_06.使用Mybatis完成DAO层的开发_7 Mybatis中使用代理Dao的执行过程分析...
  6. 语文招教考试-古今中外神话故事汇总,教育心理学知识点
  7. lan上网和adsl上网
  8. 红警地图编辑器的使用方法
  9. KEIL设置程序起始地址无效解决方法,STM32 IAP程序起始地址
  10. 每日刷题记录 (十五)
  11. win7 wifi共享设置
  12. 论文结论与摘要的区别
  13. 小米4电信4G_2014716_官方线刷包_救砖包_解账户锁
  14. IOS8定位无效问题
  15. MongoDB——常用命令
  16. 计算机应用基础 小组讨论,【《计算机应用基础》教学探讨】 计算机应用基础 2018...
  17. win10安装mysql5.7缺少MSVCP120.dll
  18. nginx网络服务配置
  19. 测试团队如何设定绩效考核指标
  20. 关于Unity unsafe的解决

热门文章

  1. 2017.3.25 圆桌聚餐 思考记录
  2. Intel Core Enhanced Core架构/微架构/流水线 (10) - 先进存储器访问
  3. 一个简单限速器的java实现[2]
  4. QObject::connect: No such signal QGraphicsView::mouseMovePoint(QPoint) in ***
  5. xcode7打包ipa文件
  6. 回答一下这些游戏帧数有关的问题吗?
  7. 管道符和作业控制 shell变量 环境变量配置文件
  8. 在mysql命令行下执行sql文件
  9. Sonar6.0应用之四:与Jenkins集成分析(Scanner+Maven)
  10. H3C S1526交换机端口镜像配置