AE中GPS信号解析

if (serialPort1.IsOpen)
            {
                #region 新建坐标系
                Type factoryType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
                System.Object obj = Activator.CreateInstance(factoryType);
                ISpatialReferenceFactory3 spatialReferenceFactory = obj as ISpatialReferenceFactory3;
                ///新建坐标系GCS WGS-84
                //D:\Program Files (x86)\ArcGIS\Desktop10.0\Coordinate Systems\Geographic Coordinate Systems\World
                ISpatialReference spatialReference = spatialReferenceFactory.
                    CreateESRISpatialReferenceFromPRJFile(@"D:\Program Files (x86)\ArcGIS\Desktop10.0\Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984.prj");
                ///新建坐标系
                //F:\yy\内蒙\city_bound\NM_city.prj
                ISpatialReference dspatialReference = spatialReferenceFactory.
                    CreateESRISpatialReferenceFromPRJFile(@"F:\yy\内蒙\city_bound\NM_city.prj");
                #endregion              

                #region  公共参数
                string str = serialPort1.ReadLine() + "\r\n";
                string[] strarray = str.Split(',');
                if (strarray[0].Equals("$GPGGA"))
                {
                    if (strarray[2]!="")
                    {
                        string jingdu, weidu, gaocheng;
                        jingdu = strarray[4].Substring(0, 3) + (double.Parse(strarray[4].Substring(3)) / 60).ToString("###.####");
                        weidu = strarray[2].Substring(0, 2) + (double.Parse(strarray[2].Substring(2)) / 60).ToString("##.####");
                        gaocheng = strarray[9] + strarray[10].ToLower();
                        starttrack = true;
                #endregion

                        #region 进行坐标转换
                        IPoint point = new PointClass();
                        point.PutCoords(double.Parse(jingdu), double.Parse(weidu));
                        //Geometry Interface to do actual project
                        IGeometry geometry;
                        geometry = point;
                        geometry.SpatialReference = spatialReference;
                        geometry.Project(dspatialReference);
                        point = geometry as IPoint;
                        double x;
                        double y;
                        point.QueryCoords(out x, out y);
                        #endregion

                        #region 在地图上显示GPS点
                        ESRI.ArcGIS.Display.ISimpleMarkerSymbol simpleMarkerSymbol = new ESRI.ArcGIS.Display.SimpleMarkerSymbolClass();
                        simpleMarkerSymbol.Color = GetRGBColor(0, 0, 255);
                        simpleMarkerSymbol.Size = 10;
                        // ESRI.ArcGIS.Display.ISymbol symbol = simpleMarkerSymbol as  ESRI.ArcGIS.Display.ISymbol; // Dynamic cast.     
                         gpspoint.PutCoords(x, y);
                         object opoint = simpleMarkerSymbol;
                         axMapControl1.DrawShape(gpspoint, ref opoint);
                        #endregion

                        #region 跟踪轨迹
                        point.X = x;
                        point.Y = y;
                        //If this is the first point of a new line
                        if (m_Polyline == null)
                        {
                            //Create the forms private polyline member and grab hold of the IPolyline interface
                            m_Polyline = new PolylineClass();
                        }
                        //QI for the IPointsCollection interface using the IPolyline interface
                        object o = Type.Missing;
                        //object o1 = m_PointCollection.PointCount-1;
                        m_PointCollection = (IPointCollection)m_Polyline;
                        m_PointCollection.AddPoint(point, ref o, ref o);
                        //Refresh the foreground thereby removing any text annotation
                        axMapControl1.Refresh(esriViewDrawPhase.esriViewForeground, Type.Missing, Type.Missing);
                        #endregion

                        #region 输出到txt
                        if (Singlepoint == true)
                        {
                            timer1.Enabled = false;
                            textBox2.Text = textBox2.Text + "Longitude," + jingdu + ",Latitude," + weidu + ",Elevation," + gaocheng + "\r\n";
                            MessageBox.Show("Longitude," + jingdu + ",Latitude," + weidu + ",Elevation," + gaocheng);
                            Singlepoint = false;
                        }
                        else
                        {
                            textBox2.Text = textBox2.Text + "Longitude," + jingdu + ",Latitude," + weidu + ",Elevation," + gaocheng + "\r\n";
                        }
                        #endregion
                    }
                    else
                    {
                        timer1.Enabled = false;
                        MessageBox.Show("未接收到GPS信号!");                        
                    }
                }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值