public static int MapWaypointList(List <WaypointLocalTime> wpts, out List <int> handles)
 {
     handles = new List <int>();
     if (wpts.Count > 0)
     {
         var sf = ShapefileFactory.PointsFromWaypointList(wpts, out handles);
         MapLayersHandler.AddLayer(sf, "GPX waypoints", uniqueLayer: true, layerKey: sf.Key, rejectIfExisting: true);
     }
     return(MapLayersHandler.CurrentMapLayer.Handle);
 }
Example #2
0
 public static int MapTrackGPX(GPXFile gpxfile, out List <int> handles)
 {
     handles = new List <int>();
     if (gpxfile.Tracks.Count > 0)
     {
         var sf = ShapefileFactory.TrackFromGPX(gpxfile, out handles);
         MapLayersHandler.AddLayer(sf, "GPX track", uniqueLayer: true, layerKey: sf.Key, rejectIfExisting: true);
     }
     return(MapLayersHandler.CurrentMapLayer.Handle);
 }
        public static int MapGPX(GPXFile gpxFile, out int shpIndex, out List <int> handles, bool showInMap = true)
        {
            shpIndex = -1;
            handles  = new List <int>();
            var utils       = new MapWinGIS.Utils();
            var shpfileName = "";

            if (showInMap)
            {
                if (gpxFile != null)
                {
                    Shapefile sf = null;
                    if (gpxFile.TrackCount > 0)
                    {
                        //sf = ShapefileFactory.TrackFromGPX(gpxFile,out shpIndex);
                        sf = ShapefileFactory.TracksFromGPXFiles(gpxFile, out handles);
                        //var result = ShapefileFactory.CreateTripAndHaulsFromGPX(gpxFile);
                        //sf = result.Shapefile;
                        //handles.Add(result.Handle);
                        //Console.WriteLine($"shapefile with {sf.Shape[0].numPoints} created. Handle is {result.Handle}");
                        shpfileName = "GPX tracks";
                    }
                    else if (gpxFile.WaypointCount > 0)
                    {
                        sf          = ShapefileFactory.NamedPointsFromGPX(gpxFile, out handles);
                        shpfileName = "GPX waypoints";
                    }
                    //MapWindowForm.Title =$"Number of layers:{MapControl.NumLayers}";
                    MapLayersHandler.AddLayer(sf, shpfileName, uniqueLayer: true, layerKey: sf.Key, rejectIfExisting: true);

                    if (gpxFile.TrackCount > 0)
                    {
                        GPXTracksLayer = MapLayersHandler.CurrentMapLayer;
                    }
                    else if (gpxFile.WaypointCount > 0)
                    {
                        GPXWaypointsLayer = MapLayersHandler.CurrentMapLayer;
                    }

                    return(MapLayersHandler.CurrentMapLayer.Handle);
                }
                else
                {
                    return(-1);
                }
            }
            else
            {
                var ly = MapLayersHandler.get_MapLayer(gpxFile.FileName);
                MapLayersHandler.RemoveLayer(ly.Handle);
                return(-1);
            }
        }
Example #4
0
        public static bool MapTrip(List <Trip> trips)
        {
            var trackHandles = new List <int>();
            var pointHandles = new List <int>();
            var sf           = ShapefileFactory.TrackFromTrip(trips, out trackHandles);
            var pointSF      = ShapefileFactory.PointsFromTrips(trips, out pointHandles);

            MapInteractionHandler.MapLayersHandler.AddLayer(sf, "Track", uniqueLayer: true, layerKey: sf.Key);
            MapInteractionHandler.MapLayersHandler.AddLayer(pointSF, "Waypoints", uniqueLayer: true, layerKey: sf.Key);
            TrackShapefile     = sf;
            WaypointsShapefile = pointSF;
            return(sf != null);
        }
 public static FishingTripAndGearRetrievalTracks MapTrackGPX(GPXFile gpxfile)
 {
     if (gpxfile.Tracks.Count > 0)
     {
         var result = ShapefileFactory.CreateTripAndHaulsFromGPX(gpxfile);
         if (result != null)
         {
             MapLayersHandler.AddLayer(result.TripShapefile, "GPX track", uniqueLayer: true, layerKey: result.TripShapefile.Key, rejectIfExisting: true);
         }
         return(result);
     }
     return(null);
 }
 public static FishingTripAndGearRetrievalTracks MapTrackCTX(CTXFileSummaryView ctx)
 {
     if (ctx.TrackpointsCount != null && ctx.TrackpointsCount > 0)
     {
         var result = ShapefileFactory.CreateTripAndHaulsFromCTX(ctx);
         if (result != null)
         {
             MapLayersHandler.AddLayer(result.TripShapefile, "CTX track", uniqueLayer: true, layerKey: result.TripShapefile.Key, rejectIfExisting: true);
         }
         return(result);
     }
     return(null);
 }
 public static int MapExtractedFishingTrack(FishingTripAndGearRetrievalTracks th, out List <int> handles)
 {
     handles = new List <int>();
     if (th != null && th.GearRetrievalTracks.Count > 0 && ShapefileFactory.ExtractFishingTrackLine)
     {
         var sf = ShapefileFactory.FishingTrackLine(th);
         if (sf != null)
         {
             return(MapLayersHandler.AddLayer(sf, "Extracted fishng track", uniqueLayer: true, layerKey: sf.Key));
         }
     }
     return(-1);
 }
 public static int MapExtractedFishingTrack(out List <int> handles)
 {
     handles = new List <int>();
     if (ShapefileFactory.ExtractFishingTrackLine)
     {
         var sf = ShapefileFactory.FishingTrackLine();
         if (sf != null)
         {
             //return MapLayersHandler.AddLayer(sf, "Extracted fishng track", uniqueLayer: true, layerKey: sf.Key, rejectIfExisting: true);
             return(MapLayersHandler.AddLayer(sf, "Extracted fishng track", uniqueLayer: true, layerKey: sf.Key));
         }
     }
     return(-1);
 }
        public static bool AddExtractedTracksLayer(bool readFromDatabase = false)
        {
            bool proceed = true;

            if (readFromDatabase)
            {
                proceed = Entities.ExtractedFishingTrackViewModel.LoadTrackDataFromDatabase();
            }
            if (proceed && Entities.ExtractedFishingTrackViewModel.Count() > 0)
            {
                var sf = ShapefileFactory.FishingTrackLines();
                ExtractedTracksShapefile             = sf;
                sf.SelectionAppearance               = tkSelectionAppearance.saDrawingOptions;
                sf.DefaultDrawingOptions.LineColor   = new Utils().ColorByName(tkMapColor.Salmon);
                sf.SelectionDrawingOptions.LineWidth = 4f;
                return(MapLayersHandler.AddLayer(sf, "Fishing tracks", layerKey: sf.Key, uniqueLayer: true) >= 0);
            }
            return(false);
        }
Example #10
0
        public static int MapTripWaypoints(List <TripWaypoint> waypoints, out int shpIndex, out List <int> handles, GPS gps, string filename, bool showInMap = true)
        {
            shpIndex = -1;
            handles  = new List <int>();
            var utils       = new MapWinGIS.Utils();
            var shpfileName = "";

            if (showInMap)
            {
                if (waypoints.Count > 0)
                {
                    Shapefile sf = null;
                    sf          = ShapefileFactory.PointsFromWayPointList(waypoints, out handles, gps.DeviceName, filename);
                    shpfileName = "Trip waypoints";
                    int h = MapLayersHandler.AddLayer(sf, shpfileName, uniqueLayer: true, layerKey: sf.Key, rejectIfExisting: true);
                }
            }
            return(MapLayersHandler.CurrentMapLayer.Handle);
        }
        public static int MapTrip(Trip trip, out int shpIndex, out List <int> handles, bool showInMap = true)
        {
            shpIndex = -1;
            handles  = new List <int>();
            var utils       = new MapWinGIS.Utils();
            var shpfileName = "";

            if (showInMap)
            {
                if (trip.Track.Waypoints.Count > 0)
                {
                    Shapefile   sf    = null;
                    List <Trip> trips = new List <Trip>();
                    trips.Add(trip);
                    sf          = ShapefileFactory.TrackFromTrip(trips, out handles);
                    shpfileName = "Trip tracks";
                    MapLayersHandler.AddLayer(sf, shpfileName, uniqueLayer: true, layerKey: sf.Key, rejectIfExisting: true);
                }
            }
            return(MapLayersHandler.CurrentMapLayer.Handle);
        }
        public static int MapWaypointsCTX(CTXFileSummaryView ctx, out List <int> handles)
        {
            handles = new List <int>();
            Shapefile sf = null;

            if (ctx.WaypointsForSet != null && ctx.WaypointsForSet > 0 ||
                ctx.WaypointsForHaul != null && ctx.WaypointsForHaul > 0)
            {
                sf = ShapefileFactory.WaypointsFromCTX(ctx, out handles);
            }

            if (sf != null)
            {
                return(MapLayersHandler.AddLayer(sf, "CTX waypoints", uniqueLayer: true, layerKey: sf.Key, rejectIfExisting: true));
                //return MapLayersHandler.CurrentMapLayer.Handle;
            }
            else
            {
                return(-1);
            }
        }
Example #13
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);
        }