Learning how to use geoprocessing in arcengine

Source: Internet
Author: User
Http://blog.sina.com.cn/s/blog_4d46bf160100fj8s.html
Abstract: geoprocessing is a very convenient and practical tool for ArcGIS users. It can use various tools in arctoolbox to model the framework of our geospatial workflow, automatic Space Analysis and Processing. Currently, arcengine 9.2 provides COM. ESRI. arcGIS. geoprocessing. the tools toolkit makes it a reality to build an application model through geoprocessing in the secondary development, and integrate multiple ArcGIS analysis tools into our applications. See how to use it in the arcengine for Java environment.


Geoprocessing is a very convenient and practical tool for ArcGIS users. It can use various tools in arctoolbox to perform framework modeling for our geospatial workflows and automatically perform spatial analysis and processing.
In the past, we could create a model in arctoolbox, or write Python scripts and AML to build a new model. Now arcengine 9.2 independently provides COM. ESRI. arcGIS. geoprocessing. the tools toolkit makes it a reality to build an application model through geoprocessing in the secondary development, and integrate multiple ArcGIS analysis tools into our applications.
Let's take a look at how to use geoprocessing in the arcengine 9.2 for Java environment.
    1. Import com. ESRI. ArcGIS. geoprocessing. geoprocessor;
    2. Import com. ESRI. ArcGIS. geoprocessing. Tools. analysistools. Clip;
    3. // Initialize the geoprocessor
    4. Geoprocessor Gp = new geoprocessor ();
    5. Clip = new clip ("C:/data/mjrroads. SHP", "C:/data/coasts. SHP ", "C:/output/clipoutput. SHP ");

CopyCode

 
 Set parameters

    1. Clip = new clip ();
    2. Clip. setinfeatures = "C:/data/mjrroads. SHP ";
    3. Clip. setclipfeatures = "C:/data/coasts. SHP ";
    4. Clip. setoutfeatureclass = "C:/output/clipoutput. SHP ";

Copy code

 
 In the code, the clip constructor and clip object parameter settings correspond to the arctoolbox --> clip tool.


 The geoprocessor class is used to perform operations on geoprocessing-related tools. The role of geoprocessor is a helper object, and its overload method execute is used to run the previously defined operation set.

    1. Gp.exe cute (clip, null );

Copy code

 The object of the COM. ESRI. ArcGIS. geoprocessing. igeoprocessorresult interface can capture the execution result after execute.

    1. // Intialize the geoprocessor
    2. Geoprocessor Gp = new geoprocessor ();
    3. // Use toolbox in Web Service
    4. GP. addtoolbox ("http: // flame7: 8399/ArcGIS/services; GP/bestpathtoolbox ");
    5. // Import a local shape File
    6. Arraylist parameters = new arraylist;
    7. Parameters. Add ("C: \ sandiego \ source. SHP ");
    8. Parameters. Add ("C: \ sandiego \ destination. SHP ");
    9. // Capture execute execution results
    10. Igeoprocessorresult result;
    11. Result = gp.exe cute ("calculatebestpath", parameters, null );

Copy code

 Name Conflict
 Like the name conflict in OO language, you can use the full name to uniquely specify the tool used when a name conflict may occur:
 Arctoolbox --> analysis tools --> extract --> clip
 Arctoolbox --> Data Management --> raster --> clip

    1. Com. ESRI. ArcGIS. geoprocessing. Tools. analysistools. Clip
    2. Com. ESRI. ArcGIS. geoprocessing. Tools. datamanagementtools. Clip

Copy code

 When programming geoprocessing, you can also use AO as the input tool.

    1. // Initialize the geoprocessor
    2. Gputilities = new gputilities ();
    3. Ifeatureclass inputfeatureclass = gputilities. openfeatureclassfromstriNg (inputdata + "/Canada/mjrroads. SHP ");
    4. Ifeatureclass clipfeatureclass = gputilities. openfeatureclassfromstriNg (inputdata + "/Canada/coasts. SHP ");
    5. Clip = new clip (inputfeatureclass, clipfeatureclass, outputdirectory + "/clipoutput. SHP ");
    6. Gp.exe cute (clip, null );

Copy code

for differences between gputilities and geoprocessor, you can refer to the descriptions and their respective class methods:
the gputilities object is mainly intended for developers building M tools. for more information about building custom tools, refer to the technical document building geoprocessing function tools.
A geoprocessing tool is executed by a geoprocessor. the geoprocessor is a helper object that simplifies the task of executing tools. toolboxes define the set of tools available for the geoprocessor. toolboxes can be added and removed from the geoprocessor.
the arctoolbox tool has its own environment settings. Generally, we use the default value, in AE, you can use the setenvironmentvalue method to set the value of the environment variable.

    1. // Get the cell size Environment Value
    2. GP. setenvironmentvalue ("cellsize", double. valueof (10.0 ));
    3. String Env = (string) GP. getenvironmentvalue ("cellsize ");

    4. // Set the output Coordinate System Environment   
    5. GP. setenvironmentvalue ("outputcoordinatesystem", "C:/program files/ArcGIS/coordinate systems/Projected coordinate systems/UTM/SAD 1983/panel 1983 UTM Zone 21N. prj ");

    6. // Reset the environment values to their ults.
    7. GP. resetenvironments ();

Copy code

 Note that when geoprocessing modeling is used for various spatial operations, we need the corresponding license authorization to complete these operations. For example, ArcInfo license is required for spatial join. For details about various levels of license descriptions, refer:

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.