学习在 ArcEngine 中使用 Geoprocessing
??? 作者:Flyingis
??? Geoprocessing對于ArcGIS使用者來說,是一種非常方便實用的工具,它可以利用ArcToolbox中的各種工具為我們的地理空間工作流進行框架建模,自動執(zhí)行空間分析與處理。
??? 過去我們可以在ArcToolbox中新建Model,或是寫python腳本、AML來構(gòu)建新的模型,現(xiàn)在ArcEngine 9.2單獨提供了com.esri.arcgis.geoprocessing.tools工具包,使得在二次開發(fā)中通過Geoprocessing構(gòu)建應(yīng)用模型,將ArcGIS眾多分析工具集成到我們的應(yīng)用中成為現(xiàn)實。
??? 我們就在ArcEngine 9.2 for Java環(huán)境中看看如何使用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");
???
??? 設(shè)置參數(shù)
clip.setInFeatures?=?"c:/data/mjrroads.shp";
clip.setClipFeatures?=?"c:/data/coasts.shp";
clip.setOutFeatureClass?=?"c:/output/clipOutput.shp";
???
??? 代碼中Clip構(gòu)造方法,以及clip對象參數(shù)的設(shè)置,均和ArcToolbox-->Clip工具相對應(yīng)。
??? Geoprocessor類用來執(zhí)行Geoprocessing相關(guān)工具的操作,geoprocessor的角色是一種helper對象,它的重載方法execute用來運行之前所定義的操作集。
GP.execute(clip,?null);?
????com.esri.arcgis.geoprocessing.IGeoProcessorResult接口的對象可以捕獲execute執(zhí)行后的結(jié)果。
//?Intialize?the?GeoprocessorGeoProcessor?gp?=?new?GeoProcessor();
//?使用web?service中的toolbox
gp.addToolbox("http://flame7:8399/arcgis/services;GP/Bestpathtoolbox");
//?導(dǎo)入本地的shape文件?
ArrayList?parameters?=?new?ArrayList;
parameters.add("C:\\sandiego\\source.shp");?
parameters.add("C:\\sandiego\\destination.shp");
//?捕獲execute執(zhí)行結(jié)果
IGeoProcessorResult?result;
result?=?gp.execute("CalculateBestPath",?parameters,?null);
?
??? 名字沖突
??? 和OO語言處理名字沖突一樣,當(dāng)可能出現(xiàn)名字沖突時,可以使用全名來唯一指定所使用的工具:
ArcToolbox-->Analysis Tools-->Extract-->Clip
ArcToolbox-->Data Management-->Raster-->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);
?
??? 關(guān)于GPUtilities和Geoprocessor區(qū)別,可以看看這兩段描述以及各自的類方法:
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工具都有自己的環(huán)境設(shè)置,一般情況下我們使用默認值,在AE中可以用setEnvironmentValue方法來設(shè)置環(huán)境變量的值
//?Get?the?Cell?Size?environment?valuegp.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建模進行各種空間操作時,我們需要相應(yīng)的license授權(quán)來完成這些操作,如Spatial Join需要ArcInfo License,各種級別License描述可以參考下圖:
轉(zhuǎn)載于:https://www.cnblogs.com/flyingis/archive/2007/04/05/700655.html
《新程序員》:云原生和全面數(shù)字化實踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀總結(jié)
以上是生活随笔為你收集整理的学习在 ArcEngine 中使用 Geoprocessing的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。