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.
- Import com. ESRI. ArcGIS. geoprocessing. geoprocessor;
- Import com. ESRI. ArcGIS. geoprocessing. Tools. analysistools. Clip;
- // Initialize the geoprocessor
- Geoprocessor Gp = new geoprocessor ();
- Clip = new clip ("C:/data/mjrroads. SHP", "C:/data/coasts. SHP ", "C:/output/clipoutput. SHP ");
CopyCode
Set parameters
- Clip = new clip ();
- Clip. setinfeatures = "C:/data/mjrroads. SHP ";
- Clip. setclipfeatures = "C:/data/coasts. SHP ";
- 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.
- Gp.exe cute (clip, null );
Copy code
The object of the COM. ESRI. ArcGIS. geoprocessing. igeoprocessorresult interface can capture the execution result after execute.
- // Intialize the geoprocessor
- Geoprocessor Gp = new geoprocessor ();
- // Use toolbox in Web Service
- GP. addtoolbox ("http: // flame7: 8399/ArcGIS/services; GP/bestpathtoolbox ");
- // Import a local shape File
- Arraylist parameters = new arraylist;
- Parameters. Add ("C: \ sandiego \ source. SHP ");
- Parameters. Add ("C: \ sandiego \ destination. SHP ");
- // Capture execute execution results
- Igeoprocessorresult result;
- 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
- Com. ESRI. ArcGIS. geoprocessing. Tools. analysistools. Clip
- Com. ESRI. ArcGIS. geoprocessing. Tools. datamanagementtools. Clip
Copy code
When programming geoprocessing, you can also use AO as the input tool.
- // Initialize the geoprocessor
- Gputilities = new gputilities ();
- Ifeatureclass inputfeatureclass = gputilities. openfeatureclassfromstriNg (inputdata + "/Canada/mjrroads. SHP ");
- Ifeatureclass clipfeatureclass = gputilities. openfeatureclassfromstriNg (inputdata + "/Canada/coasts. SHP ");
- Clip = new clip (inputfeatureclass, clipfeatureclass, outputdirectory + "/clipoutput. SHP ");
- 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.
- // Get the cell size Environment Value
- GP. setenvironmentvalue ("cellsize", double. valueof (10.0 ));
- String Env = (string) GP. getenvironmentvalue ("cellsize ");
- // Set the output Coordinate System Environment
- GP. setenvironmentvalue ("outputcoordinatesystem", "C:/program files/ArcGIS/coordinate systems/Projected coordinate systems/UTM/SAD 1983/panel 1983 UTM Zone 21N. prj ");
- // Reset the environment values to their ults.
- 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: