Geoprocessing 数据批处理

简介:

  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.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.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.gif 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 = "";
ExpandedBlockStart.gif while (! "".equals(polygon)) {
 polygonsToUnion += polygon;
 polygon = polygonFCs.next();
ExpandedSubBlockStart.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.gif while (! "".equals(polygon)) {
ExpandedSubBlockStart.gif if ("center".equals(polygon)){     
     row = polygon + " 1";     
ExpandedSubBlockStart.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而言,这里体现的是程序代码带给我们的方便。


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

相关文章
|
2月前
|
监控 搜索推荐 数据挖掘
Flink流处理与批处理大揭秘:实时与离线,一文让你彻底解锁!
【8月更文挑战第24天】Apache Flink 是一款开源框架,擅长流处理与批处理。流处理专攻实时数据流,支持无限数据流及事件驱动应用,实现数据的连续输入与实时处理。批处理则聚焦于静态数据集,进行一次性处理。两者差异体现在处理方式与应用场景:流处理适合实时性要求高的场景(例如实时监控),而批处理更适用于离线数据分析任务(如数据挖掘)。通过提供的示例代码,读者可以直观理解两种模式的不同之处及其实际应用。
65 0
|
5月前
|
消息中间件 分布式计算 Java
流计算与批处理的区别是什么?请举例说明。
流计算与批处理的区别是什么?请举例说明。
85 0
|
Shell
添加批处理扩展
添加批处理扩展
39 1
|
数据采集 数据库
数据导入任务并行化
数据导入任务并行化
63 0
|
SQL 关系型数据库 MySQL
批处理|学习笔记
快速学习批处理
批处理|学习笔记
|
监控 Shell 调度
使用EHPC实现“完美并行”的高效批处理方案
在高性能计算场景中,用户一次业务计算可以划分为大量的任务,每个任务的处理逻辑相同,但是输入文件、参数设置和输出文件不同。在此,给出了基于阿里云弹性高性能计算场景的数组作业解决方案——利用E-HPC集成的作业调度系统,将用户的批处理任务自动分配到数组作业,实现在云超算集群上高并发执行。
1896 0
|
Java
什么是批处理
什么是批处理:批处理就是多个dos命令组成的,双击可执行里面的命令。(微软系统) 批处理:桌面文件以双击就能打开,而java一双击是打不开的因为java是一个class文件他需要虚拟机得运行才能打开。
2255 0
|
Go 数据安全/隐私保护
|
人工智能 数据安全/隐私保护 Windows
|
Shell Perl Android开发