Ejemplo n.º 1
0
        public List <ExtractedFishingTrack> GetTracks(ExtractedTrackSourceType sourceType, int sourceID)
        {
            var list = ExtractedFishingTrackCollection
                       .Where(t => t.TrackSourceType == sourceType && t.TrackSourceID == sourceID).ToList();

            return(ExtractedFishingTrackCollection
                   .Where(t => t.TrackSourceType == sourceType && t.TrackSourceID == sourceID).ToList());
        }
Ejemplo n.º 2
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);
        }