|
作者:Flyingis
ArcGIS使用者經常要面對大量的數據處理工作,如果要在自己的程序中使用Geoprocessing,更多的時候我們是要進行對數據進行批處理分析,Geoprocessing為我們提供了豐富的支持批處理的功能。
1.工作空間中查詢所需數據
2.模型處理過程中各種輸入數據的處理
3.枚舉、循環執行
--------------------
1.工作空間中查詢所需數據
要對數據進行批處理操作,首先需要知道工作空間中有哪些數據,怎么從工作空間大量數據中提取出我們所需要的數據。GeoProcessor類為我們提供了一些提取數據的方法。
listDatasets (string wildCard, string datasetType) listFeatureClasses (string wildCard, string featureType, string dataset) listRasters (string wildCard, string rasterType) listTables (string wildCard, string tableType) listToolboxes(string wildCard) listWorkspaces (string wildCard, string workspaceType)
看看代碼段怎么寫:
//list all the featureClasses starting with c
gp.setEnvironmentValue("workspace", inputWorkspace);
IGpEnumList featureClasses = gp.listFeatureClasses("c*", "", "");
String featureClass = featureClasses.next();
System.out.println("-----------Feature Classes starting with c-----------");
 while (! "".equals(featureClass)) {
System.out.println(featureClass);
featureClass = featureClasses.next();
}
通過指定wildCard字符串,搜索所有"c"開頭的feature class,將結果存放在com.esri.arcgis.geoprocessing.IGpEnumList枚舉List中。看到IGpEnumList千萬不要將它和Java數據結構中各種List相提并論,它僅僅具有順序枚舉next和重置查詢指針reset的功能,可以被序列化。
再參考另外兩個例子,相信對在工作空間中查詢數據會有更多的認識。
返回所有面狀要素
System.out.println("\n-----------Polygon Feature Classes-----------");
gp.setEnvironmentValue("workspace", inputWorkspace);
featureClasses = gp.listFeatureClasses("", "polygon", "");
featureClass = featureClasses.next();
 while (! "".equals(featureClass)) {
System.out.println(featureClass);
featureClass = featureClasses.next();
}
返回所有TIF格式的Raster數據
// List all TIF files in the workspace and build pyramids
gp.setEnvironmentValue("workspace", inputWorkspace);
IGpEnumList rasters = gp.listRasters("", "TIF");
String raster = rasters.next();
BuildPyramids buildPyramids = new BuildPyramids(raster);
 while (! "".equals(raster)) {
System.out.println("\n------------Building pyramids for: " + raster + "----------");
gp.execute(buildPyramids, null);
raster = rasters.next();
}
關于各種list方法TYPE類型,可以參考下表
Method |
Type Keywords |
ListDatasets |
All, Feature, Coverage, RasterCatalog, CAD, VPF, TIN, Topology |
ListFeatureClasses |
All, Point, Label, Node, Line, Arc, Route, Polygon, Region |
ListFields |
All, SmallInteger, Integer, Single, Double, String, Date, OID, Geometry, Blob |
ListWorkspaces |
All, Coverage, Access, SDE, Folder |
ListTables |
All, dBASE, INFO |
ListRasters |
All, ADRG, BIL, BIP, BSQ, BMP, CADRG, CIB, ERS, GIF, GIS, GRID, STACK, IMG, JPEG, LAN, SID, SDE, TIF, RAW, PNG, NITF |
2.模型處理過程中各種輸入數據的處理
Geoprocessing計算過程中會要求多個輸入,通常可以用IGpEnumList來捕獲。
gp.setEnvironmentValue("workspace", multiWorkspace);
IGpEnumList polygonFCs = gp.listFeatureClasses("", "polygon", "");
String polygon = polygonFCs.next();
String polygonsToUnion = "";
 while (! "".equals(polygon)) {
polygonsToUnion += polygon;
polygon = polygonFCs.next();
 if (! "".equals(polygon)) {
polygonsToUnion += ";";
}
}
Union union = new Union(polygonsToUnion,outputWorkspace+"/unioned.shp");
gp.execute(union, null);
另外,可以使用表結構來保存每個輸入的參數值,避免全部feature保存在一個字符串中。
// List all feature classes in the workspace.
gp.setEnvironmentValue("workspace", multiWorkspace);
IGpEnumList polygonFCs = gp.listFeatureClasses("", "polygon", "");
//make the value table
GPValueTable gpValueTable = new GPValueTable();
String polygon = polygonFCs.next();
String row = null;
 while (! "".equals(polygon)) {
 if ("center".equals(polygon)) {
row = polygon + " 1";
 } else {
row = polygon + " 2";
}
gpValueTable.addRow(row);
polygon = polygonFCs.next();
}
Union union = new Union(gpValueTable, outputWorkspace+"/unionedValueTable.shp");
gp.execute(union, null);
3.枚舉、循環執行
前面兩點都是針對一個Geoprocessing操作而言,如果需要多個操作,可以用基本程序語言來描述,這分為兩種情況,一是多種Geoprocessing的數據處理,一種是同一Geoprocessing循環執行,相比ArcToolbox而言,這里體現的是程序代碼帶給我們的方便。
|