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

How to run a geoprocessing tool的更多相关文章

  1. Unable to run mksdcard SDK tool.

    Ubuntu 14.04,安装android studio后运行出错,sdk manager不能正常运行 Unable to run mksdcard SDK tool. 原因,缺少运行需要的库:li ...

  2. ubuntu15.10运行android studio出错unable to run mksdcard sdk tool

    问题:ubuntu运行android studio出错unable to run mksdcard sdk tool 系统版本:系统是ubuntu 15.10 64位 确认原因:缺少lib 解决方法: ...

  3. Android studio Unable to run mksdcard SDK tool

    /******************************************************************************************** * Andr ...

  4. 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.InteropSer ...

  5. android studio 安装报错 unable to run mksdcard sdk tool

    搜了一下原来缺少这个 sudo apt-get install lib32z1 lib32ncurses5  lib32stdc++6

  6. ubuntu运行android studio出错unable to run mksdcard sdk tool

    原因:缺少lib 解决方法: sudo apt-get install lib32z1 lib32ncurses5  lib32stdc++6 完美解决.

  7. centos7安装android studio遇到Unable to run mksdcard sdk tool

    centos系统为最小化安装,所以安装新软件时缺少许多依赖包,Android Studio下载的mksdcard是32位的,而系统是64位的,所以需要安装支持32位软件的依赖包. sudo yum i ...

  8. GP中Geoprocessor.Execute(string name, IVariantArray parameters, ITrackCancel trackCancel)

    在做一个项目的过程中,发现GP运算方法 Execute(string name, IVariantArray parameters, ITrackCancel trackCancel) 与Execut ...

  9. The Topo to Raster tool returns errors 010235 and 010067转

    Problem: The Topo to Raster tool returns errors 010235 and 010067 Description The Topo to Raster geo ...

随机推荐

  1. 洛谷 P1007 独木桥

    #include<set> #include<map> #include<cmath> #include<queue> #include<cstd ...

  2. 20160626001 O2O Website

    1. http://sidapai.baijia.baidu.com/   百度百家 2. http://www.huxiu.com/    虎嗅网 3. http://i.wshang.com   ...

  3. 给定时器settimeout、setInterval调用传递参数

    无论是window.setTimeout还是window.setInterval,在使用函数名作为调用句柄时都不能带参数,而在 许多场合必须要带参数,这就需要想方法解决.例如对于函数hello(_na ...

  4. 个人作业-Week3

    个人作业-Week3 1. 软件工程师的成长 同学们在上这门课的时候,还是大三,你的困难和迷茫,别人一定有过.请看看别人怎么学习的,有些是科班,有些是野路子,有些成功,有些失败. 请读完下面所有博客( ...

  5. Start with connect by prior 递归查询

    在SELECT命令中使用CONNECT BY和START WITH子句可以查询表中的树型结构关系.其命令格式如下: SELECT * from CONNECT BY {PRIOR列名1=列名2|列名1 ...

  6. hive的使用02

    1.hive的交互方式 1.1 bin/hive 进入hive交互命令行环境 1.2 bin/hive -e 'select * from hive.student;' (可以通过 > 将结果写 ...

  7. CentOS离线安装GCC编译环境

    gcc编译环境rpm下载 安装相关的rpm包,具体版本可能随时间变化而变化,可以去以下地址下载: 重庆大学镜像:http://b.mirrors.lanunion.org/CentOS/中国科学技术大 ...

  8. pull 解析XML 文件

    pull解析的特点 事件驱动机制来解析 当解析到一个节点,会自动停止,不会往下继续解析,好处 :很好能够控制流程 android默认采用pull解析 pull解析的事件类型 start_documen ...

  9. JavaScript的chapterII

    程序流程控制: 1.条件语句——if     if(condition) {statement1}     else {statement2} 例子:     if(i<60 && ...

  10. Cheatsheet: 2016 08.01 ~ 08.31

    .NET Getting Started with ASP.NET Core and VS Code Coding Standard Best Practices In C# Wire – Writi ...