现在的位置: 首页 > 综合 > 正文

GPS之解决

2013年10月15日 ⁄ 综合 ⁄ 共 5536字 ⁄ 字号 评论关闭

public class Gps_Operation
    {

        public Catalog cat;
        public MapControlModel model;
        public MapInfo.Mapping.Map map;
        public MapInfo.Data.Table GPSCAR ;                       //小车表
        public MapInfo.Data.Table ORBIT;                           //轨迹表
        public string _findLayerName ;                                  //层名
        public string _findColumnName ;                              //列名
        public string MapAlias;                                              //地图别名
        public string[] STRX, STRY;                                      //STRX,STRY为存有经纬度值的字符串数组
       

        public Gps_Operation()
        {

        cat = MapInfo.Engine.Session.Current.Catalog;

        GPSCAR = cat.GetTable("Animation");

        ORBIT = cat.GetTable("Tm");

        _findLayerName = "Animation";

        _findColumnName = "GPSid";                  

        model = MapControlModel.GetModelFromSession();
     
        map = model.GetMapObj("Map1");

        MapAlias = "Map1";
   
        }

        public void real_time_information(string GPS_ID,double x,double y)                      //GPS实时信息更新
        {

            GPSCAR.BeginAccess(MapInfo.Data.TableAccessMode.Write);

            SearchInfo si = MapInfo.Data.SearchInfoFactory.SearchWhere(_findColumnName + "='" + GPS_ID + "'");

            MapInfo.Engine.Session.Current.Selections.DefaultSelection.Clear();

            IResultSetFeatureCollection ifs = MapInfo.Engine.Session.Current.Catalog.Search(_findLayerName, si);

            foreach (Feature fcar in ifs)
            {

                double x_old = fcar.Geometry.Centroid.x;                                          //先前坐标

                double y_old = fcar.Geometry.Centroid.y;

                fcar.Geometry.GetGeometryEditor().OffsetByXY(x - x_old, y - y_old, MapInfo.Geometry.DistanceUnit.Degree, MapInfo.Geometry.DistanceType.Spherical);

                fcar.Geometry.EditingComplete();                                                  //更新位置,相对位移

                fcar.Update();

            }

            GPSCAR.EndAccess();
       
        }

        public void insert_orbit_feature(double x, double y, double x_sub, double y_sub)         //连接前后两个坐标,添加线形图元
        {

            MapInfo.Geometry.DPoint[] dPt = new DPoint[2];                                       //创建一个点数组
            dPt[0].x = x;
            dPt[0].y = y;
            dPt[1].x = x - x_sub;
            dPt[1].y = y - y_sub;
            MultiCurve _lineFeatureCurve = new MultiCurve(map.GetDisplayCoordSys());
            _lineFeatureCurve = MultiCurve.CreateLine(map.GetDisplayCoordSys(), dPt[1], dPt[0]); //取两点画线
            MapInfo.Styles.SimpleLineStyle slsLine = new MapInfo.Styles.SimpleLineStyle(new LineWidth(3, LineWidthUnit.Pixel), 59, Color.Red);
            MapInfo.Styles.CompositeStyle lineStyle = new MapInfo.Styles.CompositeStyle(slsLine);
                                                                                                  //创建一个红色箭头的线形图元
            Feature Lftr = new Feature(_lineFeatureCurve, lineStyle);                             //创建图元
            ORBIT.InsertFeature(Lftr);                                                             //将图元加入临时表中

        }

        public void gps_locate(string GPS_ID)                                                     //定位
        {

            SearchInfo si;

            si = MapInfo.Data.SearchInfoFactory.SearchWhere(_findColumnName + "='" + GPS_ID + "'"); //对应图元

            IResultSetFeatureCollection ifs = MapInfo.Engine.Session.Current.Catalog.Search(_findLayerName, si);

            MapInfo.Engine.Session.Current.Selections.DefaultSelection.Clear();

            if (ifs.Count>0)
       
                if (ifs.Count == 1)
                {
                    map.Center = new DPoint(ifs[0].Geometry.Centroid.x, ifs[0].Geometry.Centroid.y); //定位到小车道地图中间位置

                    MapInfo.Geometry.Distance d = new MapInfo.Geometry.Distance(0.9, map.Zoom.Unit);

                    map.Zoom = d;

                }
                else
                {

                    map.SetView(ifs.Envelope);

                }

        }

 

       public void history_orbit(string GPS_ID)                                                        //构造行车轨迹
      {

          for (int i = 1; i < STRX.Length - 1; i++)

              if (GPSCAR != null)
              {
                                                                                                        //更新点的位置
                  GPSCAR.BeginAccess(MapInfo.Data.TableAccessMode.Write);

                  SearchInfo si = MapInfo.Data.SearchInfoFactory.SearchWhere(_findColumnName + "='" + GPS_ID + "'");

                  MapInfo.Engine.Session.Current.Selections.DefaultSelection.Clear();

                  IResultSetFeatureCollection ifs = MapInfo.Engine.Session.Current.Catalog.Search(_findLayerName, si);

                  double x = Convert.ToDouble(STRX[i]);

                  double y = Convert.ToDouble(STRY[i]);

                  foreach (Feature fcar in ifs)
                  {

                      double x_old = fcar.Geometry.Centroid.x;                                            //先前坐标

                      double y_old = fcar.Geometry.Centroid.y;

                      fcar.Geometry.GetGeometryEditor().OffsetByXY(x - x_old, y - y_old, MapInfo.Geometry.DistanceUnit.Degree, MapInfo.Geometry.DistanceType.Spherical);

                      fcar.Geometry.EditingComplete();                                                     //更新位置,相对位移

                      fcar.Update();

                      gps_locate(GPS_ID);                                                                 //定位

                      double subx = x - x_old;

                      double suby = y - y_old;

                      insert_orbit_feature(fcar.Geometry.Centroid.x, fcar.Geometry.Centroid.y, subx, suby);//连接前后两个坐标,以便构造轨迹

                  }

                  GPSCAR.EndAccess();

              }
       
      }

    }

抱歉!评论已关闭.