Пример #1
0
 protected virtual void Dispose(bool disposing)
 {
     if (!_disposed)
     {
         if (disposing)
         {
         }
         _mapLayersHandler = null;
         _currentMapLayer  = null;
         _axMap            = null;
         _disposed         = true;
     }
 }
Пример #2
0
 public MapLayersForm(MapLayersHandler mapLayers, MapperForm parent)
 {
     InitializeComponent();
     _parentForm                           = parent;
     _mapLayersHandler                     = mapLayers;
     _mapLayersHandler.LayerRead          += OnLayerRead;
     _mapLayersHandler.LayerRemoved       += OnLayerDeleted;
     _mapLayersHandler.OnLayerNameUpdate  += OnLayerNameUpdated;
     _mapLayersHandler.LayerRefreshNeeded += OnLayerRefreshRequest;
     layerGrid.CellClick                  += OnCellClick;
     layerGrid.CellMouseDown              += OnCellMouseDown;
     layerGrid.CellDoubleClick            += OnCellDoubleClick;
     layerGrid.DragDrop                   += OnLayerGrid_DragDrop;
     layerGrid.DragOver                   += OnLayerGrid_DragOver;
     layerGrid.MouseDown                  += OnLayerGrid_MouseDown;
     layerGrid.MouseMove                  += OnLayerGrid_MouseMove;
 }
Пример #3
0
 /// <summary>
 /// Constructor and sets up map control events
 /// </summary>
 /// <param name="mapControl"></param>
 /// <param name="layersHandler"></param>
 public MapInterActionHandler(AxMap mapControl, MapLayersHandler layersHandler)
 {
     _mapLayersHandler = layersHandler;
     _mapLayersHandler.CurrentLayer += OnCurrentMapLayer;
     _axMap = mapControl;
     _axMap.MouseUpEvent      += OnMapMouseUp;
     _axMap.MouseDownEvent    += OnMapMouseDown;
     _axMap.SelectBoxFinal    += OnMapSelectBoxFinal;
     _axMap.MouseMoveEvent    += OnMapMouseMove;
     _axMap.DblClick          += OnMapDoubleClick;
     _axMap.SelectionChanged  += OnMapSelectionChanged;
     _axMap.SendMouseDown      = true;
     _axMap.SendMouseMove      = true;
     _axMap.SendSelectBoxFinal = true;
     _axMap.SendMouseUp        = true;
     EnableMapInteraction      = true;
 }
        /// <summary>
        /// Map a single fishing ground when coming from a selected sampling
        /// </summary>
        /// <param name="fishingGround"></param>
        /// <param name="utmZone"></param>
        /// <returns></returns>
        public bool MapFishingGround(string fishingGround, fadUTMZone utmZone, string layerName = "", bool testIfInland = false)
        {
            var  sf          = new Shapefile();
            bool success     = false;
            var  fgLayerName = "Fishing ground";

            if (layerName.Length > 0)
            {
                fgLayerName = layerName;
            }
            if (sf.CreateNew("", ShpfileType.SHP_POINT))
            {
                var shp = new Shape();
                if (shp.Create(ShpfileType.SHP_POINT))
                {
                    var iShp = 0;
                    if (_geoProjection.IsGeographic)
                    {
                        var result = FishingGrid.Grid25ToLatLong(fishingGround, utmZone);
                        iShp = shp.AddPoint(result.longitude, result.latitude);
                    }
                    else
                    {
                        FishingGrid.Grid25_to_UTM(fishingGround, out int x, out int y);
                        iShp = shp.AddPoint(x, y);
                    }
                    if (iShp >= 0 && sf.EditInsertShape(shp, 0))
                    {
                        MapLayersHandler.RemoveLayer(fgLayerName);
                        sf.GeoProjection = _geoProjection;
                        var ifldLabel = sf.EditAddField("Label", FieldType.STRING_FIELD, 1, 15);
                        sf.EditCellValue(ifldLabel, iShp, fgLayerName);
                        sf.CollisionMode = tkCollisionMode.AllowCollisions;
                        SymbolizeFishingGround(sf, fgLayerName, testIfInland);

                        success = MapLayersHandler.AddLayer(sf, fgLayerName, true, true) >= 0;
                    }
                }
            }
            return(success);
        }
Пример #5
0
 public MapLayer(int handle, string name, bool visible, bool visibleInLayersUI, MapLayersHandler parent)
 {
     Handle             = handle;
     Name               = name;
     Visible            = visible;
     VisibleInLayersUI  = visibleInLayersUI;
     IsFishingGrid      = false;
     _parent            = parent;
     ClassificationType = ClassificationType.None;
 }
Пример #6
0
 /// <summary>
 /// Event fired when a layer was selected in the layers form
 /// </summary>
 /// <param name="s"></param>
 /// <param name="e"></param>
 private void OnCurrentLayer(MapLayersHandler s, LayerEventArg e)
 {
     _currentMapLayer = MapInterActionHandler.MapLayersHandler.CurrentMapLayer;
     DisplayAttributes();
 }
Пример #7
0
 private void OnCurrentMapLayer(MapLayersHandler s, LayerEventArg e)
 {
     _currentMapLayer = _mapLayersHandler.get_MapLayer(e.LayerHandle);
 }
Пример #8
0
 private void OnMapLayerRead(MapLayersHandler s, LayerEventArg e)
 {
 }
 public VisibilityQueryForm(MapLayersHandler handler)
 {
     InitializeComponent();
     _layersHandler = handler;
     _shapeFile     = _layersHandler.CurrentMapLayer.LayerObject as Shapefile;
 }
        /// <summary>
        /// maps fishing grounds belonging to a target area, landing site, or type of gear gear
        /// </summary>
        /// <param name="aoiGUID"></param>
        /// <param name="samplingYears"></param>
        /// <param name="utmZone"></param>
        /// <param name="Aggregated"></param>
        /// <param name="notInclude1"></param>
        /// <param name="landingSiteGuid"></param>
        /// <param name="gearVariationGuid"></param>
        public void MapFishingGrounds(string aoiGUID, string samplingYears, fadUTMZone utmZone,
                                      bool Aggregated          = true, bool notInclude1 = false, string landingSiteGuid = "",
                                      string gearVariationGuid = "")
        {
            var query     = "";
            var sf        = new Shapefile();
            var ifldAOI   = 0;
            var ifldLS    = 0;
            var ifldGear  = 0;
            var ifldYear  = 0;
            var ifldFG    = 0;
            var ifldCount = 0;
            var ifldMaxWt = 0;
            var ifldMinWt = 0;
            var ifldAfgWt = 0;

            var ifldEnumerator   = 0;
            var ifldGearClass    = 0;
            var ifldNumberHauls  = 0;
            var ifldNumberFisher = 0;
            var ifldDateSet      = 0;
            var ifldTimeSet      = 0;
            var ifldDateHauled   = 0;
            var ifldTimeHauled   = 0;
            var ifldVessel       = 0;
            var ifldHP           = 0;
            var ifldCatchWt      = 0;

            if (aoiGUID.Length > 0 && samplingYears.Length > 0 && sf.CreateNewWithShapeID("", ShpfileType.SHP_POINT))
            {
                ifldAOI = sf.EditAddField("AOIName", FieldType.STRING_FIELD, 1, 255);
                sf.Field[ifldAOI].Alias = "Target area name";

                if (Aggregated)
                {
                    if (landingSiteGuid.Length > 0)
                    {
                        ifldLS = sf.EditAddField("LSName", FieldType.STRING_FIELD, 1, 255);
                        sf.Field[ifldLS].Alias = "Landing site name";
                    }

                    if (gearVariationGuid.Length > 0)
                    {
                        ifldGear = sf.EditAddField("GearName", FieldType.STRING_FIELD, 1, 255);
                        sf.Field[ifldGear].Alias = "Gear variation used";
                    }

                    ifldYear = sf.EditAddField("Year", FieldType.INTEGER_FIELD, 1, 4);
                    sf.Field[ifldYear].Alias = "Year sampled";

                    ifldFG = sf.EditAddField("fg", FieldType.STRING_FIELD, 1, 25);
                    sf.Field[ifldFG].Alias = "Fishing ground";

                    ifldCount = sf.EditAddField("n", FieldType.INTEGER_FIELD, 1, 4);

                    ifldMaxWt = sf.EditAddField("MaxWt", FieldType.DOUBLE_FIELD, 2, 8);
                    sf.Field[ifldMaxWt].Alias = "Maximum catch weight";

                    ifldMinWt = sf.EditAddField("MinWt", FieldType.DOUBLE_FIELD, 2, 8);
                    sf.Field[ifldMinWt].Alias = "Minimum catch weight";

                    ifldAfgWt = sf.EditAddField("AvgWt", FieldType.DOUBLE_FIELD, 2, 8);
                    sf.Field[ifldAfgWt].Alias = "Average catch weight";

                    if (gearVariationGuid.Length > 0)
                    {
                        query = $@"SELECT tblAOI.AOIName, tblLandingSites.LSName, tblGearVariations.Variation, tblSampling.FishingGround,
                                Year([SamplingDate]) AS samplingYear, Count(tblSampling.SamplingGUID) AS n, Max(tblSampling.WtCatch) AS MaxCatch,
                                Min(tblSampling.WtCatch) AS MinCatch, Avg(tblSampling.WtCatch) AS AvgCatch FROM tblGearVariations
                                INNER JOIN ((tblAOI INNER JOIN tblLandingSites ON tblAOI.AOIGuid = tblLandingSites.AOIGuid)
                                INNER JOIN tblSampling ON tblLandingSites.LSGUID = tblSampling.LSGUID) ON tblGearVariations.GearVarGUID = tblSampling.GearVarGUID
                                WHERE tblLandingSites.LSGUID={{{landingSiteGuid}}} AND tblSampling.GearVarGUID={{{gearVariationGuid}}}
                                GROUP BY tblAOI.AOIName, tblLandingSites.LSName, tblGearVariations.Variation, tblSampling.FishingGround, Year([SamplingDate]) ";

                        if (notInclude1)
                        {
                            query += $"HAVING Count(tblSampling.SamplingGUID)>1 AND Year([SamplingDate]) In ({samplingYears})";
                        }
                        else
                        {
                            query += $"HAVING Year([SamplingDate]) In ({samplingYears})";
                        }
                    }
                    else if (landingSiteGuid.Length > 0)
                    {
                        query = $@"SELECT tblAOI.AOIName, tblLandingSites.LSName, tblSampling.FishingGround, Year([SamplingDate]) AS samplingYear,
                            Count(tblSampling.SamplingGUID) AS n, Max(tblSampling.WtCatch) AS MaxCatch, Min(tblSampling.WtCatch) AS MinCatch,
                            Avg(tblSampling.WtCatch) AS AvgCatch FROM (tblAOI INNER JOIN tblLandingSites ON tblAOI.AOIGuid = tblLandingSites.AOIGuid)
                            INNER JOIN tblSampling ON tblLandingSites.LSGUID = tblSampling.LSGUID WHERE tblLandingSites.LSGUID={{{landingSiteGuid}}}
                            GROUP BY tblAOI.AOIName, tblLandingSites.LSName, tblSampling.FishingGround, Year([SamplingDate]) ";

                        if (notInclude1)
                        {
                            query += $"HAVING Count(tblSampling.SamplingGUID)>1 AND Year([SamplingDate]) In ({samplingYears})";
                        }
                        else
                        {
                            query += $"HAVING Year([SamplingDate]) In ({samplingYears})";
                        }
                    }
                    else
                    {
                        query = $@"SELECT tblAOI.AOIName, tblSampling.FishingGround, Year([SamplingDate]) AS samplingYear,
                            Count(tblSampling.SamplingGUID) AS n, Max(tblSampling.WtCatch) AS MaxCatch,
                            Min(tblSampling.WtCatch) AS MinCatch, Avg(tblSampling.WtCatch) AS AvgCatch
                            FROM tblAOI INNER JOIN tblSampling ON tblAOI.AOIGuid = tblSampling.AOI
                            GROUP BY tblAOI.AOIName, tblSampling.FishingGround, tblSampling.AOI, Year([SamplingDate]) ";

                        if (notInclude1)
                        {
                            query += $"HAVING tblSampling.AOI= {{{aoiGUID}}} AND Count(tblSampling.SamplingGUID)>1 AND Year([SamplingDate]) In ({samplingYears})";
                        }
                        else
                        {
                            query += $"HAVING tblSampling.AOI= {{{aoiGUID}}} AND Year([SamplingDate]) In ({samplingYears})";
                        }
                    }
                }
                else //not aggregated
                {
                    ifldEnumerator = sf.EditAddField("Enumerat", FieldType.STRING_FIELD, 1, 100);
                    sf.Field[ifldEnumerator].Alias = "Name of enumerator";

                    ifldLS = sf.EditAddField("LSName", FieldType.STRING_FIELD, 1, 255);
                    sf.Field[ifldLS].Alias = "Landing site name";

                    ifldGearClass = sf.EditAddField("GearClass", FieldType.STRING_FIELD, 1, 100);
                    sf.Field[ifldGearClass].Alias = "Gear class used";

                    ifldGear = sf.EditAddField("GearName", FieldType.STRING_FIELD, 1, 255);
                    sf.Field[ifldGear].Alias = "Gear variation used";

                    ifldYear = sf.EditAddField("Year", FieldType.INTEGER_FIELD, 1, 4);
                    sf.Field[ifldYear].Alias = "Year sampled";

                    ifldFG = sf.EditAddField("fg", FieldType.STRING_FIELD, 1, 25);
                    sf.Field[ifldFG].Alias = "Fishing ground";

                    ifldNumberHauls = sf.EditAddField("NoHauls", FieldType.INTEGER_FIELD, 1, 2);
                    sf.Field[ifldNumberHauls].Alias = "Number of hauls";

                    ifldNumberFisher = sf.EditAddField("NoFishers", FieldType.INTEGER_FIELD, 1, 2);
                    sf.Field[ifldNumberFisher].Alias = "Number of fishers";

                    ifldDateSet = sf.EditAddField("DateSet", FieldType.DATE_FIELD, 1, 2);
                    sf.Field[ifldDateSet].Alias = "Date gear set";

                    ifldTimeSet = sf.EditAddField("TimeSet", FieldType.DATE_FIELD, 1, 2);
                    sf.Field[ifldTimeSet].Alias = "Time gear set";

                    ifldDateHauled = sf.EditAddField("DateHaul", FieldType.DATE_FIELD, 1, 2);
                    sf.Field[ifldDateHauled].Alias = "Date gear hauled";

                    ifldTimeHauled = sf.EditAddField("TimeHaul", FieldType.DATE_FIELD, 1, 2);
                    sf.Field[ifldTimeHauled].Alias = "Time gear hauled";

                    ifldVessel = sf.EditAddField("VesType", FieldType.STRING_FIELD, 1, 30);
                    sf.Field[ifldVessel].Alias = "Type of vessel used";

                    ifldHP = sf.EditAddField("hp", FieldType.STRING_FIELD, 1, 2);
                    sf.Field[ifldHP].Alias = "Engine hp";

                    ifldCatchWt = sf.EditAddField("CatchWt", FieldType.DOUBLE_FIELD, 2, 8);
                    sf.Field[ifldCatchWt].Alias = "Catch weight";

                    query = @"SELECT tblAOI.AOIName, tblEnumerators.EnumeratorName, tblLandingSites.LSName, tblGearClass.GearClassName,
                            tblGearVariations.Variation, Year([SamplingDate]) AS samplingYear, tblSampling.FishingGround, tblSampling.NoHauls,
                            tblSampling.NoFishers, tblSampling.DateSet, tblSampling.TimeSet, tblSampling.DateHauled, tblSampling.TimeHauled,
                            tblSampling.VesType, tblSampling.hp, tblSampling.WtCatch FROM (tblAOI INNER JOIN tblLandingSites ON
                            tblAOI.AOIGuid = tblLandingSites.AOIGuid) INNER JOIN ((tblGearClass INNER JOIN tblGearVariations ON
                            tblGearClass.GearClass = tblGearVariations.GearClass) INNER JOIN (tblEnumerators RIGHT JOIN tblSampling ON
                            tblEnumerators.EnumeratorID = tblSampling.Enumerator) ON tblGearVariations.GearVarGUID = tblSampling.GearVarGUID) ON
                            tblLandingSites.LSGUID = tblSampling.LSGUID ";

                    if (gearVariationGuid.Length > 0)
                    {
                        query += $@"WHERE Year([SamplingDate]) In({samplingYears}) AND tblSampling.LSGUID ={{{landingSiteGuid}}}
                                AND tblSampling.GearVarGUID ={{{gearVariationGuid}}}";
                    }
                    else if (landingSiteGuid.Length > 0)
                    {
                        query += $"WHERE Year([SamplingDate]) In({samplingYears}) AND tblSampling.LSGUID ={{{landingSiteGuid}}}";
                    }
                    else
                    {
                        query += $"WHERE Year([SamplingDate]) In({samplingYears}) AND tblSampling.AOI ={{{aoiGUID}}}";
                    }
                }

                using (var conection = new OleDbConnection("Provider=Microsoft.JET.OLEDB.4.0;data source=" + global.MDBPath))
                {
                    conection.Open();
                    using (var adapter = new OleDbDataAdapter(query, conection))
                        using (var myDT = new DataTable())
                        {
                            adapter.Fill(myDT);
                            //var n = 0;
                            foreach (DataRow dr in myDT.Rows)
                            {
                                var fg = dr["FishingGround"].ToString();
                                if (fg.Length > 0)
                                {
                                    var shp = new MapWinGIS.Shape();

                                    if (shp.Create(ShpfileType.SHP_POINT))
                                    {
                                        var proceed = false;
                                        if (RemoveInland && !FishingGrid.MinorGridIsInland(fg))
                                        {
                                            proceed = true;
                                        }
                                        else if (!RemoveInland)
                                        {
                                            proceed = true;
                                        }

                                        if (proceed)
                                        {
                                            var iShp = 0;
                                            if (_geoProjection.IsGeographic)
                                            {
                                                var result = FishingGrid.Grid25ToLatLong(fg, utmZone);
                                                iShp = shp.AddPoint(result.longitude, result.latitude);
                                            }
                                            else
                                            {
                                                FishingGrid.Grid25_to_UTM(fg, out int x, out int y);
                                                iShp = shp.AddPoint(x, y);
                                            }
                                            if (iShp >= 0 && sf.EditInsertShape(shp, 0))
                                            {
                                                sf.EditCellValue(ifldAOI, iShp, dr["AOIName"].ToString());
                                                sf.EditCellValue(ifldYear, iShp, int.Parse(dr["samplingYear"].ToString()));
                                                sf.EditCellValue(ifldFG, iShp, dr["FishingGround"].ToString());

                                                //aggregated
                                                if (Aggregated)
                                                {
                                                    if (landingSiteGuid.Length > 0)
                                                    {
                                                        sf.EditCellValue(ifldLS, iShp, dr["LSName"].ToString());
                                                    }
                                                    if (gearVariationGuid.Length > 0)
                                                    {
                                                        sf.EditCellValue(ifldGear, iShp, dr["Variation"].ToString());
                                                    }
                                                    sf.EditCellValue(ifldCount, iShp, int.Parse(dr["n"].ToString()));
                                                    sf.EditCellValue(ifldMaxWt, iShp, double.Parse(dr["MaxCatch"].ToString()));
                                                    sf.EditCellValue(ifldMinWt, iShp, double.Parse(dr["MinCatch"].ToString()));
                                                    sf.EditCellValue(ifldAfgWt, iShp, double.Parse(dr["AvgCatch"].ToString()));
                                                    Console.WriteLine($"n-{sf.CellValue[ifldCount, iShp]}, AvgCatch -{sf.CellValue[ifldAfgWt, iShp]}");
                                                }

                                                //not aggregated
                                                else
                                                {
                                                    sf.EditCellValue(ifldEnumerator, iShp, dr["EnumeratorName"].ToString());
                                                    sf.EditCellValue(ifldLS, iShp, dr["LSName"].ToString());
                                                    sf.EditCellValue(ifldGearClass, iShp, dr["GearClassName"].ToString());
                                                    sf.EditCellValue(ifldGear, iShp, dr["Variation"].ToString());

                                                    if (dr["NoHauls"].ToString().Length > 0)
                                                    {
                                                        sf.EditCellValue(ifldNumberHauls, iShp, int.Parse(dr["NoHauls"].ToString()));
                                                    }

                                                    if (dr["NoFishers"].ToString().Length > 0)
                                                    {
                                                        sf.EditCellValue(ifldNumberFisher, iShp, int.Parse(dr["NoFishers"].ToString()));
                                                    }

                                                    if (dr["DateSet"].ToString().Length > 0)
                                                    {
                                                        sf.EditCellValue(ifldDateSet, iShp, DateTime.Parse(dr["DateSet"].ToString()));
                                                    }

                                                    if (dr["TimeSet"].ToString().Length > 0)
                                                    {
                                                        sf.EditCellValue(ifldTimeSet, iShp, DateTime.Parse(dr["TimeSet"].ToString()));
                                                    }

                                                    if (dr["DateHauled"].ToString().Length > 0)
                                                    {
                                                        sf.EditCellValue(ifldDateHauled, iShp, DateTime.Parse(dr["DateHauled"].ToString()));
                                                    }

                                                    if (dr["TimeHauled"].ToString().Length > 0)
                                                    {
                                                        sf.EditCellValue(ifldTimeHauled, iShp, DateTime.Parse(dr["TimeHauled"].ToString()));
                                                    }

                                                    if (dr["VesType"].ToString().Length > 0)
                                                    {
                                                        var vesselType = "Motorized";
                                                        switch (int.Parse(dr["VesType"].ToString()))
                                                        {
                                                        case 1:
                                                            vesselType = "Motorized";
                                                            break;

                                                        case 2:
                                                            vesselType = "Non-motorized";
                                                            break;

                                                        case 3:
                                                            vesselType = "No vessel used";
                                                            break;

                                                        case 4:
                                                            vesselType = "Not provided";
                                                            break;
                                                        }
                                                        sf.EditCellValue(ifldVessel, iShp, vesselType);
                                                    }

                                                    if (dr["hp"].ToString().Length > 0)
                                                    {
                                                        sf.EditCellValue(ifldHP, iShp, dr["hp"].ToString());
                                                    }

                                                    sf.EditCellValue(ifldCatchWt, iShp, double.Parse(dr["WtCatch"].ToString()));
                                                }
                                            }
                                        }
                                    }
                                }

                                //n++;
                            }
                        }
                }
                MapLayersHandler.RemoveLayer("Fishing grounds");
                if (sf.NumShapes > 0)
                {
                    sf.GeoProjection = _geoProjection;
                    sf.CollisionMode = tkCollisionMode.AllowCollisions;
                    sf.DefaultDrawingOptions.PointShape = tkPointShapeType.ptShapeCircle;
                    sf.DefaultDrawingOptions.FillColor  = new Utils().ColorByName(tkMapColor.Red);
                    sf.DefaultDrawingOptions.LineColor  = new Utils().ColorByName(tkMapColor.White);
                    ClassificationType classificationType = ClassificationType.None;
                    if (Aggregated)
                    {
                        classificationType = ClassificationType.NaturalBreaks;
                        ShapefileLayerHelper.CategorizeNumericPointLayer(sf, ifldCount);
                    }
                    else
                    {
                        sf.DefaultDrawingOptions.PointSize = 7;
                    }
                    sf.SelectionAppearance = tkSelectionAppearance.saDrawingOptions;
                    sf.SelectionDrawingOptions.PointShape = tkPointShapeType.ptShapeCircle;

                    if (ShapefileLayerHelper.ExtentsPosition(MapControl.Extents, sf.Extents) == ExtentCompare.excoOutside)
                    {
                        var newExtent = MapControl.Extents;
                        newExtent.MoveTo(sf.Extents.Center.x, sf.Extents.Center.y);
                        MapControl.Extents = newExtent;
                    }
                    var h = MapLayersHandler.AddLayer(sf, "Fishing grounds", true, true);
                    MapLayersHandler[h].ClassificationType = classificationType;
                }
            }
        }
Пример #11
0
        public static bool ShowLandingSitesOnMap(MapLayersHandler layersHandler, string aoiGUID, GeoProjection gp, ref string layerName, bool uniqueLayerName = false)
        {
            layerName = "Landing sites";
            var myDT = new DataTable();
            var iShp = -1;

            using (var conection = new OleDbConnection(global.ConnectionString))
            {
                try
                {
                    conection.Open();
                    string query = $@"SELECT Municipality, ProvinceName, LSName, cx, cy
                                    FROM Provinces INNER JOIN (Municipalities INNER JOIN tblLandingSites ON Municipalities.MunNo = tblLandingSites.MunNo)
                                    ON Provinces.ProvNo = Municipalities.ProvNo
                                    WHERE tblLandingSites.AOIGuid={{{aoiGUID}}}";

                    var adapter = new OleDbDataAdapter(query, conection);
                    adapter.Fill(myDT);
                    if (myDT.Rows.Count > 0)
                    {
                        var sf = new Shapefile();
                        if (sf.CreateNewWithShapeID("", ShpfileType.SHP_POINT))
                        {
                            var ifldName = sf.EditAddField("Name", FieldType.STRING_FIELD, 1, 50);
                            var ifldLGU  = sf.EditAddField("LGU", FieldType.STRING_FIELD, 1, 50);
                            var ifldX    = sf.EditAddField("x", FieldType.DOUBLE_FIELD, 8, 12);
                            var ifldY    = sf.EditAddField("y", FieldType.DOUBLE_FIELD, 8, 12);
                            sf.GeoProjection = gp;

                            for (int i = 0; i < myDT.Rows.Count; i++)
                            {
                                DataRow dr = myDT.Rows[i];
                                if (dr["cx"].ToString().Length > 0 && dr["cy"].ToString().Length > 0)
                                {
                                    var x    = (double)dr["cx"];
                                    var y    = (double)dr["cy"];
                                    var name = dr["LSName"].ToString();
                                    var LGU  = $"{dr["Municipality"].ToString()}, {dr["ProvinceName"].ToString()}";
                                    var shp  = new Shape();
                                    if (shp.Create(ShpfileType.SHP_POINT))
                                    {
                                        if (global.MappingMode == fad3MappingMode.grid25Mode)
                                        {
                                            var converter = new LatLngUTMConverter("WGS 84");
                                            var result    = converter.convertLatLngToUtm(y, x);
                                            x = result.Easting;
                                            y = result.Northing;
                                        }

                                        shp.AddPoint(x, y);

                                        iShp = sf.EditAddShape(shp);
                                        if (iShp >= 0)
                                        {
                                            sf.EditCellValue(ifldName, iShp, name);
                                            sf.EditCellValue(ifldLGU, iShp, LGU);
                                            sf.EditCellValue(ifldX, iShp, x);
                                            sf.EditCellValue(ifldY, iShp, y);
                                        }
                                    }
                                }
                            }
                            sf.DefaultDrawingOptions.PointShape  = tkPointShapeType.ptShapeCircle;
                            sf.DefaultDrawingOptions.FillColor   = new Utils().ColorByName(tkMapColor.Red);
                            sf.DefaultDrawingOptions.PointSize   = 7;
                            sf.DefaultDrawingOptions.LineVisible = false;
                            if (sf.Labels.Generate("[Name]", tkLabelPositioning.lpCenter, false) > 0)
                            {
                                sf.Labels.FontSize     = 7;
                                sf.Labels.FontBold     = true;
                                sf.Labels.FrameVisible = false;
                            }
                            if (iShp >= 0)
                            {
                                layersHandler.AddLayer(sf, layerName, true, uniqueLayerName);
                            }
                        }
                    }
                }
                catch (Exception ex) { Logger.Log(ex.Message, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name); }
            }

            return(iShp >= 0);
        }
Пример #12
0
        /// <summary>
        /// Saves a grid25 fishing map image  to the filename specified
        /// </summary>
        /// <returns></returns>
        private bool SaveGrid25MapToImage()
        {
            var        layerDictionary = MapLayersHandler.LayerDictionary;
            List <int> layersOnTop     = new List <int>();

            //sort the dictionary according to the weight of the layer. Layers with bigger weights are placed below those with smaller weights.
            foreach (KeyValuePair <int, MapLayer> kv in layerDictionary.OrderByDescending(r => r.Value.LayerWeight).Take(layerDictionary.Count))
            {
                if (kv.Value.Visible)
                {
                    //the layers with heavier weights are moved to the top. As the loop progresses, layers with ligter weights are placed on
                    //top. When the loop finishes, the lightest layer is on top while the heaviest layer is at the bottom.
                    if (kv.Value.LayerWeight != null)
                    {
                        _axMap.MoveLayerTop(_axMap.get_LayerPosition(kv.Value.Handle));
                    }
                    else
                    {
                        //layers whose weights are null will be placed below layers with weight values
                        _axMap.get_Shapefile(kv.Key).Labels.VerticalPosition = tkVerticalPosition.vpAboveParentLayer;
                    }

                    if (kv.Value.IsGrid25Layer)
                    {
                        switch (kv.Value.Name)
                        {
                        case "MBR":
                            _handleGridBoundary = kv.Value.Handle;
                            break;

                        case "Labels":
                            _handleLabels = kv.Value.Handle;

                            break;

                        case "Major grid":
                            _handleMajorGrid = kv.Value.Handle;
                            break;

                        case "Minor grid":
                            _handleMinorGrid = kv.Value.Handle;
                            break;
                        }
                    }

                    if (kv.Value.KeepOnTop)
                    {
                        layersOnTop.Add(kv.Value.Handle);
                    }
                }
            }

            foreach (int lyr in layersOnTop)
            {
                _axMap.MoveLayerTop(_axMap.get_LayerPosition(lyr));
            }

            //add a mask to the map control
            SetMask();
            var handleMask = MapLayersHandler.AddLayer(_shapeFileMask, "Grid mask", true);

            //move the mask layer to the top
            _axMap.MoveLayerTop(_axMap.get_LayerPosition(handleMask));

            //move the boundary layer on top so that it won't be hidden by the mask
            _axMap.MoveLayerTop(_axMap.get_LayerPosition(_handleGridBoundary));

            //make sure that map labels are placed on top of all layers
            _axMap.get_Shapefile(_handleLabels).Labels.VerticalPosition = tkVerticalPosition.vpAboveAllLayers;

            _axMap.get_Shapefile(_handleLabels).Labels.AvoidCollisions = false;

            bool success = false;

            try
            {
                success = SaveMapHelper(handleMask);
            }
            catch
            {
                success = false;
            }
            return(success);
        }
Пример #13
0
        /// <summary>
        /// Actual functionality to save a map image to a file
        /// </summary>
        /// <param name="handleMask"> shapefile mask layer</param>
        /// <returns></returns>
        private bool SaveMapHelper(int?handleMask)
        {
            //we now compute the width (w) that corresponds to a map whose width fits the required dpi
            var   ext     = _axMap.Extents;
            var   w       = ((double)_axMap.Width) * ((double)_dpi / 96);
            bool  proceed = true;
            Image img     = new Image();

            try
            {
                //create an image whose width (w) will result in a map whose width in pixels fits the the required dpi
                img = _axMap.SnapShot3(ext.xMin, ext.xMax, ext.yMax, ext.yMin, (int)w);
            }
            catch (System.Runtime.InteropServices.COMException comex)
            {
                Logger.Log(comex.Message, "SaveMapImage.cs", "SaveMapHelper");
                proceed = false;
            }
            catch (Exception ex)
            {
                Logger.Log(ex.Message, "SaveMapImage.cs", "SaveMapHelper");
                proceed = false;
            }

            if (proceed)
            {
                //restore the map to its previous state by removing the mask and setting Reset to true
                if (handleMask != null)
                {
                    MapLayersHandler.RemoveLayer((int)handleMask);
                }
                Reset = true;
                AdjustFeatureSize();

                if (_saveToTempFile)
                {
                    _fileName = $@"{global.AppPath}\tempMap.jpg";
                    global.ListTemporaryFile(_fileName);
                    if (img.Save(_fileName))
                    {
                        img.Close();
                        return(true);
                    }
                    else
                    {
                        _fileName = $@"{global.AppPath}\tempMap1.jpg";
                        if (img.Save(_fileName))
                        {
                            img.Close();
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }
                else
                {
                    //specify filename of projection file for the image
                    var prjFileName = _fileName.Replace(Path.GetExtension(_fileName), ".prj");

                    //save the image to disk and create a worldfile. Image format is specified by USE_FILE_EXTENSION.
                    //also save the projection file
                    if (img.Save(_fileName, WriteWorldFile: true, FileType: ImageType.USE_FILE_EXTENSION) && _axMap.GeoProjection.WriteToFile(prjFileName))
                    {
                        //show the image file using the default image viewer
                        if (PreviewImage)
                        {
                            Process.Start(_fileName);
                        }
                        img.Close();
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            else
            {
                return(false);
            }
        }
Пример #14
0
 private void OnLayerNameUpdated(MapLayersHandler s, LayerEventArg e)
 {
     layerGrid[_layerCol, _layerRow].Value = e.LayerName;
 }
Пример #15
0
 private void OnVisibilityExpression(MapLayersHandler s, LayerEventArg e)
 {
     txtVisibilityExpression.Text = e.VisibilityExpression;
 }
Пример #16
0
 private void CleanUp()
 {
     _shapeFile     = null;
     _fontComboBox  = null;
     _layersHandler = null;
 }
        public bool MapSamplingFishingGround(string samplingGuid, fadUTMZone utmZone, string layerName)
        {
            var           success = false;
            string        refNo   = "";
            List <string> fg      = new List <string>();
            DataTable     dt      = new DataTable();

            using (var conection = new OleDbConnection(global.ConnectionString))
            {
                try
                {
                    conection.Open();
                    var sql     = $"Select RefNo from tblSampling WHERE SamplingGUID = {{{samplingGuid}}}";
                    var adapter = new OleDbDataAdapter(sql, conection);
                    adapter.Fill(dt);
                    DataRow dr = dt.Rows[0];
                    refNo = dr["RefNo"].ToString();

                    sql = $@"SELECT FishingGround FROM tblSampling WHERE SamplingGUID={{{samplingGuid}}}
                        UNION ALL
                        SELECT GridName from tblGrid
                        WHERE SamplingGUID={{{samplingGuid}}}";

                    dt.Rows.Clear();
                    adapter = new OleDbDataAdapter(sql, conection);
                    adapter.Fill(dt);

                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        dr = dt.Rows[i];
                        fg.Add(dr["FishingGround"].ToString());
                    }
                }
                catch (Exception ex)
                {
                    Logger.Log(ex.Message, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name);
                }
            }

            if (fg.Count > 0)
            {
                var sf = new Shapefile();
                if (sf.CreateNew("", ShpfileType.SHP_POINT))
                {
                    MapLayersHandler.RemoveLayer(layerName);
                    sf.GeoProjection = _geoProjection;
                    var ifldLabel = sf.EditAddField("Label", FieldType.STRING_FIELD, 1, 15);
                    sf.FieldByName["Label"].Alias = "Fishing ground";
                    var ifldRefNo = sf.EditAddField("RefNo", FieldType.STRING_FIELD, 1, 20);
                    sf.FieldByName["RefNo"].Alias = "Reference number";
                    foreach (var item in fg)
                    {
                        var shp = new Shape();
                        if (shp.Create(ShpfileType.SHP_POINT))
                        {
                            var iShp   = 0;
                            var result = FishingGrid.Grid25ToLatLong(item, utmZone);
                            iShp = shp.AddPoint(result.longitude, result.latitude);

                            if (iShp >= 0 && sf.EditInsertShape(shp, 0))
                            {
                                sf.EditCellValue(ifldLabel, iShp, item);
                                sf.EditCellValue(ifldRefNo, iShp, refNo);
                                sf.CollisionMode = tkCollisionMode.AllowCollisions;
                            }
                        }
                    }
                    sf.DefaultDrawingOptions.SetDefaultPointSymbol(tkDefaultPointSymbol.dpsCircle);
                    sf.DefaultDrawingOptions.FillColor   = new Utils().ColorByName(tkMapColor.Red);
                    sf.DefaultDrawingOptions.PointSize   = 7;
                    sf.DefaultDrawingOptions.LineVisible = false;
                    success = MapLayersHandler.AddLayer(sf, layerName, true, true) >= 0;
                    if (MapControl == null)
                    {
                        MapControl = global.MappingForm.MapControl;
                    }
                    if (!MapControl.Extents.ToShape().Contains(sf.Extents.ToShape()))
                    {
                        Point   pt  = sf.Extents.ToShape().Center;
                        Extents ext = MapControl.Extents;
                        ext.MoveTo(pt.x, pt.y);
                        MapControl.Extents = ext;
                    }
                }
            }
            return(success);
        }