Geoprocessing 数据批处理

    作者: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----------- " );
ExpandedBlockStart.gifContractedBlock.gif
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();
ExpandedBlockStart.gifContractedBlock.gif    
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);
ExpandedBlockStart.gifContractedBlock.gif
while  ( !   "" .equals(raster))  {
    System.out.println(
"\n------------Building pyramids for: " + raster + "----------");
    gp.execute(buildPyramids, 
null);
    raster 
= rasters.next();
}

    关于各种list方法TYPE类型,可以参考下表

MethodType Keywords
ListDatasetsAll, Feature, Coverage, RasterCatalog, CAD, VPF, TIN, Topology
ListFeatureClassesAll, Point, Label, Node, Line, Arc, Route, Polygon, Region
ListFieldsAll, SmallInteger, Integer, Single, Double, String, Date, OID, Geometry, Blob
ListWorkspacesAll, Coverage, Access, SDE, Folder
ListTablesAll, 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 
=   "" ;
ExpandedBlockStart.gifContractedBlock.gif
while  ( !   "" .equals(polygon)) {
 polygonsToUnion 
+= polygon;
 polygon 
= polygonFCs.next();
ExpandedSubBlockStart.gifContractedSubBlock.gif 
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 ;
ExpandedBlockStart.gifContractedBlock.gif
while  ( !   "" .equals(polygon)) {
ExpandedSubBlockStart.gifContractedSubBlock.gif 
if ("center".equals(polygon)){     
     row 
= polygon + " 1";     
ExpandedSubBlockStart.gifContractedSubBlock.gif }
 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而言,这里体现的是程序代码带给我们的方便。

### ArcGIS 中进行辐射定标的批处理方法 在地理信息系统的数据分析过程中,ArcGIS 提供了一系列功能强大的工具用于遥感图像的预处理和分析。其中,辐射定标是一个重要的步骤,它将传感器记录的数字化数值转换为物理单位(如反射率或亮度温度),以便进一步的空间分析和建模。 #### 使用 ModelBuilder 实现辐射定标的批处理 ModelBuilder 是 ArcGIS 的一种可视化编程环境,可以用来构建复杂的地理处理工作流。通过创建一个模型并将其保存为脚本工具,可以在多个输入数据集上执行相同的操作序列。以下是具体的方法: 1. **打开 ModelBuilder 工具** 在 ArcMap 或 ArcCatalog 中启动 ModelBuilder,并设置参数以接受多个栅格作为输入[^3]。 2. **添加 Raster Calculator 工具** 将 `Raster Calculator` 添加到模型中,利用其表达式语法完成从数字化数 (DN) 到物理量的转换。例如,对于 Landsat 数据,可以通过以下公式计算表面反射率: \[ \text{Reflected\_TOA} = (\text{Ml} * DN + Al)/\cos(\theta_s) \] 这里 \( Ml \) 和 \( Al \) 分别表示增益系数和偏移值,\( \theta_s \) 表示太阳天顶角[^1]。 3. **配置批处理选项** 右键单击已定义好的工具节点,在弹出菜单中选择“运行模式”,然后切换至“按列表”方式支持多场景影像的同时导入导出。 4. **保存并共享成果** 完成调试之后可将此流程打包发布成为独立扩展插件或者 Python 脚本形式分发给其他同事使用。 #### 编写自定义 Python 脚本来简化过程 如果更倾向于编码,则可以直接编写一段基于 arcpy 库调用相应 geoprocessing 函数实现自动化作业逻辑如下所示: ```python import os from arcpy.sa import * def batchRadianceCalibration(input_folder, output_folder): # 遍历指定路径下的所有tif文件 for filename in os.listdir(input_folder): if not filename.endswith(".tif"): continue input_raster_path = os.path.join(input_folder,filename) # 假设我们已经知道Landsat波段对应的ML AL参数 ml_value=0.0003342; al_value=-0.1; out_name=os.path.splitext(filename)[0]+"_calibrated.tif" calibrated_image=(ml_value*Float(input_raster_path)+al_value) calibrated_image.save(os.path.join(output_folder,out_name)) if __name__ == '__main__': input_dir="path/to/input/images/" output_dir="path/to/output/calibrated_images/" batchRadianceCalibration(input_dir,output_dir) ``` 以上代码片段展示了如何读取本地磁盘上的 TIFF 文件集合,并逐一对它们实施简单的线性变换从而达到校正目的[^2]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值