ArcEngine 经纬度坐标 画线

来源:互联网 发布:d算法 编辑:程序博客网 时间:2024/05/16 13:43

尊重原创:http://blog.csdn.net/zdb330906531/article/details/40864015


开发背景:项目需要把Android设备上的手绘数据显示到地图上

代码大放送,都是干货啊,关键代码如下:

根据经纬度构建点

/// <summary>/// 获取点/// </summary>/// <param name="x">经度</param>/// <param name="y">纬度</param>/// <returns></returns>private IPoint ConstructPoint(double x, double y){    IPoint pPoint = new PointClass();    pPoint.PutCoords(x, y);    return pPoint;}
颜色转换

/// <summary>/// Android系统提供的几种颜色值转换/// </summary>/// <returns></returns>private static IColor GetColor(int colorValue){    IColor color = ConvertColorToIColor(Color.Transparent);//默认透明    switch (colorValue)    {        case -1://白色            color = ConvertColorToIColor(Color.White);            break;        case -256://黄色            color = ConvertColorToIColor(Color.Yellow);            break;        case -65536://红色            color = ConvertColorToIColor(Color.Red);            break;        case -16777216://黑色            color = ConvertColorToIColor(Color.Black);            break;        case -16776961://蓝色            color = ConvertColorToIColor(Color.Blue);            break;        case -16711681://蓝绿色            color = ConvertColorToIColor(Color.Cyan);            break;        case -12303292://深灰            color = ConvertColorToIColor(Color.DimGray);            break;        case -7829368://灰            color = ConvertColorToIColor(Color.Gray);            break;        case -16711936://绿            color = ConvertColorToIColor(Color.Lime);            break;        case -3355444://亮灰            color = ConvertColorToIColor(Color.Gainsboro);            break;        case -65281://品红            color = ConvertColorToIColor(Color.Magenta);            break;    }    return color;}public static IColor ConvertColorToIColor(Color color){    IColor pColor = new RgbColorClass();    pColor.RGB = color.B * 65536 + color.G * 256 + color.R;    return pColor;}
画线

IElementCollection pElements = new ElementCollectionClass();IGeometry tempGeometry = null;//临时图形,用于图形放大foreach(DataRow dr in dt.Rows){//多线条在这里循环int colorValue = Convert.ToInt32(dr["color"]);//颜色值ISegmentCollection pPath = new PathClass();object o = Type.Missing;IPoint startPoint = null;//起始点foreach (DataRow dr2 in dt2.Rows){if (startPoint == null){startPoint = ConstructPoint(Convert.ToDouble(dr2["经度"]), Convert.ToDouble(dr2["纬度"]));}else{IPoint endPoint = ConstructPoint(Convert.ToDouble(dr2["经度"]), Convert.ToDouble(dr2["纬度"]));//终止点ILine pLine = new LineClass();pLine.FromPoint = startPoint;pLine.ToPoint = endPoint;//pLine.PutCoords(startPoint, endPoint);pPath.AddSegment(pLine as ISegment, ref o, ref o);startPoint = endPoint;}}IGeometryCollection pPolyline = new PolylineClass();pPolyline.AddGeometry(pPath as IGeometry, ref o, ref o);ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass();lineSymbol.Color = GetColor(colorValue);//颜色lineSymbol.Style = esriSimpleLineStyle.esriSLSInsideFrame; //样式lineSymbol.Width = 2;ILineElement pLineElement = new LineElementClass();pLineElement.Symbol = lineSymbol;IElement pElement = pLineElement as IElement;tempGeometry = pElement.Geometry = pPolyline as IGeometry;pGraphicsContainer.AddElement(pElement, 0);}//最后刷新if (tempGeometry != null){MapControl.ActiveView.Extent = tempGeometry.Envelope;MapControl.ActiveView.Refresh();}else{MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);}




0 0