Exemplo n.º 1
0
        /// <summary>
        /// Sets dummy color scheme based on the shapefile default color. The color schemes is the first in the list.
        /// </summary>
        public void SetDefaultColorScheme(Shapefile sf)
        {
            // settings dummy color scheme
            ColorBlend blend = null;

            if (List.Count <= 0)
            {
                blend           = new ColorBlend(2);
                blend.Colors[0] = Color.Black; blend.Positions[0] = 0.0f;
                blend.Colors[1] = Color.Black; blend.Positions[1] = 1.0f;
                List.Add(blend);
            }

            blend = (ColorBlend)List[0];
            ShpfileType shpType = ShapefileLayerHelper.ShapefileType2D(sf.ShapefileType);

            if (shpType == ShpfileType.SHP_POINT || shpType == ShpfileType.SHP_POLYGON || shpType == ShpfileType.SHP_MULTIPOINT)
            {
                blend.Colors[0] = Colors.UintToColor(sf.DefaultDrawingOptions.FillColor);
                blend.Colors[1] = Colors.UintToColor(sf.DefaultDrawingOptions.FillColor);
            }
            else if (shpType == ShpfileType.SHP_POLYLINE)
            {
                blend.Colors[0] = Colors.UintToColor(sf.DefaultDrawingOptions.LineColor);
                blend.Colors[1] = Colors.UintToColor(sf.DefaultDrawingOptions.LineColor);
            }
        }
Exemplo n.º 2
0
        public bool MapGearDistribution(List <GearInventoryMappingItem> distributionList, string gearName, bool doFisherJenks = false)
        {
            Shapefile sf = new Shapefile();

            if (sf.CreateNew("", ShpfileType.SHP_POINT))
            {
                sf.GeoProjection = _mapControl.GeoProjection;
                int ifldProjectName      = sf.EditAddField("Inventory project", FieldType.STRING_FIELD, 1, 50);
                int ifldProvince         = sf.EditAddField("Province", FieldType.STRING_FIELD, 1, 30);
                int ifldMunicipalityName = sf.EditAddField("Municipality", FieldType.STRING_FIELD, 1, 30);
                int ifldMuni             = sf.EditAddField("Muni", FieldType.STRING_FIELD, 1, 8);
                int ifldGear             = sf.EditAddField("Gear", FieldType.STRING_FIELD, 1, 50);
                int ifldX               = sf.EditAddField("x", FieldType.DOUBLE_FIELD, 9, 12);
                int ifldY               = sf.EditAddField("y", FieldType.DOUBLE_FIELD, 9, 12);
                int ifldCount           = sf.EditAddField("n", FieldType.INTEGER_FIELD, 1, 7);
                int ifldCommercial      = sf.EditAddField("Commercial", FieldType.INTEGER_FIELD, 1, 7);
                int ifldMunicipalMot    = sf.EditAddField("Motorized", FieldType.INTEGER_FIELD, 1, 7);
                int ifldMunicipalNonMot = sf.EditAddField("Non-motorized", FieldType.INTEGER_FIELD, 1, 7);
                int ifldNoBoat          = sf.EditAddField("No boat", FieldType.INTEGER_FIELD, 1, 7);
                foreach (var item in distributionList)
                {
                    Shape sh = new Shape();
                    if (sh.Create(ShpfileType.SHP_POINT) && sh.AddPoint(item.X, item.Y) >= 0)
                    {
                        var iShp = sf.EditAddShape(sh);
                        if (iShp >= 0)
                        {
                            sf.EditCellValue(ifldProjectName, iShp, item.InventoryProjectName);
                            sf.EditCellValue(ifldProvince, iShp, item.ProvinceName);
                            sf.EditCellValue(ifldMunicipalityName, iShp, item.Municipality);
                            //sf.EditCellValue(ifldMunNameAbbrev, iShp, item.Municipality.Substring(0, 4));
                            sf.EditCellValue(ifldMuni, iShp, Database.Classes.LGUs.ShortenPlaceName(item.Municipality));
                            sf.EditCellValue(ifldGear, iShp, item.GearVariationName);
                            sf.EditCellValue(ifldX, iShp, item.X);
                            sf.EditCellValue(ifldY, iShp, item.Y);
                            sf.EditCellValue(ifldCount, iShp, item.TotalUsed);
                            sf.EditCellValue(ifldCommercial, iShp, item.CountCommercial);
                            sf.EditCellValue(ifldMunicipalMot, iShp, item.CountMunicipalMotorized);
                            sf.EditCellValue(ifldMunicipalNonMot, iShp, item.CountMunicipalNonMotorized);
                            sf.EditCellValue(ifldNoBoat, iShp, item.CountNoBoat);
                        }
                    }
                }
                sf.DefaultDrawingOptions.PointShape  = tkPointShapeType.ptShapeCircle;
                sf.DefaultDrawingOptions.FillColor   = new Utils().ColorByName(tkMapColor.Blue);
                sf.DefaultDrawingOptions.LineColor   = new Utils().ColorByName(tkMapColor.White);
                sf.DefaultDrawingOptions.LineVisible = true;
                sf.CollisionMode = tkCollisionMode.AllowCollisions;
                Database.Classes.ClassificationType classificationType = Database.Classes.ClassificationType.NaturalBreaks;
                if (ComparisonAmongLGUs)
                {
                    ShapefileLayerHelper.CategorizeNumericPointLayer(sf, ifldCount);
                }
                else
                {
                    ShapefileLayerHelper.CategorizeNumericPointLayer(sf, GearDataFisherJenksBreaks, ifldCount, BreakSourceMaximum);
                    classificationType = Database.Classes.ClassificationType.JenksFisher;
                }
                InventoryLayerHandle = _layersHandler.AddLayer(sf, gearName);
                _layersHandler[InventoryLayerHandle].ClassificationType = classificationType;
                //_layersHandler.set_MapLayer(h);

                if (Labels != null)
                {
                    sf.Labels.Clear();
                    _layersHandler.ShapeFileLableHandler.LabelShapefile(_labelXML);
                }

                _layersHandler.SetAsPointLayerFromDatabase(_layersHandler[InventoryLayerHandle]);
            }
            return(sf.NumShapes > 0);
        }
Exemplo n.º 3
0
        public bool MapFisherBoatDistribution(List <FisherVesselInventoryItem> distributionList, string itemToMap)
        {
            Shapefile sf = new Shapefile();

            if (sf.CreateNew("", ShpfileType.SHP_POINT))
            {
                sf.GeoProjection = _mapControl.GeoProjection;
                int ifldProjectName      = sf.EditAddField("Inventory project", FieldType.STRING_FIELD, 1, 50);
                int ifldProvince         = sf.EditAddField("Province", FieldType.STRING_FIELD, 1, 30);
                int ifldMunicipalityName = sf.EditAddField("Municipality", FieldType.STRING_FIELD, 1, 30);
                int ifldMuni             = sf.EditAddField("Muni", FieldType.STRING_FIELD, 1, 4);
                int ifldX               = sf.EditAddField("x", FieldType.DOUBLE_FIELD, 9, 12);
                int ifldY               = sf.EditAddField("y", FieldType.DOUBLE_FIELD, 9, 12);
                int ifldFishers         = sf.EditAddField("Fishers", FieldType.INTEGER_FIELD, 1, 7);
                int ifldCommercial      = sf.EditAddField("Commercial", FieldType.INTEGER_FIELD, 1, 7);
                int ifldMunicipalMot    = sf.EditAddField("Municipal Motorized", FieldType.INTEGER_FIELD, 1, 7);
                int ifldMunicipalNonMot = sf.EditAddField("Municipal Non-motorized", FieldType.INTEGER_FIELD, 1, 7);
                foreach (var item in distributionList)
                {
                    Shape sh = new Shape();
                    if (sh.Create(ShpfileType.SHP_POINT) && sh.AddPoint(item.X, item.Y) >= 0)
                    {
                        var iShp = sf.EditAddShape(sh);
                        if (iShp >= 0)
                        {
                            sf.EditCellValue(ifldProjectName, iShp, item.InventoryProjectName);
                            sf.EditCellValue(ifldProvince, iShp, item.ProvinceName);
                            sf.EditCellValue(ifldMunicipalityName, iShp, item.Municipality);
                            sf.EditCellValue(ifldMuni, iShp, Database.Classes.LGUs.ShortenPlaceName(item.Municipality));
                            sf.EditCellValue(ifldX, iShp, item.X);
                            sf.EditCellValue(ifldY, iShp, item.Y);
                            sf.EditCellValue(ifldFishers, iShp, item.CountFisher);
                            sf.EditCellValue(ifldCommercial, iShp, item.CountCommercial);
                            sf.EditCellValue(ifldMunicipalMot, iShp, item.CountMunicipalMotorized);
                            sf.EditCellValue(ifldMunicipalNonMot, iShp, item.CountMunicipalNonMotorized);
                        }
                    }
                }
                sf.DefaultDrawingOptions.PointShape  = tkPointShapeType.ptShapeCircle;
                sf.DefaultDrawingOptions.FillColor   = new Utils().ColorByName(tkMapColor.Blue);
                sf.DefaultDrawingOptions.LineColor   = new Utils().ColorByName(tkMapColor.White);
                sf.DefaultDrawingOptions.LineVisible = true;
                sf.CollisionMode = tkCollisionMode.AllowCollisions;

                int    fld      = 0;
                string itemName = "";
                switch (itemToMap)
                {
                case "fishers":
                    itemName = "Total number of fishers";
                    fld      = ifldFishers;
                    break;

                case "commercial":
                    fld      = ifldCommercial;
                    itemName = "Total number of commercial fishing vessels";
                    break;

                case "municipalMotorized":
                    fld      = ifldMunicipalMot;
                    itemName = "Total number of municipal motorized vessels";
                    break;

                case "municipalNonMotorized":
                    fld      = ifldMunicipalNonMot;
                    itemName = "Total number of municipal non-motorized vessels";
                    break;
                }

                Database.Classes.ClassificationType classificationType = Database.Classes.ClassificationType.NaturalBreaks;
                if (itemToMap == "fishers" || ComparisonAmongLGUs)
                {
                    ShapefileLayerHelper.CategorizeNumericPointLayer(sf, fld);
                }
                else
                {
                    ShapefileLayerHelper.CategorizeNumericPointLayer(sf, FisherVesselDataFisherJenksBreaks, fld, BreakSourceMaximum);
                    classificationType = Database.Classes.ClassificationType.JenksFisher;
                }

                InventoryLayerHandle = _layersHandler.AddLayer(sf, itemName);
                _layersHandler[InventoryLayerHandle].IgnoreZeroWhenClassifying = true;
                _layersHandler[InventoryLayerHandle].ClassificationType        = classificationType;

                if (Labels != null)
                {
                    sf.Labels.Clear();
                    _layersHandler.ShapeFileLableHandler.LabelShapefile(_labelXML);
                }
                _layersHandler.SetAsPointLayerFromDatabase(_layersHandler[InventoryLayerHandle]);
            }
            return(sf.NumShapes > 0);
        }
Exemplo n.º 4
0
        private bool SpeciesOccurenceMapping()
        {
            string sql = "";

            if (Aggregate)
            {
                if (MapInSelectedTargetArea)
                {
                    sql = $@"SELECT tblAOI.AOIName,
                                tblSampling.FishingGround,
                                Count(tblSampling.SamplingGUID) AS n,
                                tblAOI.UTMZone
                            FROM (tblSampling INNER JOIN
                                tblAOI ON
                                tblSampling.AOI = tblAOI.AOIGuid) INNER JOIN
                                tblCatchComp ON tblSampling.SamplingGUID = tblCatchComp.SamplingGUID
                            WHERE tblCatchComp.NameGUID = {{{ItemToMapGuid}}} AND
                                Year([SamplingDate]) In ({YearsToCSV()}) AND
                                tblSampling.FishingGround Is Not Null AND
                                tblAOI.UTMZone Is Not Null AND
                                tblAOI.AOIGuid={{{SelectedTargetAreaGuid}}}
                            GROUP BY tblAOI.AOIName,
                                tblSampling.FishingGround,
                                tblAOI.UTMZone";
                }
                else
                {
                    sql = $@"SELECT tblAOI.AOIName,
                              tblSampling.FishingGround,
                              Count(tblSampling.SamplingGUID) AS n,
                              tblAOI.UTMZone
                            FROM (tblSampling INNER JOIN
                              tblCatchComp ON
                              tblSampling.SamplingGUID = tblCatchComp.SamplingGUID) INNER JOIN
                              tblAOI ON tblSampling.AOI = tblAOI.AOIGuid
                            WHERE Year([SamplingDate]) In ({YearsToCSV()}) AND
                              tblSampling.FishingGround Is Not Null AND
                              tblAOI.UTMZone Is Not Null AND
                              tblCatchComp.NameGUID={{{ItemToMapGuid}}}
                            GROUP BY tblAOI.AOIName,
                              tblSampling.FishingGround,
                              tblAOI.UTMZone";
                }
            }
            else
            {
                if (MapInSelectedTargetArea)
                {
                    sql = $@"SELECT tblAOI.AOIName,
                                tblEnumerators.EnumeratorName,
                                tblSampling.*,
                                tblLandingSites.LSName,
                                tblGearClass.GearClassName,
                                tblGearVariations.Variation,
                                tblAOI.UTMZone
                            FROM tblEnumerators
                                RIGHT JOIN ((tblAOI INNER JOIN tblLandingSites ON
                                tblAOI.AOIGuid = tblLandingSites.AOIGuid) INNER JOIN
                                ((tblGearClass INNER JOIN tblGearVariations ON
                                tblGearClass.GearClass = tblGearVariations.GearClass) INNER JOIN
                                (tblSampling INNER JOIN tblCatchComp ON
                                tblSampling.SamplingGUID = tblCatchComp.SamplingGUID) ON
                                tblGearVariations.GearVarGUID = tblSampling.GearVarGUID) ON
                                tblLandingSites.LSGUID = tblSampling.LSGUID) ON
                                tblEnumerators.EnumeratorID = tblSampling.Enumerator
                            WHERE tblSampling.AOI={{{SelectedTargetAreaGuid}}} AND
                                tblAOI.UTMZone Is Not Null AND
                                tblCatchComp.NameGUID={{{ItemToMapGuid}}} AND
                                Year([SamplingDate]) In ({YearsToCSV()}) AND
                                tblSampling.FishingGround Is Not Null
                            ORDER BY tblAOI.AOIName,
                                tblGearClass.GearClassName,
                                tblGearVariations.Variation,
                                tblSampling.SamplingDate";
                }
                else
                {
                    sql = $@"SELECT tblAOI.AOIName,
                                tblEnumerators.EnumeratorName,
                                tblSampling.*,
                                tblLandingSites.LSName,
                                tblGearClass.GearClassName,
                                tblGearVariations.Variation,
                                tblAOI.UTMZone
                            FROM tblEnumerators
                                RIGHT JOIN ((tblAOI INNER JOIN tblLandingSites ON
                                tblAOI.AOIGuid = tblLandingSites.AOIGuid) INNER JOIN
                                ((tblGearClass INNER JOIN tblGearVariations ON
                                tblGearClass.GearClass = tblGearVariations.GearClass) INNER JOIN
                                (tblSampling INNER JOIN tblCatchComp ON
                                tblSampling.SamplingGUID = tblCatchComp.SamplingGUID) ON
                                tblGearVariations.GearVarGUID = tblSampling.GearVarGUID) ON
                                tblLandingSites.LSGUID = tblSampling.LSGUID) ON
                                tblEnumerators.EnumeratorID = tblSampling.Enumerator
                            WHERE tblCatchComp.NameGUID={{{ItemToMapGuid}}} AND
                                Year([SamplingDate]) In ({YearsToCSV()}) AND
                                tblSampling.FishingGround Is Not Null AND
                                tblAOI.UTMZone Is Not Null
                            ORDER BY tblAOI.AOIName,
                                tblGearClass.GearClassName,
                                tblGearVariations.Variation,
                                tblSampling.SamplingDate";
                }
            }
            try
            {
                var sf = new Shapefile();
                if (sf.CreateNew("", ShpfileType.SHP_POINT))
                {
                    sf.GeoProjection = MapControl.GeoProjection;
                    var ifldTargetArea      = -1;
                    var ifldCount           = -1;
                    var ifldFishingGround   = -1;
                    var ifldSpeciesName     = -1;
                    var ifldGearClass       = -1;
                    var ifldGearVariation   = -1;
                    var ifldCatchWt         = -1;
                    var ifldReferenceNumber = -1;
                    var ifldSamplingDate    = -1;
                    var ifldVesselType      = -1;
                    var ifldLandindSite     = -1;
                    var ifldEnumerator      = -1;
                    if (Aggregate)
                    {
                        ifldTargetArea    = sf.EditAddField("TargetArea", FieldType.STRING_FIELD, 1, 100);
                        ifldFishingGround = sf.EditAddField("FG", FieldType.STRING_FIELD, 1, 8);
                        ifldSpeciesName   = sf.EditAddField("Species", FieldType.STRING_FIELD, 1, 100);
                        ifldCount         = sf.EditAddField("n", FieldType.INTEGER_FIELD, 1, 4);
                    }
                    else
                    {
                        ifldReferenceNumber = sf.EditAddField("RefNo", FieldType.STRING_FIELD, 1, 20);
                        ifldEnumerator      = sf.EditAddField("Enumerator", FieldType.STRING_FIELD, 1, 30);
                        ifldSpeciesName     = sf.EditAddField("Species", FieldType.STRING_FIELD, 1, 100);
                        ifldTargetArea      = sf.EditAddField("TargetArea", FieldType.STRING_FIELD, 1, 100);
                        ifldLandindSite     = sf.EditAddField("LandingSite", FieldType.STRING_FIELD, 1, 50);
                        ifldSamplingDate    = sf.EditAddField("SamplingDate", FieldType.DATE_FIELD, 1, 1);
                        ifldGearClass       = sf.EditAddField("GearClass", FieldType.STRING_FIELD, 1, 25);
                        ifldGearVariation   = sf.EditAddField("GearVariation", FieldType.STRING_FIELD, 1, 35);
                        ifldFishingGround   = sf.EditAddField("FishingGround", FieldType.STRING_FIELD, 1, 8);
                        ifldCatchWt         = sf.EditAddField("CatchWeight", FieldType.DATE_FIELD, 2, 10);
                        ifldVesselType      = sf.EditAddField("Vessel", FieldType.STRING_FIELD, 1, 25);
                    }

                    using (OleDbConnection conn = new OleDbConnection(global.ConnectionString))
                    {
                        conn.Open();
                        var       adapter = new OleDbDataAdapter(sql, conn);
                        DataTable dt      = new DataTable();
                        adapter.Fill(dt);
                        if (dt.Rows.Count > 0)
                        {
                            for (int n = 0; n < dt.Rows.Count; n++)
                            {
                                DataRow    dr      = dt.Rows[n];
                                var        fg      = dr["FishingGround"].ToString();
                                var        zone    = dr["UTMZone"].ToString();
                                fadUTMZone utmZone = FishingGrid.ZoneFromZoneName(zone);
                                FishingGrid.UTMZone = utmZone;
                                var latlong = FishingGrid.Grid25ToLatLong(fg, utmZone);
                                var shp     = new Shape();
                                if (shp.Create(ShpfileType.SHP_POINT) && shp.AddPoint(latlong.longitude, latlong.latitude) >= 0)
                                {
                                    var iShp = sf.EditAddShape(shp);
                                    if (Aggregate)
                                    {
                                        if (sf.EditCellValue(ifldTargetArea, iShp, dr["AOIName"].ToString()))
                                        {
                                            sf.EditCellValue(ifldCount, iShp, (int)dr["n"]);
                                            sf.EditCellValue(ifldSpeciesName, iShp, ItemName);
                                            sf.EditCellValue(ifldFishingGround, iShp, fg);
                                        }
                                    }
                                    else
                                    {
                                        sf.EditCellValue(ifldSpeciesName, iShp, ItemName);
                                        sf.EditCellValue(ifldEnumerator, iShp, dr["EnumeratorName"].ToString());
                                        sf.EditCellValue(ifldTargetArea, iShp, dr["AOIName"].ToString());
                                        sf.EditCellValue(ifldFishingGround, iShp, fg);
                                        sf.EditCellValue(ifldGearClass, iShp, dr["GearClassName"].ToString());
                                        sf.EditCellValue(ifldGearVariation, iShp, dr["Variation"].ToString());
                                        sf.EditCellValue(ifldReferenceNumber, iShp, dr["RefNo"].ToString());
                                        sf.EditCellValue(ifldSamplingDate, iShp, string.Format("{0:MMM-dd-yyyy}", (DateTime)dr["SamplingDate"]));
                                        sf.EditCellValue(ifldCatchWt, iShp, (double)dr["WtCatch"]);
                                        sf.EditCellValue(ifldVesselType, iShp, FishingVessel.VesselTypeFromVesselTypeNumber((int)dr["VesType"]));
                                        sf.EditCellValue(ifldLandindSite, iShp, dr["LSName"].ToString());
                                    }
                                }
                            }
                        }
                    }
                    sf.DefaultDrawingOptions.PointShape = tkPointShapeType.ptShapeCircle;
                    ClassificationType classificationType = ClassificationType.None;
                    if (Aggregate)
                    {
                        ShapefileLayerHelper.CategorizeNumericPointLayer(sf, ifldCount);
                        sf.DefaultDrawingOptions.LineVisible = true;
                        sf.DefaultDrawingOptions.LineColor   = new Utils().ColorByName(tkMapColor.White);
                        sf.CollisionMode   = tkCollisionMode.AllowCollisions;
                        classificationType = ClassificationType.JenksFisher;
                    }
                    else
                    {
                        sf.DefaultDrawingOptions.PointSize = 8;
                    }

                    var h = MapLayersHandler.AddLayer(sf, $"Species mapping: {ItemName} ({YearsToCSV()})", mappingMode: fad3MappingMode.occurenceMappingSpeciesAggregated);
                    MapLayersHandler[h].ClassificationType = classificationType;
                    MapControl.Redraw();
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex.Message, "OcuurenceMapping", "SpeciesOccurence");
            }
            return(true);
        }