How to run a geoprocessing tool

How to run a geoprocessing tool

In this topic


Running a geoprocessing tool

Each geoprocessing tool has a fixed set of parameters that provides the tool with the information it needs for execution. Tools usually have input parameters that define the dataset or datasets that will typically be used to generate new output data. Parameters have several important properties:

  • Name—Each tool parameter has a unique name.
  • Type—The type of data expected, such as feature class, integer, string, and raster.
  • Required—Either a value must be provided for a parameter or it is optional.

When a tool is used in a program, its parameter values must be correctly set so it can execute when the program is run. The documentation of each tool clearly defines its parameters and properties. Once a valid set of parameter values are provided, the tool is ready to be executed.

Parameters are specified either as strings or objects. Strings are text values that uniquely identify a parameter value, such as a path to a dataset or a keyword.

Most tool parameters can be specified as a simple string. However, complex parameters, such as a spatial reference, may be easier to specify with an object. In the following code example, the required parameters for the Buffer tool are defined. In this case, strings are used to define the input, output, and buffer distance properties of Buffer so the call to the tool is easier to read.

The following Execute method uses null reference instead of an ITrackCancel interface. The ITrackCancel interface provides access to properties and methods that determine if a cancellation has been executed by the user and also allows developers to specify what actions constitute a cancellation.

[C#]

using ESRI.ArcGIS.Geoprocessor;
using ESRI.ArcGIS.AnalysisTools;

public void SampleBufferTool()
{

  // Initialize the geoprocessor.
  Geoprocessor GP = new Geoprocessor();

  ESRI.ArcGIS.AnalysisTools.Buffer bufferTool = new
    ESRI.ArcGIS.AnalysisTools.Buffer();

  bufferTool.in_features = @"D:\St_Johns\data.mdb\roads_Buffer";
  bufferTool.out_feature_class = @"D:\St_Johns\data.mdb\roads";
  bufferTool.buffer_distance_or_field = "distance";

  GP.Execute(bufferTool, null);

}


[VB.NET]

Imports ESRI.ArcGIS.Geoprocessor
Imports ESRI.ArcGIS.AnalysisTools

Public Sub SampleBufferTool()

    ‘ Initialize the geoprocessor.
    Dim GP As Geoprocessor = New Geoprocessor()

    Dim bufferTool As ESRI.ArcGIS.AnalysisTools.Buffer = New ESRI.ArcGIS.AnalysisTools.Buffer()

    bufferTool.in_features = "D:\St_Johns\data.mdb\roads_Buffer"
    bufferTool.out_feature_class = "D:\St_Johns\data.mdb\roads"
    bufferTool.buffer_distance_or_field = "distance"

    GP.Execute(bufferTool, Nothing)

End Sub

Toolbox names and namespaces

The following table shows the system toolbox names and namespaces:

Toolbox names Namespaces
3D Analyst tools ESRI.ArcGIS.Analyst3DTools
Analysis tools ESRI.ArcGIS.AnalysisTools
Conversion tools ESRI.ArcGIS.ConversionTools
Data Management tools ESRI.ArcGIS.DataManagementTools
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.LinearReferencingAnalystTools
Multidimension tools ESRI.ArcGIS.MultidimensionTools
Network Analyst tools ESRI.ArcGIS.NetworkAnalystTools
Samples ESRI.ArcGIS.SamplesTools
Spatial Analyst tools ESRI.ArcGIS.SpatialAnalystTools
Spatial Statistics tools ESRI.ArcGIS.SpatialStatisticsTools

Running custom geoprocessing tools

In addition to using the existing tools and toolboxes provided by ESRI, it is also possible to execute your custom tools, such as model tools and script tools, which exist in custom toolboxes. Using the integrated development environment (IDE) framework built-in Visual Studio .NET, you can generate a geoprocessing assembly to represent any custom toolbox. To do so, use the ArcGIS Toolbox Reference dialog box.

Executing a tool by name

It is not a prerequisite to generate a geoprocessing assembly to represent your custom toolbox. There is an alternative way to use the Execute method on the geoprocessor. The Execute method is overloaded and has an additional argument list that allows you to execute a tool by specifying the tool name, the parameters of the tool, and the ITrackCancel interface.

The following is an example of executing the CalculateBestPath model tool, which is located in the BestPath toolbox:

[C#]

using ESRI.ArcGIS.Geoprocessor;
using ESRI.ArcGIS.esriSystem;

public void SampleCalculateBestPathTool()
{

  // Initialize the geoprocessor.
  Geoprocessor GP = new Geoprocessor();

  // Add the BestPath toolbox.
  GP.AddToolbox(@"C:\SanDiego\BestPath.tbx");

  // Generate the array of parameters.
  IVariantArray parameters = new VarArrayClass();
  parameters.Add(@"C:\SanDiego\source.shp");
  parameters.Add(@"C:\SanDiego\destination.shp");
  parameters.Add(@"C:\SanDiego\bestpath.shp");

  // Execute the model tool by name.
  GP.Execute("CalculateBestPath", parameters, null);

}


[VB.NET]

Imports ESRI.ArcGIS.Geoprocessor
Imports ESRI.ArcGIS.esriSystem

Public Sub SampleCalculateBestPathTool()

    ‘ Initialize the geoprocessor.
    Dim GP As Geoprocessor = New Geoprocessor()

    ‘ Add the BestPath toolbox.
    GP.AddToolbox("C:\SanDiego\BestPath.tbx")

    ‘ Generate the array of parameters.
    Dim parameters As IVariantArray = New VarArrayClass()
    parameters.Add("C:\SanDiego\source.shp")
    parameters.Add("C:\SanDiego\destination.shp")
    parameters.Add("C:\SanDiego\bestpath.shp")

    ‘ Execute the model tool by name.
    GP.Execute("CalculateBestPath", parameters, Nothing)

End Sub

时间: 2024-10-24 15:48:26

How to run a geoprocessing tool的相关文章

Android studio Unable to run mksdcard SDK tool

/******************************************************************************************** * Android studio Unable to run mksdcard SDK tool * 说明: * 记录Ubuntu下AS安装过程中遇到的问题. * * 2016-6-13 深圳 南山平山村 曽剑锋 *************************************************

Create a geoprocessing tool to buffer a layer and retrieve messages____sync

using System.Drawing; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; using ESRI.ArcGIS.ADF.BaseClasses; using ESRI.ArcGIS.ADF.CATIDs; using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.esriSys

Unable to run mksdcard SDK tool.

Ubuntu 14.04,安装android studio后运行出错,sdk manager不能正常运行 原因,缺少运行需要的库:lib32z1 lib32ncurses5  lib32stdc++6 sudo apt-get install lib32z1 lib32ncurses5  lib32stdc++6 安装完成后重新启动android studio即可

Arcengine调用GP服务

注需 2个引用的区别 D:\Program Files (x86)\ArcGIS\DeveloperKit10.1\DotNet\ESRI.ArcGIS.Geoprocessor.dll D:\Program Files (x86)\ArcGIS\DeveloperKit10.1\DotNet\ESRI.ArcGIS.Geoprocessing.dll 官网代码: Each geoprocessing tool has a fixed set of parameters that provide

AE 打开工具箱工具的对话框

The best approach to run a system tool—or any tool or model created, and saved in a toolbox from a button—is to create an add-in control. Add-in controls are a new feature in ArcGIS 10. You can create an add-in control through the Customize dialog bo

【翻译自mos文章】将Oracle 12c数据库从标准版convert到企业版

将Oracle 12c数据库从标准版convert到企业版 来源于: How to Convert Oracle Database 12c from Standard to Enterprise Edition ? (文档 ID 2046103.1) APPLIES TO: Oracle Database - Enterprise Edition - Version 12.1.0.1 and later Information in this document applies to any pl

centos 装 android studio

一.安装前的准备 1.1.如果你还没有安装ubuntu 14.04 LTS系统,请参考下面的文章安装 http://blog.csdn.net/lsyz0021/article/details/52187026 这里需要说明的是:在ubuntu下google官方测试的Android studio支持版本是ubuntu 12.04 LTS.jdk1.8.推荐电脑内存8GB 其实ubuntu 14.04 LTS和ubuntu 16.04 LTS也是可以的,这里我都安装测试过,因为ubuntu 12.

ubuntu下搭建android开发环境核心篇安装AndroidStudio、sdk、jdk

本文系转载http://blog.csdn.net/lsyz0021/article/details/52215996 一.安装前的准备 1.1.如果你还没有安装ubuntu 14.04 LTS系统,请参考下面的文章安装 http://blog.csdn.net/lsyz0021/article/details/52187026 这里需要说明的是:在ubuntu下google官方测试的Android studio支持版本是ubuntu 12.04 LTS.jdk1.8.推荐电脑内存8GB 其实u

【小梅哥FPGA进阶教程】第九章 基于串口猎人软件的串口示波器

九.基于串口猎人软件的串口示波器 1.实验介绍 本实验,为芯航线开发板的综合实验,该实验利用芯航线开发板上的ADC.独立按键.UART等外设,搭建了一个具备丰富功能的数据采集卡,芯航线开发板负责进行数据的采集并将数据通过串口发送到PC机上,PC端,利用强大的串口调试工具--串口猎人,来实现数据的接收分析,并将数据分别以波形.码表.柱状图的形式动态显示出来,以让使用者能够直观的看到ADC采集到的信号细节.同时,用户也可以使用串口猎人通过串口给下位机(FPGA)发送指令,下位机将对接收到的指令进行解