Flyingis

Talking and thinking freely !
Flying in the world of GIS !
随笔 - 156, 文章 - 16, 评论 - 589, 引用 - 0
数据加载中……

Geoprocessing 消息机制

    作者:Flyingis

    ArcToolbox每个工具执行之后,都会向Geoprocessor返回消息,包括操作何时开始,使用哪些参数,操作的进度,以及可能出现的问题和错误。消息的种类包括常规消息、警告、错误,GPMessage类可以包含消息的文本及严重等级。

    首先,Geoprocessor.getMessage()方法可以捕获最后一个工具执行后返回的错误消息

String messages = gp.getMessages(2);
System.out.println(messages);

    如何使用GPMessage

//if there was an error then you want to loop the messages
//returned by the geoprocessor to look for the error
GPMessages gpMessages = (GPMessages)gp.getReturnMessages();
for(int i = 0;  i gpMessages.getCount(); i++{
      System.out.println(gpMessages.getMessage(i).getDescription());
}

    可以看出,上面都是通过GeoProcessor的方法来获取消息,除此之外还可以使用IGeoProcessorResult接口,从功能上来说它们没有多少区别。

// Execute Union
IGeoProcessorResult pResult = gp.execute(uniontool, null); 
if (pResult.getMessageCount() > 0)  
      
for(int i = 0;  i <= pResult.getMessageCount() - 1; i++){
            System.out.println(pResult.getMessageCount());
      }

}

    另外我们还可以自定义输出的方法,根据程序执行的过程,可以添加的方法有AddMessage、AddWarning、AddError。下面的示例将feature class从一个工作区复制到另外一个工作区,并跟踪显示每个文件复制的情况。

IGpEnumList fcs = gp.listFeatureClasses("""","");
Copy copy 
= new Copy();
String fc 
= fcs.next();
while (! "".equals(fc)){
      gp.addMessage(
"Copying " + fc + " to file gdb" );
      copy.setInData(fc);
      copy.setOutData(
"C:/temp/eric.gdb" + "/" + fc);
      
try {
            gp.execute(copy, 
null);
      }
 catch (Exception e) {
            gp.addError(
"COPY FAILED! " + gp.getMessage(2));
      }

      fc 
= fcs.next();
}

posted on 2007-04-10 15:58 Flyingis 阅读(3548) 评论(0)  编辑  收藏 所属分类: ArcEngine


只有注册用户登录后才能发表评论。


网站导航: