ArcEngine 测量 docx 下载本文

m_ptColl = new PolylineClass(); }

//记录节点

object obj = Type.Missing;

m_ptColl.AddPoint(pt, ref obj, ref obj);

#endregion

#region 绘制结点

try {

IElement vertexElement = CreateElement(pt); //

g = m_hookHelper.ActiveView as IGraphicsContainer;

//g.AddElement(vertexElement, 0);

//g.MoveElementToGroup(vertexElement, m_VertexElement);

m_VertexElement.AddElement(vertexElement); //刷新

m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, vertexElement, pEnvBounds);

} catch { }

#endregion

try {

if (m_ptColl.PointCount >= 2) {

IPoint fromPt = m_ptColl.get_Point(m_ptColl.PointCount - 2); //倒数第二个点

IPoint toPt = m_ptColl.get_Point(m_ptColl.PointCount - 1); //最后第一个点

ILine line = new LineClass(); line.PutCoords(fromPt, toPt);

#region 绘制轨迹线

try {

object missing = Type.Missing;

ISegmentCollection segColl = new PolylineClass();

segColl.AddSegment(line as ISegment, ref missing, ref missing);

IElement traceElement = CreateElement(segColl as IPolyline);

//

g = m_hookHelper.ActiveView as IGraphicsContainer;

//g.AddElement(traceElement, 0);

//g.MoveElementToGroup(traceElement, m_TraceElement);

m_TraceElement.AddElement(traceElement);

m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, traceElement, pEnvBounds);

} catch { }

#endregion

#region 计算单线的长度,并将结果显示在单线中点偏上上面 try {

double angle = line.Angle;

if ((angle > (Math.PI / 2) && angle < (Math.PI)) || (angle > -Math.PI && angle < -(Math.PI / 2))) // 大于90度小于等于180

angle += Math.PI;

//标注点Y值偏移量

double d_OffsetY = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.FromPoints(9);

//标注点

double d_CenterX = (fromPt.X + toPt.X) / 2; double d_CenterY = (fromPt.Y + toPt.Y) / 2 + d_OffsetY; //向上偏移

IPoint labelPt = new PointClass(); labelPt.PutCoords(d_CenterX, d_CenterY);

ITextElement txtElement = CreateTextElement(l

ine.Length.ToString(\));

IElement labelelement = txtElement as IElement;

labelelement.Geometry = labelPt;

object oElement = (object)labelelement;

//根据角度旋转

TransformByRotate(ref oElement, labelPt, angle);

////添加到GraphicsContainer //g.AddElement(labelelement, 0);

////移到m_LabelElement组中

//g.MoveElementToGroup(labelelement, m_LabelElement);

//添加到组

m_LabelElement.AddElement(labelelement);

//刷新

m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, labelelement, pEnvBounds); } catch { }

#endregion }