[轉] AE中如何由IFeature 如何獲取所對應的FeatureClass


轉載的原文 AE中如何由IFeature 如何獲取所對應的FeatureClass

 
先獲取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);
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM