ArcGIS Engine空間分析之緩衝區分析的實現

  • 2019 年 11 月 5 日
  • 筆記

緩衝分析(BufferAnalysis)的結果是一個面狀要素——即緩衝要素,點狀要素、線狀要素和面狀要素,被緩衝分析功能處理過之後,它們的周圍產生一個緩衝區域,該區域即新產生的面狀要素。

在緩衝方向上,點狀要素和線狀要素只能進行向外緩衝,面狀要素可以雙向緩衝——向外緩衝和向內緩衝

在ArcGIS Engine中,緩衝分析由ITopologicalOperator.Buffer(double Distance)來實現,函數的返回值為IGeometry(表5-12)。其中,輸入的參數為正時向外緩衝,為負時向內緩衝。

 

緩衝分析實現的基本思路為:

1、設置緩衝距離

2、調用ITopologicalOperator.Buffer()方法生成緩衝區

3、向axMapControl中添加緩衝區。

//  // 摘要:  //     Constructs a polygon that is the locus of points at a distance less than or equal  //     to a specified distance from this geometry.  //       構造一個多邊形,該多邊形是距離此幾何體小於或等於指定距離的點的軌跡。  IGeometry Buffer(double distance);

(1)Buffer方法的參數
Bulfer方法僅攜帶了唯一的一個參數:distance,它用以設置緩衝的距離。輸入的數字為正時向外緩衝;為負時向內緩衝(僅面狀對象)。

(2)Buffer功能的基本思路
Buffer方法並沒有產生新的要素類(Feature Class),因為Buffer方法的返回值為lGeometry,僅為要素的幾何形狀,不攜帶任何要素屬性特徵。

所以說,在ArcGIS Engine中,Buffer方法並不能直接產生一個緩衝結果的要素對象。

顯示了觸發Bufer按鈕事件,如圖所示:

 

緩衝區分析函數:BufferArea(double BuffDistance)

/// <summary>  /// 緩衝區分析函數  /// </summary>  /// <param name="BuffDistance">緩衝區距離</param>  private void BufferArea(double BuffDistance)  {      //以主地圖為緩衝區添加對象      IGraphicsContainer graphicsContainer = axMapControl1.Map as IGraphicsContainer;      //刪除之前存留的所有元素      graphicsContainer.DeleteAllElements();      //選中索引值為0的圖層      ILayer layer = axMapControl1.get_Layer(0);      //此循環用於查找圖層名為LayerName的圖層索引      /*      ILayer layer = null;      for (int i = 0; i < axMapControl1.LayerCount; i++)      {          if (axMapControl1.get_Layer(i).Name.Equals("Layer-Name"))          {              layer = axMapControl1.get_Layer(i);              break;          }      }      */      //將圖層名為LayerName的圖層強轉成要素選擇集      IFeatureSelection pFtSel = (IFeatureLayer)layer as IFeatureSelection;      //將圖層名為LayerName的圖層中的所有要素加入選擇集      pFtSel.SelectFeatures(null, esriSelectionResultEnum.esriSelectionResultNew, false);        ICursor pCursor;      //獲得遍歷選擇集中所有要素的游標      pFtSel.SelectionSet.Search(null, false, out pCursor);      IFeatureCursor pFtCursor = pCursor as IFeatureCursor;      IFeature pFt = pFtCursor.NextFeature();      //遍歷所有選擇集中的所有要素, 逐個要素地創建緩衝區      while (pFt != null)      {          //將要素的幾何對象(pFt.Shape)強轉成ITopologicalOperator          //pFt.Shape即為創建緩衝區的操作對象          ITopologicalOperator topologicalOperator = pFt.Shape as ITopologicalOperator;          //注意: BuffDIstance輸入為正時向外緩衝, 為負時向內緩衝          IPolygon polygon = topologicalOperator.Buffer(BuffDistance) as IPolygon;          //實例化要素以裝載緩衝區          IElement element = new PolygonElement();          //將幾何要素賦值為多邊形          element.Geometry = polygon;          //逐個顯示          graphicsContainer.AddElement(element, 0);          //指向下一個          pFt = pFtCursor.NextFeature();      }      //這裡清除選擇集, 以免高亮顯示的要素與緩衝結果相互混淆      pFtSel.Clear();      //刷新axMapControl1      axMapControl1.Refresh();  }  

 

核心緩衝分析函數總結:

 

 

謝謝觀看!本人初學GIS二次開發,如果有不對的地方,請多多包涵!