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. Python基础操作-函数

    本节内容 1. 函数基本语法及特性2. 参数与局部变量3. 返回值4.递归5.高阶函数 1.函数基本语法及特性函数是什么? 函数一词来源于数学,但编程中的「函数」概念,与数学中的函数是有很大不同的,具 ...

  2. CI框架--事务

    CI框架中事务封装的很完善,使用起来很简单 1.不开启事务 //不开启事务 前两个sql 能够执行成功,第三个执行失败 $this->device_model->addForCamera( ...

  3. ping命令脚本实现显示网络状态、学生姓名、学号

    #!/bin/bash a=. ####定义一个固定变量 h=(wanghao xieyunshen 刘桃) ####定义数组 ..} ####for循环,后面的in是条件即从多少循环到多少 do # ...

  4. 20161014001 DataGridView 单元格内容 自动计算

    private void T_Form_CY_CBD_D_CellValueChanged(object sender, DataGridViewCellEventArgs e)        {   ...

  5. up_modembin.sh

    --- 编译modem生成bin文件cp到指定文件夹 up_modembin.sh #!/bin/bash flag=${} == $flag ];then # echoMsg find vendor ...

  6. 在MAC服务器上搭建docker-registry(转)

    在MAC服务器上搭建docker-registry 2014-03-14      0个评论    来源:在MAC服务器上搭建docker-registry   收藏    我要投稿 本文介绍如何在M ...

  7. VC++2013出现bug: 无法打开源文件“stdafx.h”

    VC++2013出现bug: 无法打开源文件“stdafx.h” 1.首先需要把#include "stdafx.h"置于最头 2.在解决方案资源管理器中添加以下几个文件(附图下)

  8. 读《编写可维护的JavaScript》第八章总结

    第八章 避免“空比较” 我们在对传进来的参数做处理之前,肯定需要验证一下是否是我们想要的,也就是说大多数情况下,我们需要对比一下它的类型. 作者首先给了一个看起来都感觉不对的代码: var Contr ...

  9. 将JSON对象带有格式的写出到文件中

    需求:将一个JSON对象写出到文件中,要求文件中的JSON数据带有简单的格式.代码的实现参考了Java算法中的栈处理括号匹配问题.好了,不多说了,下面是代码的实现. 代码: package gemu. ...

  10. 切换npm源

    直接切换源: npm install --registry=https://registry.npm.taobao.org 另: (仅用于学习参考使用) 参考: http://www.xuebuyua ...