How to run a geoprocessing Tool

Source: Internet
Author: User

Eachhttp: // response

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, objects, or native types for simple parameters. an example of a native type is the number of neighbors parameters on the calculatedistanceband tool. 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, the output, and the buffer distance properties of buffer so the call to the tool is easier to read.

Be aware that the syntax for specifying fields in Query expressions is different for different data formats. Some of the most commonly encountered differences are below.

    • For ArcSDE, the field names are not wrapped, for example, my_field.
    • For file or personal geodatabases the field names are wrapped in square brackets, for example, [my_field].
    • For all others, the field names are wrapped in double quotes, for example, "my_field ".
    • Access uses '*' and '? As string wildcards rather than '%' and '_' in all other formats

The execute method below uses null reference instead of an itrackcancel object. 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.

 
// Initialize the geoprocessorgeoprocessor Gp = new geoprocessor (); buffer buffertool = new buffer ("C:/data/USA. GDB/wind. SHP "," C:/data/USA. GDB/bufferedwind. SHP "," distance "implements gp.exe cute (buffertool, null );

Below are the system toolbox names and their namespaces:

  • Analysis tools? Com. ESRI. ArcGIS. geoprocessing. Tools. analysistools
  • Conversion tools? Com. ESRI. ArcGIS. geoprocessing. Tools. conversiontools
  • Data management tools? Com. ESRI. ArcGIS. geoprocessing. Tools. datamanagementtools
  • 3D Analyst tools? Com. ESRI. ArcGIS. geoprocessing. Tools. analyst3dtools
  • Cartography tools? Com. ESRI. ArcGIS. geoprocessing. Tools. cartographytools
  • Coverage tools? Com. ESRI. ArcGIS. geoprocessing. Tools. coveragetools *
  • Geocoding tools? Com. ESRI. ArcGIS. geoprocessing. Tools. geocodingtools
  • Geostatistical analyst tools? Com. ESRI. ArcGIS. geoprocessing. Tools. geostatisticalanalysttools
  • Linear referencing tools? Com. ESRI. ArcGIS. geoprocessing. Tools. linearreferencingtools
  • Multidimension tools? Com. ESRI. ArcGIS. geoprocessing. Tools. multidimensiontools
  • Network analyst tools? Com. ESRI. ArcGIS. geoprocessing. Tools. networkanalysttools
  • Spatial Analyst tools? Com. ESRI. ArcGIS. geoprocessing. Tools. spatialanalysttools
  • Spatial Statistics tools? Com. ESRI. ArcGIS. geoprocessing. Tools. spatialstatisticstools
  • Tracking analyst tools? Com. ESRI. ArcGIS. geoprocessing. Tools. trackinganalysttools

* (Only available with a ArcInfo Workstation install and not available on Linux)

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 IDE integration framework built in to eclipse or the command line, you can generate a geoprocessing Assembly to represent any custom toolbox. for instructions please see the documentation on wrapping a custom tool.

Executing a tool by name

It is not a prerequisite to generate a geoprocessing Assembly to represent your m toolbox. there is an alternative way to use the execute method on the geoprocessor. the execute method is overloaded and has an additional parameters which allows you to execute a tool by specifying the Tool Name, the parameters to the tool, and the itrackcancel object.

Here is an example of executing a model tool called caluatebestpath located in the bestpath toolbox:

 
// Initialize the geoprocessorgeoprocessor Gp = new geoprocessor (); // Add the bestpath toolboxgp. addtoolbox ("C:/sandiego/bestpath. tbx "); // generate the array of parametersvararray parameters = new vararray (); parameters. add ("C:/sandiego/source. SHP "); parameters. add ("C:/sandiego/destination. SHP "); parameters. add ("C:/sandiego/bestpath. SHP "); // execute the model tool by namegp.exe cute (" calculatebestpath ", parameters, null );

See also:

Wrapping a custom tool

Executing geoprocessing server tools

With ArcGIS 9.2 desktop and engine, you can now execute geoprocessing tools that have been published on An ArcGIS Server. server tools can be accessed and executed the same as custom tools. first, you must add the custom toolbox by generating a geoprocessing toolbox Assembly to represent the toolbox or by adding the custom toolbox using the addtoolbox method.

Toolboxes can be published on a local area network (LAN) or published as a Web Service on the Internet. to access the geoprocessing server tools you must add the toolbox. here are examples for adding toolboxes published on An ArcGIS Server using the addtoolbox method:

// Add the bestpath toolbox published on a LAN // entered as server name; Folder/toolboxgp. addtoolbox (javaslame7; sandiego/bestpath "); // Add the bestpath toolbox published as a geoprocessing Web Service // entered as Web Service; Folder/toolboxgp. addtoolbox (effecttp: // flame7: 8399/ArcGIS/services; sandiego/bestpath ");

Toolboxes published on the server may contain tools that require you to enter the input parameter values by specifying the path to the data or, contain tools that require the user to choose from a list of inputs referencing layers in a map document on the ArcGIS Server. see ArcGIS Server and geoprocessing for further information about publishing geoprocessing tools to An ArcGIS Server.

Here are two examples between strating how to executing server tools:

  1. execute a tool by reference. the input parameters reference layers in a map document which contains the toolbox and tools.

     // intialize the geoprocessorgeoprocessor Gp = new geoprocessor (); // Add the bestpath toolboxgp. addtoolbox ("http: // flame7: 8399/ArcGIS/services; GP/bestpathtoolbox"); // inputs reference layers in a map document on the server. arraylist parameters = new arraylist (); parameters. add ("Source"); parameters. add ("destination"); // execute the server tool by referenceigeoprocessorresult result; Result = gp.exe cute ("calculatebestpath", parameters, null); 
  2. Execute a tool by value. The input parameters are shapefiles on a local drive.

    // Intialize the geoprocessorgeoprocessor Gp = new geoprocessor (); // Add the bestpath toolboxgp. addtoolbox ("http: // flame7: 8399/ArcGIS/services; GP/bestpathtoolbox"); // input values are data on a local drive. arraylist parameters = new arraylist; parameters. add ("C: \ sandiego \ source. SHP "); parameters. add ("C: \ sandiego \ destination. SHP "); // execute the server tool by referenceigeoprocessorresult result; Result = gp.exe cute (" calculatebestpath ", parameters, null );

Geoprocessing results

All geoprocessing tools generate results. the execute method returns an igeoprocessorresult object which manages the results. the result object is necessary for supporting geoprocessing with ArcGIS Server. this result object will have the return value of a tool when executed; it will return the status of a job on the server, it will return the result ID, and provide the geoprocessing messages.

Here is an example of executing a server tool and getting it's status and messages:

 // intialize the geoprocessorgeoprocessor Gp = new geoprocessor (); // Add the bestpath toolboxgp. addtoolbox ("http: // flame7: 8399/ArcGIS/services; GP/bestpathtoolbox"); // input values are data on a local drive. arraylist parameters = new arraylist (); parameters. add ("C: \ sandiego \ source. SHP "); parameters. add ("C: \ sandiego \ destination. SHP "); // execute the server tool by referenceigeoprocessorresult result; Result = gp.exe cute (" calculatebestpath ", parameters, null); While (result. getstatus () = esrijobstatus. esrijobsucceeded) {for (INT I = 0; I <= result. getmessagecount ()-1; I ++) {system. out. println (result. getmessagecount () ;}

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.