ArcEngine查询栅格像元属性值

  前期开发了一个三维交互查询要素属性值的功能,用到了FeatureLayer实现的IIdentify2接口。如果想实现在SceneControl中查询栅格像元属性值应该怎么做?

  首先查询OMD,想找到IIdentify2类似的接口。而IRasterLayer并没有直接实现IIdentify2接口。倒是其父类DisplayLayer实现了IIdentify接口。IIdentify接口只有一个Identify方法:帮助中其描述如下:

When the IIdentify interface is on a map layer, the Identify method returns an array of FeatureIdentifyObject objects.

On a FeatureIdentifyObject, you can do a QI to the IIdentifyObj interface to get more information about the identified feature. The IIdentifyObj interface returns the window handle, layer, and name of the feature; it has methods to flash the feature in the display and to display a context menu at the Identify location.

This method performs an identify operation with the provided geometry.  When identifying layers, typically a small envelope is passed in rather than a point to account for differences in the precision of the display and the feature geometry.

   感觉很奇怪,父类Identify方法怎么返回一个 FeatureIdentifyObject的Array数组?于是通过IIdentifyObj找到了RasterIdentifyObj对象。栅格图层返回的应该是RasterIdentifyObj数组,这样把Array对象中的要素做一下类型转换就可以获得查询结果了。我写了代码却出问题,原因有两方面,一是过滤栅格图层出错,另外是栅格调用Identify方法时传入的是一个点,而不应该是一个缓冲圆。百度中输入RasterIdentifyObj找到如下参考程序http://www.cnblogs.com/zany-hui/articles/1527563.html。测试没有问题,和我想的一致!

  看来帮助中的描述是有问题的,要素图层Identify返回FeatureIdentifyObject数组,而栅格图层返回的是RasterIdentifyObj数组。

利用IRaster.Read接口可以读取每个PixelBlock的值,输入的参数是行和列,而不是地图坐标
利用IIdentify接口可以读取指定坐标的PixelBlock的值,代码如下
IIdentify identify = (IIdentify)rasterlayer;//rasterLayer是打开的栅格图层
if(identify=null)
return;
IPoint point = new PointClass();
point.PutCoords(longitude, latitude);
IArray array=identify.Identify(point);
if (array != null)
   {
     int arraycount = array.Count;
     for (int i = 0; i < arraycount; i++)
      {
       IRasterIdentifyObj rasterIdentifyobj = (IRasterIdentifyObj)array.get_Element(i);
       if (rasterIdentifyobj !=null&&rasterIdentifyobj.MapTip !="")
       {
        MessageBox("Value:"+rasterIdentifyobj.MapTip)
        }
     } 
}

ArcGIS 的架构设计的真的很棒!

posted @ 2013-04-04 13:37  太一吾鱼水  阅读(2460)  评论(4编辑  收藏  举报