예제 #1
0
 /// <summary>
 /// Creates and adds shape corresponding to grid value val to shapeFile
 /// </summary>
 /// <param name="shapeFile"></param>
 /// <param name="val"></param>
 /// <param name="shapeIndex">set to index of added shape</param>
 /// <returns>true if shape successfully added</returns>
 public bool InsertShape(MapWinGIS.Shapefile shapeFile, int val, ref int shapeIndex)
 {
     MapWinGIS.Shape shape = offset.makeShape(ShapesTable[val].polygons);
     if (shape == null)
     {
         return(false);
     }
     else
     {
         return(shapeFile.EditInsertShape(shape, ref shapeIndex));
     }
 }
예제 #2
0
        /// <summary>
        /// determine if the shape is partially inside grid extents
        /// </summary>
        /// <param name="shp"></param>
        /// <param name="hdr"></param>
        /// <returns>false, if the shape is completely outside grid extents
        ///          true, if it's at least partially inside</returns>
        private bool IsGridContainsShape(MapWinGIS.Shape shp, MapWinGIS.GridHeader hdr)
        {
            double gridXmin = hdr.XllCenter;
            double gridYmin = hdr.YllCenter;
            double gridXmax = gridXmin + (hdr.NumberCols * hdr.dX);
            double gridYmax = gridYmin + (hdr.NumberRows * hdr.dY);

            MapWinGIS.Extents ext = shp.Extents;
            if (ext.xMin > gridXmax || ext.yMin > gridYmax ||
                ext.xMax < gridXmin || ext.yMax < gridYmin)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
예제 #3
0
            /// <summary>
            /// Makes a shape from a list of polygons; each polygon becames a part of the shape.
            /// </summary>
            /// <param name="polygons"></param>
            /// <returns>null if error, else shape</returns>
            public MapWinGIS.Shape makeShape(List <Polygon> polygons)
            {
                MapWinGIS.Shape shape = new MapWinGIS.Shape();
                if (!shape.Create(MapWinGIS.ShpfileType.SHP_POLYGON))
                {
                    return(null);
                }
                int pointindex = 0;
                int partindex  = 0;

                for (int i = 0; i < polygons.Count; i++)
                {
                    if (!addChainToShape(polygons[i].perimeter, shape, ref partindex, ref pointindex))
                    {
                        return(null);
                    }
                }
                return(shape);
            }
예제 #4
0
            /// <summary>
            /// Adds a chain of links as a part to a shape
            /// </summary>
            /// <param name="l">chain</param>
            /// <param name="shape"></param>
            /// <param name="partindex"></param>
            /// <param name="pointindex"></param>
            /// <returns>true iff no eror</returns>
            private bool addChainToShape(List <Link> l, MapWinGIS.Shape shape,
                                         ref int partindex, ref int pointindex)
            {
                if (!shape.InsertPart(pointindex, ref partindex))
                {
                    return(false);
                }
                partindex++;
                Polygon.rotate(l);
                Link l0 = l[0];

                MapWinGIS.Point p0;
                p0 = linkToPoint(l0);
                if (!shape.InsertPoint(p0, ref pointindex))
                {
                    return(false);
                }
                pointindex++;
                Direction lastDir = l0.dir;

                for (int i = 1; i < l.Count; i++)
                {
                    Link nextLink = l[i];
                    if (nextLink.dir != lastDir)
                    {
                        // next link has a new direction, so include its start point
                        if (!shape.InsertPoint(linkToPoint(nextLink), ref pointindex))
                        {
                            return(false);
                        }
                        pointindex++;
                    }
                    lastDir = nextLink.dir;
                }
                // close the polygon
                if (!shape.InsertPoint(p0, ref pointindex))
                {
                    return(false);
                }
                pointindex++;
                return(true);
            }
예제 #5
0
파일: Rasterizer.cs 프로젝트: qlands/GOBLET
        /// <summary>
        /// converts a Line shapefile to grid using Bresenham algorithm
        /// </summary>
        /// <param name="PolySf">Polygon shapefile object</param>
        /// <param name="FldID">Field index</param>
        /// <param name="Newgrd">New grid object</param>
        /// <param name="header">Grid header</param>
        /// <param name="nodatavalue"></param>
        /// <param name="cback">optional, for reporting progress</param>
        /// <returns>true if successful</returns>
        private bool Line2Grid(MapWinGIS.Shapefile LineSf, int FldID, MapWinGIS.Grid Newgrd,
            MapWinGIS.GridHeader header, MapWinGIS.GridDataType grType, MapWinGIS.ICallback cback)
        {
            int numParts, numPoints;
            int curPartStart, curPartEnd, vertexCol, vertexRow, lastCol, lastRow;
            int nShps = LineSf.NumShapes;
            int perc = 1;
            int shpsPerc = NumPercentShapes(perc, nShps); //percent of progress
            int s = 0; //shape number
            int p = 0; //part number
            int k = 0; //point number
            MapWinGIS.Shape LineShp = new MapWinGIS.Shape();
            MapWinGIS.Point curPoint;
            //Rasterization ras = new Rasterization(); //rasterization class, contains the code of
            //lineToGrid methods independent on MapWinGIS functions
            ArrayList vertices = new ArrayList(); //list of line vertex points
            ArrayList pixels = new ArrayList();   //list of calculated pixels on the line
            GridPixel px;

            object val; //the shape's value

            for (s = 0; s < nShps; ++s)
            {
            LineShp = LineSf.get_Shape(s);
            numParts = LineShp.NumParts;
            numPoints = LineShp.numPoints;

            //exclude shapes which are completely outside of the grid extents
            if (!IsGridContainsShape(LineShp, header))
            {
                continue;
            }

            //get the shape's value
            val = GetCellValue(LineSf, FldID, s, header.NodataValue);

            //process each part of the polyline
            curPartStart = 0;
            for (p = 0; p < numParts; ++p)
            {
                vertices.Clear();
                pixels.Clear();

                curPartStart = LineShp.get_Part(p);

                // check for multi-part lines
                if (p < numParts - 1)
                {
                    curPartEnd = LineShp.get_Part(p + 1) - 1;
                }
                else
                {
                    curPartEnd = numPoints - 1;
                }

                //go to next part if there's zero points
                if (numPoints <= 0)
                {
                    continue;
                }

                // add all points of current part to rasterization list
                // always add the first point of the part (convert its coordinates to
                // grid row and column)
                curPoint = LineShp.get_Point(curPartStart);
                Newgrd.ProjToCell(curPoint.x, curPoint.y,
                        out vertexCol, out vertexRow);
                px.col = vertexCol;
                px.row = vertexRow;
                vertices.Add(px);
                lastCol = vertexCol; lastRow = vertexRow;

                // add all other points with different grid coordinates
                for (k = curPartStart + 1; k <= curPartEnd; ++k)
                {
                    // (check if it has a different row or column than the previous point)
                    curPoint = LineShp.get_Point(k);
                    Newgrd.ProjToCell(curPoint.x, curPoint.y,
                        out vertexCol, out vertexRow);
                    if (vertexCol != lastCol || vertexRow != lastRow)
                    {
                        px.col = vertexCol;
                        px.row = vertexRow;
                        vertices.Add(px);
                        lastCol = vertexCol;
                        lastRow = vertexRow;
                    }
                }

                // convert the polyline and write pixels to grid
                LineBresenham(vertices, pixels);
                writePxList(Newgrd, grType, pixels, val, cback);

            }

            //report the progress
            if (s >= shpsPerc)
            {
                reportProgress(shpsPerc, nShps, "shapefile to grid", cback);
                perc = (int)((s * 100) / nShps);
                shpsPerc = NumPercentShapes(perc + 1, nShps);
            }
            }
            return true;
        }
예제 #6
0
/// <summary>
        /// converts a Line shapefile to grid using Bresenham algorithm
        /// </summary>
        /// <param name="PolySf">Polygon shapefile object</param>
        /// <param name="FldID">Field index</param>
        /// <param name="Newgrd">New grid object</param>
        /// <param name="header">Grid header</param>
        /// <param name="nodatavalue"></param>
        /// <param name="cback">optional, for reporting progress</param>
        /// <returns>true if successful</returns>

        private bool Line2Grid(MapWinGIS.Shapefile LineSf, int FldID, MapWinGIS.Grid Newgrd,
                               MapWinGIS.GridHeader header, MapWinGIS.GridDataType grType, MapWinGIS.ICallback cback)
        {
            int numParts, numPoints;
            int curPartStart, curPartEnd, vertexCol, vertexRow, lastCol, lastRow;
            int nShps    = LineSf.NumShapes;
            int perc     = 1;
            int shpsPerc = NumPercentShapes(perc, nShps); //percent of progress
            int s        = 0;                             //shape number
            int p        = 0;                             //part number
            int k        = 0;                             //point number

            MapWinGIS.Shape LineShp = new MapWinGIS.Shape();
            MapWinGIS.Point curPoint;
            //Rasterization ras = new Rasterization(); //rasterization class, contains the code of
            //lineToGrid methods independent on MapWinGIS functions
            ArrayList vertices = new ArrayList(); //list of line vertex points
            ArrayList pixels   = new ArrayList(); //list of calculated pixels on the line
            GridPixel px;

            object val; //the shape's value


            for (s = 0; s < nShps; ++s)
            {
                LineShp   = LineSf.get_Shape(s);
                numParts  = LineShp.NumParts;
                numPoints = LineShp.numPoints;

                //exclude shapes which are completely outside of the grid extents
                if (!IsGridContainsShape(LineShp, header))
                {
                    continue;
                }

                //get the shape's value
                val = GetCellValue(LineSf, FldID, s, header.NodataValue);

                //process each part of the polyline
                curPartStart = 0;
                for (p = 0; p < numParts; ++p)
                {
                    vertices.Clear();
                    pixels.Clear();

                    curPartStart = LineShp.get_Part(p);

                    // check for multi-part lines
                    if (p < numParts - 1)
                    {
                        curPartEnd = LineShp.get_Part(p + 1) - 1;
                    }
                    else
                    {
                        curPartEnd = numPoints - 1;
                    }

                    //go to next part if there's zero points
                    if (numPoints <= 0)
                    {
                        continue;
                    }

                    // add all points of current part to rasterization list
                    // always add the first point of the part (convert its coordinates to
                    // grid row and column)
                    curPoint = LineShp.get_Point(curPartStart);
                    Newgrd.ProjToCell(curPoint.x, curPoint.y,
                                      out vertexCol, out vertexRow);
                    px.col = vertexCol;
                    px.row = vertexRow;
                    vertices.Add(px);
                    lastCol = vertexCol; lastRow = vertexRow;

                    // add all other points with different grid coordinates
                    for (k = curPartStart + 1; k <= curPartEnd; ++k)
                    {
                        // (check if it has a different row or column than the previous point)
                        curPoint = LineShp.get_Point(k);
                        Newgrd.ProjToCell(curPoint.x, curPoint.y,
                                          out vertexCol, out vertexRow);
                        if (vertexCol != lastCol || vertexRow != lastRow)
                        {
                            px.col = vertexCol;
                            px.row = vertexRow;
                            vertices.Add(px);
                            lastCol = vertexCol;
                            lastRow = vertexRow;
                        }
                    }

                    // convert the polyline and write pixels to grid
                    LineBresenham(vertices, pixels);
                    writePxList(Newgrd, grType, pixels, val, cback);
                }

                //report the progress
                if (s >= shpsPerc)
                {
                    reportProgress(shpsPerc, nShps, "shapefile to grid", cback);
                    perc     = (int)((s * 100) / nShps);
                    shpsPerc = NumPercentShapes(perc + 1, nShps);
                }
            }
            return(true);
        }
        /// <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;
                }
            }
        }