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 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 the following important properties:

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

Each tool has a documentation page known as a tool reference page. For more information about parameters, see Interpreting a tool reference page.

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

Parameters are specified 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, can be easier to specify with an object. Each tool has its own parameter types. To get complete information on a particular tool, review the tool reference page. Interpreting a tool reference page explains how to read a tool reference page and extract information to use in .NET.

You can run a geoprocessing tool by using the Geoprocessing library methods or by the geoprocessor managed assembly methods. For information about the basic differences between the two approaches, see Executing tools. In both cases, the Execute method of the geoprocessor is called.

The Execute method uses a 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. Both approaches are elaborated with the following examples.

Using the geoprocessing assembly

The geoprocessing assembly is the Component Object Model (COM) interop of the Geoprocessing type library. The Execute method of the IGeoProcessor2 interface of the library is used to run a tool.

The following are the generic steps to execute a tool:

  1. Add a reference to ESRI.ArcGIS.Geoprocessing to your project. This is the only reference you need if you use the geoprocessing assembly.
  2. Create the geoprocessor object.
  3. Add the path to the custom toolbox if you are running a custom tool.
  4. Create an IVariantArray and populate it with tool parameter values. The IVariantArray is available through the esriSystem library.
  5. Call the Execute method on the geoprocessor.

The process is the same if you run a system tool or a custom tool.

Make sure you maintain the order of parameters as specified in the tool reference page when populating the variant array. Follow the syntax section of the tool reference page (see link at the bottom), it shows the correct ordering of parameters.

If you want to skip an optional parameter, just add an empty string to the variant array in correct order. For example, if a tool‘s third, fourth and fifth parameters are optional and you want to pass value only to the fifth parameter, then you have to pass empty strings to the third and fourth parameters to maintain correct ordering.

Passing an empty string instructs the tool to use the default value of that parameter.

Do not follow the tool‘s dialog box to get the order of parameters; follow the tool‘s Help page (browse to Interpreting a tool reference page link at the end). Parameters are arranged on a tool dialog box by "display order" not by the actual order.

Executing a system tool

The following code example shows the execution of the Buffer tool from the Analysis toolbox. The required parameters for the tool are defined. In this case, strings are used to define the input, output, and buffer distance properties, so the call to the tool is easier to read.

[C#]

using System;
using System.Threading;
// Add references to esriSystem for licensing and IVariantArray.
using ESRI.ArcGIS.esriSystem;
// Add a reference to the geoprocessing namespace.
using ESRI.ArcGIS.Geoprocessing;

// Call this method from your main.
private static void RunBuffer()
{
    // Create the geoprocessor.
    IGeoProcessor2 gp = new GeoProcessorClass();
    gp.OverwriteOutput = true;

    IGeoProcessorResult result = new GeoProcessorResultClass();

    // Create a variant array to hold the parameter values.
    IVariantArray parameters = new VarArrayClass();

    object sev = null;

    try
    {
        // Populate the variant array with parameter values.
        parameters.Add(@"C:\data\california.gdb\cities");
        parameters.Add(@"C:\data\california.gdb\cities_buff");
        parameters.Add("1000 Meters");

        // Execute the tool.
        result = gp.Execute("Buffer_analysis", parameters, null);

        // Wait until the execution completes.
        while (result.Status == esriJobStatus.esriJobExecuting)
            Thread.Sleep(1000);
        // Wait for 1 second.

        // Print geoprocessring messages.
        Console.WriteLine(gp.GetMessages(ref sev));
    }

    catch (Exception ex)
    {
        // Print a generic exception message.
        Console.WriteLine(ex.Message);

        // Print geoprocessing execution error messages.
        Console.WriteLine(gp.GetMessages(ref sev));
    }
}

[VB.NET]

Imports System
Imports System.Threading
‘ Add references to esriSystem for licensing and IVariantArray.
Imports ESRI.ArcGIS.esriSystem
‘ Add a reference to the geoprocessing namespace.
Imports ESRI.ArcGIS.Geoprocessing

‘ Call this method from your main.

Private Sub RunBuffer()

    ‘ Create the geoprocessor.
    Dim gp As IGeoProcessor2 = New GeoProcessor()
    gp.OverwriteOutput = True

    Dim result As IGeoProcessorResult = New GeoProcessorResult()

    ‘ Create a variant array to hold the parameter values.
    Dim parameters As IVariantArray = New VarArray()

    Dim sev As Object = Nothing

    Try
    ‘ Populate the variant array with parameter values.
    parameters.Add("C:\data\california.gdb\cities")
    parameters.Add("C:\data\california.gdb\cities_buff")
    parameters.Add("1000 Meters")

    ‘ Execute the tool.
    result = gp.Execute("Buffer_analysis", parameters, Nothing)

    ‘ Wait until the execution completes.
    While (result.Status = esriJobStatus.esriJobExecuting)
        Thread.Sleep(1000)
    End While

    ‘ Print geoprocessing messages.
    Console.WriteLine(gp.GetMessages(sev))

    Catch ex As Exception
    ‘ Print generic exception messages.
    Console.WriteLine(ex.Message)

    ‘ Print geoprocessing execution error messages.
    Console.WriteLine(gp.GetMessages(sev))

    End Try

End Sub
时间: 2024-10-09 10:43:18

Arcengine调用GP服务的相关文章

ArcGIS API for Silverlight 调用GP服务准备---GP模型建立、发布、测试

原文:ArcGIS API for Silverlight 调用GP服务准备---GP模型建立.发布.测试 第一篇.GP降雨量等值线建模.发布及测试 在水利.气象等行业中,要在WebGIS中实现空间分析功能,如绘制等值线.等高线.等直面.缓冲区等都是经常遇到,经过一段时间的学习和研究,查阅ESRI文档,请教他人,终于可以说是初步实现了等值线功能,这里记录下来详细的操作步骤和图片说明,一方面是对此次努力的总结,另一方面希望也能给后来用到这方面的其他同志们,起个抛砖引玉的作用. 下一篇是关于Silv

ArcGIS API for Silverlight 调用GP服务加载等值线图层

原文:ArcGIS API for Silverlight 调用GP服务加载等值线图层 第二篇.Silverlight客户端调用GP服务 利用ArcGIS API for Silverlight实现GP服务调用,这里的雨量数据是通过一个WebService获取而来,主要信息是雨量站点的经纬度坐标值和某个时间段内的降雨量值三个主要字段. 以下是核心代码部分: <UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/pr

ArcGIS API for Silverlight 调用GP服务绘制等值面

原文:ArcGIS API for Silverlight 调用GP服务绘制等值面 GP服务模型如下图: 示例效果图片如下:

ArcEngine 调用GP里面的Merge工具

public static Boolean Merge(String[] inputs,String output) { Geoprocessor gp = new Geoprocessor(); gp.OverwriteOutput = true; int strSize = inputs.Count(); String tempStr = "\""+inputs[0]+""; for (int i = 1; i < strSize-1; i++)

GP服务的调用(等值线面、泰森多边形、标注)

//获取并初始化等值线面图层 function getIsoAnalyzeResultLayer() { var layerId = "isoAnalyzeResult"; var graphicsLayerIsoAnalyze = map.getLayer(layerId); if (typeof (graphicsLayerIsoAnalyze) == "undefined" || graphicsLayerIsoAnalyze == null) { graph

arcgis服务之GP服务的几点问题(附GP服务发布步骤)

最近在发布GP服务时遇到了一些以前没有遇到问题,所以对GP服务进行一下总结. 一.什么是GP服务 GP服务,即Geoprocessing Service,意为地理处理服务,是将Arctoolbox中的工具或ModelBuilder中创建的工具发布为服务,以供Arcgis API For Javascript调用工具服务,辅助分析处理功能进行开发. 二.GP服务的分类 GP服务包括两类,一类是Execute task,即同步执行任务:另外一类是Submit job,即异步提交作业. 这两种GP服务

ArcGIS 10.1 发布使用ArcEngine自定义的GP服务

1. 新建立GP模型 在VS2010中新建一个普通的程序及,引入ArcEngine相关的dll.在该DLL中定义一个或多个GP类和一个GP工厂类.GP类要继承IGPFunction2接口,GP工厂类要继承IGPFunctionFactory接口. 下面是各个接口的一些实现方法 IGPFunction2 接口 接口意义 UID DialogCLSID { get; } 对话框的类标识,该方法在实现时直接返回为空即可. public UID DialogCLSID{ get{ return null

c# 调用ArcEngine的GP工具

转自原文c# 调用ArcEngine的GP工具,AE调用GP工具 IAoInitialize m_AoInitialize = new AoInitializeClass(); esriLicenseStatuslicenseStatus = esriLicenseStatus.esriLicenseUnavailable; licenseStatus = m_AoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCod

GIS有关GP服务的发布和调用

1.通过Modelbuilder新建工具.(注意:假如工具输出两个以上的结果,需要保存在相同文件及下,并将输入输出都设置为参数) 2.调用新建的工具,在result窗口中查看结果,工作是否正确. 3.发布服务时,参数要设置自定义,并且异步调用 4.调用参数说明: 5.参数输入世必须是字符串格式,json需要用JSON.stringify(obj);进行转换 6.调用时: usr1="https://localhost:6443/arcgis/rest/services/gp服务所在目录/gp服务