• ArcGIS Engine+C#缓冲区分析文档及完整源码


    1 概述

    缓冲区分析(Buffer)是对选中的一组或一类地图要素(点、线或面)按设定的距离条件,围绕其要素而形成一定缓冲区多边形实体,从而实现数据在二维空间得以扩展的信息分析方法。缓冲区应用的实例有如:污染源对其周围的污染量随距离而减小,确定污染的区域;为失火建筑找到距其500米范围内所有的消防水管等。

    2 缓冲区的基础

    缓冲区是地理空间,目标的一种影响范围或服务范围在尺度上的表现。它是一种因变量,由所研究的要素的形态而发生改变。从数学的角度来看,缓冲区是给定空间对象或集合后获得的它们的领域,而邻域的大小由邻域的半径或缓冲区建立条件来决定,因此对于一个给定的对象A,它的缓冲区可以定义为:

    P={x | d(x , A)<=r}

    (d一般是指欧式距离,也可以是其它的距离,其中r为邻域半径或缓冲区建立的条件)

    缓冲区建立的形态多种多样,这是根据缓冲区建立的条件来确定的,常用的对于点状要素有圆形,也有三角形、矩形和环形等;对于线状要素有双侧对称、双侧不对称或单侧缓冲区;对于面状要素有内侧和外侧缓冲区,虽然这些形体各异,但是可以适合不同的应用要求,建立的原理都是一样的。点状要素,线状要素和面状要素的缓冲区示意图如下。


    3 定制工具的使用

    1 打开工程GPBufferLayer\CSharp\GpBufferLayer.sln

    2 在VS2005内选择重新生成解决方案

    3 开发需要添加工具的工程

    4 在ToolBarControl上点右键,选择属性

    5 选择条目,点击添加



    6 在命令类中选择“自定义工具集”,选择“缓冲区分析”,可通过双击或者拖放到工具条上。

    7 运行程序

    8 使用“选择要素”命令,选择需要建立缓冲区的要素(点或线)

    9 点击工具条上的“缓冲区分析按钮”,弹出缓冲区分析对话框


                       选择要素




    选择缓冲区分析按钮


    10 选择缓存分析的图层,选择距离及单位,设置输出的图层

    11 点击分析按钮,当出现“分析完成”字样时,工作完成



    12 这时通过附加新的图层,即可看到结果





    4 核心源代码分析

    4.1 BufferSelectedLayerCmd.cs

         主要完成定制command的相关代码,具体原理可参见《ArcGIS Engine中文开发指南》

    4.2 BufferDlg.cs

    为缓冲区分析的输入对话框。其中最主要的是“分析”按钮的处理事件。源代码及分析如下:

          double bufferDistance;

         //转换distance为double类型

          double.TryParse(txtBufferDistance.Text, out bufferDistance);

          if (0.0 == bufferDistance)

          {

            MessageBox.Show("Bad buffer distance!");

            return;

          }

          //判断输出路径是否合法

          if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(txtOutputPath.Text)) ||

            ".shp" != System.IO.Path.GetExtension(txtOutputPath.Text))

          {

            MessageBox.Show("Bad output filename!");

            return;

          }

          //判断图层个数

          if (m_hookHelper.FocusMap.LayerCount == 0)

            return;

          //get the layer from the map

          IFeatureLayer layer = GetFeatureLayer((string)cboLayers.SelectedItem);

          if (null == layer)

          {

            txtMessages.Text += "Layer " + (string)cboLayers.SelectedItem + "cannot be found!\r\n";

            return;

          }

          //scroll the textbox to the bottom

          ScrollToBottom();

          txtMessages.Text += "\r\n分析开始,这可能需要几分钟时间,请稍候..\r\n";

          txtMessages.Update();

          //get an instance of the geoprocessor

          Geoprocessor gp = new Geoprocessor();

          gp.OverwriteOutput = true;

            //create a new instance of a buffer tool

          ESRI.ArcGIS.AnalysisTools.Buffer buffer = new ESRI.ArcGIS.AnalysisTools.Buffer(layer, txtOutputPath.Text, Convert.ToString(bufferDistance) + " " + (string)cboUnits.SelectedItem);

          buffer.dissolve_option = "ALL";//这个要设成ALL,否则相交部分不会融合

          //buffer.line_side = "FULL";//默认是"FULL",最好不要改否则出错

          //buffer.line_end_type = "ROUND";//默认是"ROUND",最好不要改否则出错

         

          //execute the buffer tool (very easy :-))

          IGeoProcessorResult results=null;

         

          try

          {

              results = (IGeoProcessorResult)gp.Execute(buffer, null);

          }

          catch (Exception ex)

          {

              txtMessages.Text += "Failed to buffer layer: " + layer.Name + "\r\n";

          }

          if (results.Status != esriJobStatus.esriJobSucceeded)

          {

            txtMessages.Text += "Failed to buffer layer: " + layer.Name + "\r\n";

          }

         

           //scroll the textbox to the bottom

          ScrollToBottom();

          txtMessages.Text += "\r\n分析完成.\r\n";

          txtMessages.Text += "-----------------------------------------------------------------------------------------\r\n";

          //scroll the textbox to the bottom

          ScrollToBottom();

    5 工程代码下载


    GPBufferLayer源码下载


     


     


     


     

  • 相关阅读:
    no-useless-call (Rules) – Eslint 中文开发手册
    Java 8 Stream
    CSS3 ,checked 选择器
    MySQL 数据类型
    _Alignas (C keywords) – C 中文开发手册
    C 库函数 – modf()
    JavaScript E 属性
    SyntaxError.prototype (Errors) – JavaScript 中文开发手册
    swagger和openAPI: 上传文件
    Java中HashMap的putAll()方法: HashMap.putAll()
  • 原文地址:https://www.cnblogs.com/ericgisser/p/gis_cacheanalysis.html
Copyright © 2020-2023  润新知