Arcengine Call GP Service

Source: Internet
Author: User

Note the difference between 2 references required

D:\Program Files (x86) \arcgis\developerkit10.1\dotnet\esri. ArcGIS.Geoprocessor.dll

D:\Program Files (x86) \arcgis\developerkit10.1\dotnet\esri. ArcGIS.Geoprocessing.dll

Official code:

Each geoprocessing tool have a fixed set of parameters that provide the tool with the information it needs for execution. Tools usually has input parameters that define the dataset or datasets that would typically be used to generate new output Data. Parameters has 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 on parameters, see Interpreting a tool reference page. When a tool was used in a program, its parameter values must being 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, and the tool is ready to be executed. Parameters is specified as strings or objects. Strings is text values that uniquely identify a parameter value, such as a path to a dataset or a keyword. Most tool parameters can is specified as a simple string. However, complex parameters, such as a spatial reference, can is easier to specify with an object. Each tool have 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 cA 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 and the 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 have been executed by The user and also allows developers to specify what actions constitute a cancellation. Both approaches is elaborated with the following examples. Using the geoprocessing assemblyThe geoprocessing assembly is the Component Object Model (COM) interop of the The Geoprocessing type library. The Execute method of the IGeoProcessor2 interface of the library is used to run a tool. The following is the generic steps to execute a tool:
    1. Add a reference to ESRI. Arcgis.geoprocessing to your project. The reference you need if you use the Geoprocessing assembly.
    2. Create the Geoprocessor object.
    3. Add the path to the custom Toolbox if is running a custom tool.
    4. Create a 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 Varia NT 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 a 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 is optional and you want to pass value-only to the fifth para Meter, then you had to pass empty strings to the third and fourth parameters to maintain correct ordering. Passing a empty string instructs the tool to use the default value of this 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 is arranged on a tool dialog box by ' Display order ' not by the actualOrder. executing a system toolThe following code example shows the execution of the Buffer tool from the Analysis Toolbox. The required parameters for the tool is defined. In this case, strings was used to define the input, output, and buffer distance properties, so the call to the tool is EAS Ier to read.

[C #]

usingSystem;usingSystem.Threading;//ADD references to Esrisystem for licensing and Ivariantarray.usingESRI. Arcgis.esrisystem;//ADD A reference to the Geoprocessing namespace.usingESRI. arcgis.geoprocessing;//Call the This method from your main.Private Static voidRunbuffer () {//Create the geoprocessor.IGeoProcessor2 GP =NewGeoprocessorclass (); Gp. Overwriteoutput=true; Igeoprocessorresult result=NewGeoprocessorresultclass (); //Create A Variant array to hold the parameter values.Ivariantarray parameters =NewVararrayclass (); ObjectSEv =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 ("Meters"); //Execute the tool.result = GP. Execute ("buffer_analysis", parameters,NULL); //Wait until the execution completes.         while(result.) Status = =esrijobstatus.esrijobexecuting) Thread.Sleep ( +); //Wait for 1 second. //Print geoprocessring messages.Console.WriteLine (GP. Getmessages (refsev)); }    Catch(Exception ex) {//Print a generic exception message.Console.WriteLine (ex.        Message); //Print geoprocessing execution error messages.Console.WriteLine (GP. Getmessages (refsev)); }}

[VB.net]

Imports systemimports 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 the 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 ("Meters")        'Execute the tool.result = GP. Execute ("buffer_analysis", parameters, nothing)'Wait until the execution completes.while (result. Status =esrijobstatus.esrijobexecuting) Thread.Sleep ( +) 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

Arcengine Call GP Service

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.