ArcGIS Engine空间分析之缓冲区分析的实现

缓冲分析(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二次开发,如果有不对的地方,请多多包涵!

 

posted @ 2019-11-05 11:43  the_path_of_grace  阅读(3964)  评论(2编辑  收藏  举报