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

来源:互联网 发布:去掉淘宝客链接 编辑:程序博客网 时间:2024/05/17 00:59
声明:仅做自己学习整理用,内容拷贝自ArcEngine SDK开发文档

Executing tools

In this topic

  • About roadmap to executing tools
  • Creating the geoprocessor object
  • Using the geoprocessor object

About roadmap to executing tools

Geoprocessing is a fundamental part of ArcGIS. Whether you are a novice or advanced user, geoprocessing will become an essential part of your daily work with ArcGIS. Geoprocessing provides the necessary data analysis, data management, and data conversion tools for all geographic information system (GIS) software users.
The main purposes of geoprocessing are to allow you to automate your GIS tasks and to perform spatial analysis and modeling. Geoprocessing supports the automation of workflows by providing a set of tools and a mechanism to combine a series of tools in a sequence of operations using models and scripts.
The kinds of tasks to be automated can be mundane, for example, converting data from one format to another; or the tasks can be creative, using a sequence of operations to model and analyze complex spatial relationships. For example, calculating optimum paths through a transportation network, predicting the path of wildfire, analyzing and finding patterns in crime locations, predicting which areas are prone to landslides, or predicting flooding effects of a storm event.
Geoprocessing consists of operators (tools) that operate on the data in ArcGIS (tables, feature classes, rasters, triangulated irregular network [TINs], and so on) and performs necessary tasks for manipulating and analyzing geographic information across a wide range of disciplines. Each geoprocessing tool performs an essential operation on geographic data, such as projecting datasets from one map projection to another, adding fields to a table, or creating buffer zones around features.
ArcGIS includes hundreds of such geoprocessing tools. A geoprocessing tool takes ArcGIS datasets as inputs (such as feature classes, tables, rasters, and computer-aided design [CAD] files), applies an operation against this data, and creates a dataset as output. Tool execution is the basic operation in geoprocessing. 

Creating the geoprocessor object(创建对象的两种方式)

In .NET, you run a geoprocessing tool by calling the Execute method on the geoprocessor. You can create the geoprocessor in the following two ways:
  • Using the IGeoProcessor2 interface of the GeoProcessor class available in the Geoprocessing type library through the ESRI.ArcGIS.Geoprocessing namespace. See the following code example:
[C#]
IGeoProcessor2 gp = new GeoProcessorClass();

[C#]
ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor    ();

Using the geoprocessor object(两种创建对象方式的选择性)

The created geoprocessor object (gp) has the same methods and properties, no matter what approach you take to create it. The other differences between the two approaches are as follows:
  • Setting up and running a geoprocessing tool. For more information, see How to run a geoprocessing tool.
  • Handling errors. For more information, see Working with result objects.
So, which approach is better? In short, both approaches are equally applicable; although, the managed classes have the advantage of being .NET native and you get IntelliSense for tool parameters. The scope is limited to only a subset (although, the most important one) of geoprocessing functionalities. Conversely, the only limitation of using IGeoProcessor.Execute is that you are forced to know the order of a tool's parameters. However, that can be considered a benefit also, for example, the IntelliSense of the managed classes do not show if a parameter is "derived." For more information, see Interpreting a tool reference page.

Accessing licensing and extensions for the geoprocessor


About accessing licensing and extensions for the geoprocessor

An ArcGIS Desktop license is required to execute a tool in a program. Tools from ArcGIS extensions, such as ArcGIS Spatial Analyst, require an additional license for that extension. If the necessary licenses are not available, a tool fails and returns the appropriate error messages.
In ArcGIS 10, you need to set the product that will execute the code by the RuntimeManager. Add ESRI.ArcGIS.Version to your project as a reference. However, you don't need to add the namespace to your code with the using keyword.
When using an ArcView or ArcEditor license, a program must explicitly use AoIntialize, and the product must be set to ArcView or ArcEditor, or the program fails. By default, the geoprocessor always assumes an ArcInfo license is required for execution of a tool. See the following code example:
[C#]
static void Main(string[] args){    // Add runtime management      ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop);    //Initialize the application.    esriLicenseStatus licenseStatus = esriLicenseStatus.esriLicenseUnavailable;    IAoInitialize m_AoInitialize = new AoInitializeClass();    licenseStatus = m_AoInitialize.Initialize        (esriLicenseProductCode.esriLicenseProductCodeArcInfo);    licenseStatus = m_AoInitialize.CheckOutExtension        (esriLicenseExtensionCode.esriLicenseExtensionCodeSpatialAnalyst);    // Initialize the geoprocessor.             Geoprocessor gp = new Geoprocessor();    Slope tSlope = new Slope();    tSlope.in_raster = @"E:\Data\demlatgrd";    tSlope.out_raster = @"E:\Data\aspect03";    gp.Execute(tSlope, null);    licenseStatus = m_AoInitialize.CheckInExtension        (esriLicenseExtensionCode.esriLicenseExtensionCodeSpatialAnalyst);    m_AoInitialize.Shutdown();    m_AoInitialize = null;}


0 0
原创粉丝点击