zoukankan      html  css  js  c++  java
  • 距离测量

    实现在IMapcontrol上采点,双击结束采点进行距离测量,并标注在IMapcontrol上,实现结果如下:

    1. 初始化主要变量:

    1         private bool m_bStart = false;
    2         private INewLineFeedback m_pNewLineFeedback = null;
    3         private IPoint m_prevPoint = null;
    4         private double m_CurDistance = 0.0;
    5         private double m_TotalDistance = 0.0;

    2.MouseDown事件:

     1 IPoint pt = m_pMapControl.ToMapPoint(X, Y);
     2 
     3             if (m_bStart && m_pNewLineFeedback != null)
     4             {
     5                 m_pNewLineFeedback.AddPoint(pt);
     6                               if (m_prevPoint != null)
     7                 {
     8                     m_CurDistance = ReturnDistance(m_prevPoint, pt);
     9                     m_TotalDistance += m_CurDistance;
    10                     m_prevPoint = pt;
    11                 }
    12             }
    13             else
    14             {
    15                 m_pNewLineFeedback.Display = m_pMapControl.ActiveView.ScreenDisplay;
    16                 m_bStart = true;
    17                 m_pNewLineFeedback.Start(pt);
    18                 m_prevPoint = pt;
    19              }
    View Code

    3.MouseDoubleClick事件:

     1 try
     2             {
     3                 IPolyline pline = m_pNewLineFeedback.Stop();
     4                 IGraphicsContainer pGraphicsContainer = m_pMapControl.ActiveView as IGraphicsContainer;
     5                 
     6                 DrawElement(pline, pGraphicsContainer);
     7             }
     8             catch (Exception ex)
     9             {
    10                 System.Windows.Forms.MessageBox.Show(ex.ToString(), "提示");
    11 
    12             }
    13             m_TotalDistance = 0;
    14             m_bStart = false;
    View Code

    4.在Mapcontrol上添加标注:

    添加所画线的标注:

    1             IRgbColor pColor = new RgbColorClass();
     2             ILineElement pLineElement = new LineElementClass();
     3             IElement pElement = pLineElement as IElement;
     4             pElement.Geometry = pLine as IGeometry;
     5 
     6             ISimpleLineSymbol pSmplLine = new SimpleLineSymbolClass();
     7             pColor = new RgbColorClass();
     8             pColor.Red = 0; pColor.Blue = 250; pColor.Green = 0;
     9             pSmplLine.Color = pColor as IColor;
    10             pSmplLine.Style = esriSimpleLineStyle.esriSLSSolid;
    11             pSmplLine.Width = 1;
    12             pLineElement.Symbol = pSmplLine as ILineSymbol;
    13 
    14             pGraphicsContainer.AddElement(pElement, 0);
    View Code

    添加文字标注:

     1            ITextElement pTextElement = new TextElementClass();
     2             pElement = pTextElement as IElement;
     3             pElement.Geometry = pLine as IGeometry;
     4             ISimpleTextSymbol pSimpleTextSymbol = new TextSymbolClass();
     5             
     6             pColor.Red = 255; pColor.Green = 0; pColor.Blue = 0;
     7             pSimpleTextSymbol.Color = pColor as IColor;
     8             stdole.IFont font = new stdole.StdFontClass();
     9             font.Name = "宋体";
    10             font.Bold = false;
    11             font.Size = 18;
    12             pSimpleTextSymbol.Font = font as IFontDisp;
    13 
    14             pTextElement.Symbol = (ITextSymbol)pSimpleTextSymbol;
    15             pTextElement.ScaleText = false;
    16             pTextElement.Text = "距离:" + pLine.Length.ToString("0.00") + "";          
    17             pGraphicsContainer.AddElement(pElement, 0);       
    View Code

    刷新显示:

    1 m_pMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
    View Code

    另:返回两个IGeometry之间的距离:

    1 private double ReturnDistance(IPoint point1, IPoint point2)
    2         {
    3             IProximityOperator pPO = point1 as IProximityOperator;
    4             double dis = pPO.ReturnDistance(point2);
    5             return dis;           
    6         }
    View Code
  • 相关阅读:
    向量场中的积分
    Oracle 动态视图4 V$SESSION_WAIT & V$SESSION_EVENT
    Oracle 动态视图3 V$SESSION
    Oracle 动态视图2 V$LOCKED_OBJECT
    Oracle 摘去数据块的面纱
    Oracle 动态视图1 V$LOCK
    Oracle Lock 概述
    Oracle 监听动态注册与静态注册
    Oracle用户进程跟踪
    Oracle SGA参数调整
  • 原文地址:https://www.cnblogs.com/fatherZyl/p/3285277.html
Copyright © 2011-2022 走看看