学习在 ArcEngine 中使用 Geoprocessing

简介: http://blog.sina.com.cn/s/blog_4d46bf160100fj8s.html 摘要:Geoprocessing对于ArcGIS使用者来说,是一种非常方便实用的工具,它可以利用ArcToolbox中的各种工具为我们的地理空间工作流进行框架建模,自动执行空间分析与处理。
摘要:Geoprocessing对于ArcGIS使用者来说,是一种非常方便实用的工具,它可以利用ArcToolbox中的各种工具为我们的地理空间工作流进行框架建模,自动执行空间分析与处理。现在ArcEngine 9.2单独提供了com.esri.arcgis.geoprocessing.tools工具包,使得在二次开发中通过Geoprocessing构建应用模型,将ArcGIS众多分析工具集成到我们的应用中成为现实。看看在ArcEngine for Java环境中如何使用它。


    Geoprocessing对于ArcGIS使用者来说,是一种非常方便实用的工具,它可以利用ArcToolbox中的各种工具为我们的地理空间工作流进行框架建模,自动执行空间分析与处理。
    过去我们可以在ArcToolbox中新建Model,或是写python脚本、AML来构建新的模型,现在ArcEngine 9.2单独提供了com.esri.arcgis.geoprocessing.tools工具包,使得在二次开发中通过Geoprocessing构建应用模型,将ArcGIS众多分析工具集成到我们的应用中成为现实。
    我们就在ArcEngine 9.2 for Java环境中看看如何使用Geoprocessing。
  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 clip= new Clip("c:/data/mjrroads.shp", "c:/data/coasts.shp",  "c:/output/clipOutput.shp");
复制代码

   
    设置参数

  1. Clip clip = new Clip();
  2. clip.setInFeatures = "c:/data/mjrroads.shp";
  3. clip.setClipFeatures = "c:/data/coasts.shp";
  4. clip.setOutFeatureClass = "c:/output/clipOutput.shp";
复制代码

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



    Geoprocessor类用来执行Geoprocessing相关工具的操作,geoprocessor的角色是一种helper对象,它的重载方法execute用来运行之前所定义的操作集。
  1. GP.execute(clip, null);
复制代码

    com.esri.arcgis.geoprocessing.IGeoProcessorResult接口的对象可以捕获execute执行后的结果。
  1. // Intialize the Geoprocessor
  2. GeoProcessor gp = new GeoProcessor();
  3. // 使用web service中的toolbox
  4. gp.addToolbox("http://flame7:8399/arcgis/services;GP/Bestpathtoolbox");
  5. // 导入本地的shape文件
  6. ArrayList parameters = new ArrayList;
  7. parameters.add("C:\\sandiego\\source.shp");
  8. parameters.add("C:\\sandiego\\destination.shp");
  9. // 捕获execute执行结果
  10. IGeoProcessorResult result;
  11. result = gp.execute("CalculateBestPath", parameters, null);
复制代码


    名字冲突
    和OO语言处理名字冲突一样,当可能出现名字冲突时,可以使用全名来唯一指定所使用的工具:
    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
复制代码


    Geoprocessing编程的时候,还可以使用AO作为输入的工具
  1. // Initialize the Geoprocessor
  2. GPUtilities gpUtilities = new GPUtilities();
  3. IFeatureClass inputFeatureClass = gpUtilities.openFeatureClassFromString(inputData+"/canada/mjrroads.shp");
  4. IFeatureClass clipFeatureClass = gpUtilities.openFeatureClassFromString(inputData+"/canada/coasts.shp");
  5. Clip clip = new Clip(inputFeatureClass, clipFeatureClass, outputDirectory+"/clipOutput.shp");
  6. 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方法来设置环境变量的值
  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/Nad 1983/NAD 1983 UTM Zone 21N.prj");

  6. // Reset the environment values to their defaults.
  7. gp.resetEnvironments();
复制代码


    需要注意的是,在使用Geoprocessing建模进行各种空间操作时,我们需要相应的license授权来完成这些操作,如Spatial Join需要ArcInfo License,各种级别License描述可以参考下图:
相关实践学习
基于阿里云DeepGPU实例,用AI画唯美国风少女
本实验基于阿里云DeepGPU实例,使用aiacctorch加速stable-diffusion-webui,用AI画唯美国风少女,可提升性能至高至原性能的2.6倍。
相关文章
|
12月前
|
前端开发 JavaScript 算法
ThreeJS开篇
ThreeJS开篇
100 0
|
存储 编解码 人工智能
学术论文插图要求简介
学术论文插图要求简介
94 0
|
Web App开发 数据可视化 Python
[雪峰磁针石博客]Bokeh数据可视化工具1快速入门
简介 数据可视化python库参考 python数据可视化库最突出的为Matplotlib、Seaborn和Bokeh。前两个,Matplotlib和Seaborn,绘制静态图。Bokeh可以绘制交互式图。
|
Java Android开发 数据格式
阅读手札:《Android开发艺术探索》(二)
在 《阅读手札:《Android开发艺术探索》(一)》中主要介绍了Activity的生命周期以及异常处理、启动模式、意图过滤器。本篇文章主要介绍的是《Android开发艺术探索》的第二章 IPC机制 个人评语:第二章的内容非常多(第二章近90页内容),内容有IPC机制基本概念;序列化Serializable、Parcelable;Binder;实现IPC的多种方式;Binder连接池内容非常多,但还是要耐着性子分析完。
1449 0
|
Android开发
阅读手札:《Android开发艺术探索》(一)
《Android开发艺术探索》这本书在Android开发界内可谓口碑极佳,他的作者任玉刚在百度担任Android资深开发工程师。我的一个初中朋友现在深圳百度做Android研发,上周去深圳找他玩的时候碰巧在他电脑桌上看到了这本书,他谈到这本书内容多、有深度且知识点非常系统值得反复阅读。
1329 0
|
存储 定位技术 容器