public void LogTracksOutsidePH(CTXFile ctx) { if (ctx.XML != null && ctx.XML.Length == 0) { ctx.XML = Entities.CTXFileViewModel.GetXMLOfCTX(ctx); if (ctx.XML.Length == 0) { return; } } XmlDocument doc = new XmlDocument(); doc.LoadXml(ctx.XML); var tracknodes = doc.SelectNodes("//T"); bool logged = false; foreach (XmlNode node in tracknodes) { var lat = double.Parse(node.SelectSingleNode(".//A[@N='Latitude']").Attributes["V"].Value); var lon = double.Parse(node.SelectSingleNode(".//A[@N='Longitude']").Attributes["V"].Value); if (!logged && (lon < 115 || lon > 127 || lat < 4 || lat > 20)) { logged = true; Logger.Log($"outside: {ctx.UserName} RowID:{ctx.RowID} Start:{ctx.TrackTimeStampStart}"); break; } } }
public void ShowDetails() { CTXFile c = null; if (CTXFileSummary != null) { if (CTXFileSummary.CTXFile.TrackingInterval == null) { c = CTXFileSummary.CTXFile; c.TrackingInterval = Entities.CTXFileViewModel.GetGPSTimerIntervalFromCTX(CTXFileSummary.CTXFile, true); CTXFileSummary = new CTXFileSummaryView(c); } else if (CTXFileSummary.TrackingInterval == null && CTXFileSummary.CTXFile.TrackingInterval != null) { c = CTXFileSummary.CTXFile; CTXFileSummary = new CTXFileSummaryView(c); } PropertyGrid.SelectedObject = CTXFileSummary; txtXML.Text = CTXFileSummary.XML; DataGridWaypoints.AutoGenerateColumns = false; DataGridWaypoints.Columns.Add(new DataGridTextColumn { Header = "Name", Binding = new Binding("Waypoint.Name") }); DataGridWaypoints.Columns.Add(new DataGridTextColumn { Header = "Type", Binding = new Binding("WaypointType") }); DataGridWaypoints.Columns.Add(new DataGridTextColumn { Header = "Time", Binding = new Binding("Waypoint.Time") }); DataGridWaypoints.Columns.Add(new DataGridTextColumn { Header = "Lon", Binding = new Binding("Waypoint.Longitude") }); DataGridWaypoints.Columns.Add(new DataGridTextColumn { Header = "Lat", Binding = new Binding("Waypoint.Latitude") }); DataGridWaypoints.DataContext = Entities.CTXFileViewModel.GearWaypointsFromTrip(CTXFileSummary.Identifier); DataGridTracks.AutoGenerateColumns = false; DataGridTracks.Columns.Add(new DataGridTextColumn { Header = "Name", Binding = new Binding("Waypoint.Name") }); DataGridTracks.Columns.Add(new DataGridTextColumn { Header = "Distance", Binding = new Binding("Distance") }); DataGridTracks.Columns.Add(new DataGridTextColumn { Header = "Speed", Binding = new Binding("Speed") }); DataGridTracks.Columns.Add(new DataGridTextColumn { Header = "Time", Binding = new Binding("Waypoint.Time") }); DataGridTracks.Columns.Add(new DataGridTextColumn { Header = "Lon", Binding = new Binding("Waypoint.Longitude") }); DataGridTracks.Columns.Add(new DataGridTextColumn { Header = "Lat", Binding = new Binding("Waypoint.Latitude") }); DataGridTracks.DataContext = Entities.CTXFileViewModel.TrackWaypointsFromTrip(CTXFileSummary.Identifier); buttonScanXML.IsEnabled = txtXML.Text.Length == 0; } }
private List <ExtractedFishingTrack> CreateFromSource(CTXFile ctx = null, DeviceGPX gpx = null, bool save = false) { FishingTripAndGearRetrievalTracks result = null; List <ExtractedFishingTrack> listOfExtractedTracks = new List <ExtractedFishingTrack>(); if (ctx == null && gpx == null) { throw new ArgumentNullException("Error: Source is not specified"); } ExtractedTrackSourceType sourceType = ExtractedTrackSourceType.TrackSourceTypeNone; var deviceName = ""; int id = 0; if (ctx != null) { sourceType = ExtractedTrackSourceType.TrackSourceTypeCTX; id = ctx.RowID; deviceName = Entities.CTXFileViewModel.GetFile(id, false).UserName; } else if (gpx != null) { sourceType = ExtractedTrackSourceType.TrackSourceTypeGPX; id = gpx.RowID; deviceName = Entities.DeviceGPXViewModel.GetDeviceGPX(id).GPS.DeviceName; } bool proccedSavetrack = false; bool proceedExtractNewTracks = false; var extractedTracks = Entities.ExtractedFishingTrackViewModel.GetTracks(sourceType, id); if (extractedTracks != null) { if (extractedTracks.Count > 0) { result = new FishingTripAndGearRetrievalTracks { TripShapefile = null }; foreach (var item in extractedTracks) { item.FromDatabase = true; var shp = new Shape(); if (shp.Create(ShpfileType.SHP_POLYLINE)) { shp.CreateFromString(item.SerializedTrack); item.SegmentSimplified = shp; item.TrackOriginal = null; DetectedTrack dt = new DetectedTrack { Shape = shp, ExtractedFishingTrack = item, Length = item.LengthOriginal, Accept = true }; if (result.GearRetrievalTracks == null) { result.GearRetrievalTracks = new List <DetectedTrack>(); } //if (MapWindowManager.BSCBoundaryShapefile == null || !shp.Crosses(MapWindowManager.BSCBoundaryShapefile.Shape[0])) //{ result.GearRetrievalTracks.Add(dt); //} } } proccedSavetrack = result.GearRetrievalTracks != null; } else { proceedExtractNewTracks = true; } } else { proceedExtractNewTracks = true; } if (proceedExtractNewTracks) { if (ctx != null && !ctx.TrackExtracted) { if (ctx.XML != null && ctx.XML.Length == 0) { ctx.XML = Entities.CTXFileViewModel.GetXMLOfCTX(ctx); if (ctx.XML.Length == 0) { return(null); } } XmlDocument doc = new XmlDocument(); doc.LoadXml(ctx.XML); var tracknodes = doc.SelectNodes("//T"); if (ctx.TrackingInterval == null) { ctx.TrackingInterval = Entities.CTXFileViewModel.GetGPSTimerIntervalFromCTX(ctx, true); } result = ShapefileFactory.GearRetrievalTrackShapeFromCTX(tracknodes, ctx.TrackingInterval); //procced = result != null && result.GearRetrievalTracks.Where(T => T.Accept).ToList().Count > 0; } else if (gpx != null) { var gpxFile = Entities.GPXFileViewModel.ConvertToGPXFile(gpx); if (gpxFile.GPSTimerInterval == null) { gpxFile.GPSTimerInterval = Entities.DeviceGPXViewModel.GetDeviceGPX(id).TimerInterval; } result = ShapefileFactory.GearRetrievalTrackShapeFromGPX(gpxFile, gpxFile.GPSTimerInterval); //procced = result != null && result.GearRetrievalTracks.Where(T => T.Accept).ToList().Count > 0; } proccedSavetrack = result != null && result.GearRetrievalTracks.Where(T => T.Accept).ToList().Count > 0; } if (proccedSavetrack) { foreach (var item in result.GearRetrievalTracks.Where(t => t.Accept)) { ExtractedFishingTrack extractedTrack = new ExtractedFishingTrack { DateAdded = DateTime.Now, TrackSourceType = sourceType, TrackSourceID = id, Start = item.ExtractedFishingTrack.Start, End = item.ExtractedFishingTrack.End, LengthOriginal = item.ExtractedFishingTrack.LengthOriginal, LengthSimplified = item.ExtractedFishingTrack.LengthSimplified, TrackPointCountOriginal = item.ExtractedFishingTrack.TrackPointCountOriginal, TrackPointCountSimplified = item.ExtractedFishingTrack.TrackPointCountSimplified, AverageSpeed = item.ExtractedFishingTrack.AverageSpeed, TrackOriginal = item.ExtractedFishingTrack.TrackOriginal, SegmentSimplified = item.ExtractedFishingTrack.SegmentSimplified, SerializedTrack = item.ExtractedFishingTrack.SegmentSimplified.SerializeToString(), DeviceName = deviceName, FromDatabase = item.ExtractedFishingTrack.FromDatabase, SerializedTrackUTM = item.ExtractedFishingTrack.SerializedTrackUTM, CombinedTrack = item.ExtractedFishingTrack.CombinedTrack }; if (extractedTrack.TrackSourceType == ExtractedTrackSourceType.TrackSourceTypeCTX) { var ctxFile = Entities.CTXFileViewModel.GetFile(extractedTrack.TrackSourceID); extractedTrack.Gear = ctxFile.Gear; extractedTrack.LandingSite = ctxFile.LandingSite; } if (!save) { extractedTrack.ID = ++_idCounter; } listOfExtractedTracks.Add(extractedTrack); } } if (sourceType == ExtractedTrackSourceType.TrackSourceTypeCTX && !ctx.TrackExtracted) { ctx.TrackExtracted = true; Entities.CTXFileViewModel.UpdateRecordInRepo(ctx); } else if (sourceType == ExtractedTrackSourceType.TrackSourceTypeGPX && !gpx.TrackIsExtracted) { gpx.TrackIsExtracted = true; Entities.DeviceGPXViewModel.UpdateRecordInRepo(gpx, true); } return(listOfExtractedTracks); }