public static Track ConvertToTrack(string gpxString) { gpx.gpxType gpx = null; try { var xmlSerialize = new System.Xml.Serialization.XmlSerializer(typeof(gpx.gpxType)); var stream = new System.IO.StringReader(gpxString); gpx = (gpx.gpxType)xmlSerialize.Deserialize(stream); } catch(Exception ex) { ExceptionProcess.ProcessWithNotify(ex); return null; } Track track = new Track(); track.TrackPoints = new List<TrackPoint>(); track.StartTime = gpx.metadata.timeSpecified ? (DateTime?)gpx.metadata.time : null; track.TrackPoints = new List<TrackPoint>(); foreach (var i in gpx.trk) { foreach (var j in i.trkseg) { foreach (var k in j.trkpt) { var p = new TrackPoint(); p.Altitude = k.eleSpecified ? (double)k.ele : 0; p.Latitude = (double)k.lat; p.Longitude = (double)k.lon; p.GpsTime = k.timeSpecified ? k.time : DateTime.MinValue; p.MessageTime = p.GpsTime; p.VehicleName = gpx.creator; p.Track = track; track.TrackPoints.Add(p); } } } return track; }
public static string ConvertToGpx(Track track) { gpx.gpxType gpx = new gpx.gpxType(); gpx.creator = track.VehicleName; gpx.metadata = new global::gpx.metadataType(); gpx.metadata.time = track.StartTime.HasValue ? DateTime.MinValue : track.StartTime.Value; gpx.metadata.timeSpecified = track.StartTime.HasValue; using (var rep = ServiceProvider.GetService<IRepositoryFactory>().GenerateRepository<TrackPoint>()) { rep.Attach(track); gpx.trk = new gpx.trkType[1]; gpx.trk[0] = new global::gpx.trkType(); gpx.trk[0].number = "1"; gpx.trk[0].trkseg = new gpx.trksegType[1]; gpx.trk[0].trkseg[0] = new global::gpx.trksegType(); gpx.trk[0].trkseg[0].trkpt = new gpx.wptType[track.TrackPoints.Count]; for(int i=0; i<track.TrackPoints.Count; ++i) { gpx.trk[0].trkseg[0].trkpt[i] = new global::gpx.wptType(); gpx.trk[0].trkseg[0].trkpt[i].ele = (decimal)track.TrackPoints[i].Altitude; gpx.trk[0].trkseg[0].trkpt[i].eleSpecified = true; gpx.trk[0].trkseg[0].trkpt[i].lat = (decimal)track.TrackPoints[i].Latitude; gpx.trk[0].trkseg[0].trkpt[i].lon = (decimal)track.TrackPoints[i].Longitude; gpx.trk[0].trkseg[0].trkpt[i].time = track.TrackPoints[i].GpsTime; gpx.trk[0].trkseg[0].trkpt[i].timeSpecified = true; gpx.trk[0].trkseg[0].trkpt[i].magvar = (decimal)track.TrackPoints[i].Heading; gpx.trk[0].trkseg[0].trkpt[i].magvarSpecified = true; } } var xmlSerialize = new System.Xml.Serialization.XmlSerializer(typeof(gpx.gpxType)); var stream = new System.IO.StringWriter(); xmlSerialize.Serialize(stream, gpx); stream.Close(); return stream.ToString(); }
private static Track NewTrack(string gpsId) { //Zkzx.Model.车辆 cl = rep.Get<Zkzx.Model.车辆>(Guid.Parse("888b4dba-c454-42a0-9bbe-9e7500c65101")); //Zkzx.Model.车辆作业 clzy = new Zkzx.Model.车辆作业(); //clzy.车辆 = cl; //clzy.专家任务 = rep.Get<Zkzx.Model.专家任务>(Guid.Parse("00000000-0000-0000-0000-000000000001")); //clzy.作业号 = s_dao.生成作业号(); Track track = new Track(); track.Name = "Default"; track.VehicleName = gpsId; track.IsActive = true; return track; }
public string SendTrackData(string gpsId, string gpxData) { try { Feng.Track track = new Feng.Track(); track.Name = "Gpx"; track.VehicleName = gpsId; track.IsActive = true; track.Gpx = gpxData; track.StartTime = System.DateTime.Now; track.EndTime = System.DateTime.Now; s_trackDao.Save(track); } catch (Exception) { return string.Empty; } return string.Empty; }