AE中如何由IFeature 如何获取所对应的FeatureClass

本文提供了一个在ArcGIS中删除要素后的事件处理示例,通过遍历地图中的图层来定位被删除要素的完整路径名,并输出该要素的坐标和ID号。
先获取FeatureClass,然后遍历Map中所有的FeatureLayer,然后比较
FeatureClass与FeatureLayer所对应的FeatureClass。

下面的例子中是在编辑功能里,删除一个Feature后,所触发的事件。目的是找到该Feature所在的FullPathName,并且输出该对象的坐标和ID号。

private void OnDeleteFeatureMethod(object o)
      {          
        IFeature pFeature = o as IFeature;        
        IFeatureClass pFeatureClass = pFeature.Class as IFeatureClass;
      for (int i = 0; i < axMapControl1.Map.LayerCount;i++ )
      {
          IFeatureLayer iFeatureLayer = axMapControl1.get_Layer(i) as IFeatureLayer;
          IFeatureClass iFeatureCla = iFeatureLayer.FeatureClass;
           
              if (iFeatureCla == pFeatureClass)
              {
                  IWorkspace pWorkSpace = m_EngineEditor.EditWorkspace;
                  textBox3.Text += "操作的文件全路径:" + pWorkSpace.PathName + "\\" +      axMapControl1.get_Layer(i).Name + ".shp " + "\r\n";
                  break;
              }
      }

        if (pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
        {
            IGeometry iGe = pFeature.Shape;
            IPoint ipo = new PointClass();
            ipo = iGe as IPoint;
            int a = 0;
            int b = 0;
            axMapControl1.FromMapPoint(ipo, ref a, ref  b);
            textBox3.Text += "删除的点的ID号:" + pFeature.OID + ",坐标:(" + a + "," + b + ")" + "\r\n";
        }
        else if (pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon)
        {
            textBox3.Text += "删除的多边形对象的ID号:" + pFeature.OID + ",坐标:";
            IPolygon pPolygon = (IPolygon)pFeature.Shape;
            int a = 0;
            int b = 0;
            //把该feature强制转换为一个点的集合,再取点的坐标
            IPointCollection pPointCollection = pPolygon as IPointCollection;
            for (int i = 0; i < pPointCollection.PointCount - 1; i++)
            {
                IPoint ipo = pPointCollection.get_Point(i);
                axMapControl1.FromMapPoint(ipo, ref a, ref  b);
                textBox3.Text += "(" + a + "," + b + ")" + "\t";
            }
            textBox3.Text += "\r\n";
        }
        else if (pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline)
        {
            textBox3.Text += "删除的线对象的ID号:" + pFeature.OID + ",其坐标:";
            IPolyline pPolygon = (IPolyline)pFeature.Shape;
            int a = 0;
            int b = 0;
            //把该feature强制转换为一个点的集合,再取点的坐标
            IPointCollection pPointCollection = pPolygon as IPointCollection;
            for (int i = 0; i < pPointCollection.PointCount; i++)
            {
                IPoint ipo = pPointCollection.get_Point(i);
                axMapControl1.FromMapPoint(ipo, ref a, ref  b);
                textBox3.Text += "(" + a + "," + b + ")" + "\t";
            }
            textBox3.Text += "\r\n";
        }

        axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
      }
你可以使用ArcObjects来实现这个功能。具体步骤如下: 1. 在ArcMap中打开需要添加属性值的要素类 2. 打开ArcMap的开发环境,创建一个新的C#项目 3. 在项目中添加对ESRI.ArcGIS.Geodatabase和ESRI.ArcGIS.DataSourcesRaster引用 4. 编写代码来读取栅格图像的像素值,并将其添加到要素类的属性表中 以下是一个示例代码,可以帮助你读取栅格图像的像素值并将其添加到要素类的属性表中: ```csharp //获取要素类 IFeatureClass featureClass = GetFeatureClass(); //获取栅格数据集 IRasterDataset rasterDataset = GetRasterDataset(); //获取栅格数据 IRaster2 raster = (IRaster2)rasterDataset.CreateDefaultRaster(); //获取栅格范围 IRasterProps rasterProps = (IRasterProps)raster; IRasterGeometry geo = rasterProps.Extent as IRasterGeometry; //获取栅格分辨率 double cellSize = rasterProps.MeanCellSize().X; //循环要素 IFeatureCursor cursor = featureClass.Update(null, false); IFeature feature = cursor.NextFeature(); while (feature != null) { //获取要素中心点 IPoint point = (IPoint)feature.ShapeCopy; point.Project(rasterProps.SpatialReference); double x = point.X; double y = point.Y; //获取栅格值 IPnt pnt = new PntClass(); pnt.SetCoords((int)((x - geo.Envelope.XMin) / cellSize), (int)((geo.Envelope.YMax - y) / cellSize)); IRasterProps2 rasterProps2 = (IRasterProps2)raster; object value = rasterProps2.GetPixelValue(0, pnt); //将栅格值添加到要素属性表中 feature.set_Value(feature.Fields.FindField("PixelValue"), value); //更新要素 cursor.UpdateFeature(feature); //获取下一个要素 feature = cursor.NextFeature(); } ``` 在代码中,GetFeatureClass()和GetRasterDataset()是自定义的函数,用于获取要素类和栅格数据集。你需要根据自己的数据来修改这些函数。此外,你还需要将"PixelValue"替换为你要添加的属性字段名称。 希望这个示例代码可以帮助你实现读取栅格图像的像素值并将其添加到要素类的属性表中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值