• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
bobird的学习笔记
博客园    首页    新随笔    联系   管理    订阅  订阅

AE中解析GPS信号

if (serialPort1.IsOpen)
            {
                #region 新建坐标系
                Type factoryType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
                System.Object bj = 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 point = 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信号!");                        
                    }
                }

 

posted on 2013-06-27 09:23  bobird  阅读(310)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3