开发者社区> 文艺小青年> 正文

学习在 ArcEngine 中使用 Geoprocessing

简介:
+关注继续查看

Geoprocessing对于ArcGIS使用者来说,是一种非常方便实用的工具,它可以利用ArcToolbox中的各种工具为我们的地理空间工作流进行框架建模,自动执行空间分析与处理。

    过去我们可以在ArcToolbox中新建Model,或是写python脚本、AML来构建新的模型,现在ArcEngine 9.2单独提供了com.esri.arcgis.geoprocessing.tools工具包,使得在二次开发中通过Geoprocessing构建应用模型,将ArcGIS众多分析工具集成到我们的应用中成为现实。

    我们就在ArcEngine 9.2 for Java环境中看看如何使用Geoprocessing。

import com.esri.arcgis.geoprocessing.GeoProcessor;
import com.esri.arcgis.geoprocessing.tools.analysistools.Clip;
// Initialize the GeoProcessor 
GeoProcessor gp = new GeoProcessor();
Clip clip= new Clip("c:/data/mjrroads.shp", "c:/data/coasts.shp",  "c:/output/clipOutput.shp");

    
    设置参数

Clip clip = new Clip();
clip.setInFeatures = "c:/data/mjrroads.shp";
clip.setClipFeatures = "c:/data/coasts.shp";
clip.setOutFeatureClass = "c:/output/clipOutput.shp";

    
    代码中Clip构造方法,以及clip对象参数的设置,均和ArcToolbox-->Clip工具相对应。


    Geoprocessor类用来执行Geoprocessing相关工具的操作,geoprocessor的角色是一种helper对象,它的重载方法execute用来运行之前所定义的操作集。

GP.execute(clip, null);

 

    com.esri.arcgis.geoprocessing.IGeoProcessorResult接口的对象可以捕获execute执行后的结果。

// Intialize the Geoprocessor
GeoProcessor gp = new GeoProcessor();
// 使用web service中的toolbox
gp.addToolbox("http://flame7:8399/arcgis/services;GP/Bestpathtoolbox");
// 导入本地的shape文件 
ArrayList parameters = new ArrayList;
parameters.add("C:\\sandiego\\source.shp"); 
parameters.add("C:\\sandiego\\destination.shp");
// 捕获execute执行结果
IGeoProcessorResult result;
result = gp.execute("CalculateBestPath", parameters, null);

 

    名字冲突

    和OO语言处理名字冲突一样,当可能出现名字冲突时,可以使用全名来唯一指定所使用的工具:

ArcToolbox-->Analysis Tools-->Extract-->Clip
ArcToolbox-->Data Management-->Raster-->Clip

com.esri.arcgis.geoprocessing.tools.analysistools.Clip
com.esri.arcgis.geoprocessing.tools.datamanagementtools.Clip

 

    Geoprocessing编程的时候,还可以使用AO作为输入的工具

// Initialize the Geoprocessor 
GPUtilities gpUtilities = new GPUtilities();
IFeatureClass inputFeatureClass = gpUtilities.openFeatureClassFromString(inputData+"/canada/mjrroads.shp");
IFeatureClass clipFeatureClass = gpUtilities.openFeatureClassFromString(inputData+"/canada/coasts.shp");
Clip clip = new Clip(inputFeatureClass, clipFeatureClass, outputDirectory+"/clipOutput.shp");
gp.execute(clip, null);

 

    关于GPUtilities和Geoprocessor区别,可以看看这两段描述以及各自的类方法:

The GPUtilities object is mainly intended for developers building custom 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.

    ArcToolbox工具都有自己的环境设置,一般情况下我们使用默认值,在AE中可以用setEnvironmentValue方法来设置环境变量的值

// 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/Nad 1983/NAD 1983 UTM Zone 21N.prj");

// Reset the environment values to their defaults.
gp.resetEnvironments();

 

    需要注意的是,在使用Geoprocessing建模进行各种空间操作时,我们需要相应的license授权来完成这些操作,如Spatial Join需要ArcInfo License,各种级别License描述可以参考下图:


本文转自Flyingis博客园博客,原文链接:http://www.cnblogs.com/flyingis/archive/2007/04/05/700655.html,如需转载请自行联系原作者

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
文章
问答
文章排行榜
最热
最新
相关电子书
更多
低代码开发师(初级)实战教程
立即下载
阿里巴巴DevOps 最佳实践手册
立即下载
冬季实战营第三期:MySQL数据库进阶实战
立即下载