/// <summary>
        /// Generates grid cells according to the gridSpecification.
        /// </summary>
        /// <param name="gridSpecification">The grid specification.</param>
        /// <param name="displayCoordinateSystem">The display coordinate system.</param>
        /// <returns>A list of grid cells according to the grid specification.</returns>
        public List <GridCellBase> GenerateGrid(GridSpecification gridSpecification, ICoordinateSystem displayCoordinateSystem)
        {
            if (gridSpecification.GridCellSize <= 0)
            {
                throw new ArgumentException("GridCellSize must be greater than 0.");
            }

            List <GridCellBase> gridCells = new List <GridCellBase>();

            IBoundingBox boundingBox = gridSpecification.BoundingBox;

            if (boundingBox == null)
            {
                boundingBox = SwedenExtentManager.GetSwedenExtentBoundingBox(gridSpecification.GridCoordinateSystem.ToCoordinateSystem());
            }

            double xMin, yMin, xMax, yMax;
            int    cellSize;

            cellSize = gridSpecification.GridCellSize;

            xMin = Math.Floor(boundingBox.Min.X / cellSize) * cellSize;
            xMax = Math.Ceiling(boundingBox.Max.X / cellSize) * cellSize;
            yMin = Math.Floor(boundingBox.Min.Y / cellSize) * cellSize;
            yMax = Math.Ceiling(boundingBox.Max.Y / cellSize) * cellSize;

            ICoordinateSystem fromCoordinateSystem = gridSpecification.GridCoordinateSystem.ToCoordinateSystem();
            ICoordinateSystem toCoordinateSystem   = displayCoordinateSystem;

            // The last grid cell may exceed the boundary box.
            while (xMin < xMax)
            {
                // The last grid cell may exceed the boundary box.
                while (yMin < yMax)
                {
                    GridCellBase gridCell = new GridCellBase();
                    gridCell.GridCoordinateSystem            = gridSpecification.GridCoordinateSystem;
                    gridCell.GridCellSize                    = gridSpecification.GridCellSize;
                    gridCell.OrginalGridCellBoundingBox      = new BoundingBox();
                    gridCell.OrginalGridCellBoundingBox.Min  = new Point(xMin, yMin);
                    gridCell.OrginalGridCellBoundingBox.Max  = new Point(xMin + cellSize, yMin + cellSize);
                    gridCell.OrginalGridCellCentreCoordinate = new Point(Math.Floor(xMin / cellSize) * cellSize + cellSize * 0.5, Math.Floor(yMin / cellSize) * cellSize + cellSize * 0.5);

                    gridCell.GridCellBoundingBox      = GisTools.CoordinateConversionManager.GetConvertedBoundingBox(gridCell.OrginalGridCellBoundingBox, fromCoordinateSystem, toCoordinateSystem);
                    gridCell.CoordinateSystem         = displayCoordinateSystem;
                    gridCell.GridCellCentreCoordinate = GisTools.CoordinateConversionManager.GetConvertedPoint(gridCell.OrginalGridCellCentreCoordinate, fromCoordinateSystem, toCoordinateSystem);

                    gridCells.Add(gridCell);
                    yMin = yMin + cellSize;
                }

                xMin = xMin + cellSize;
                yMin = Math.Floor(boundingBox.Min.Y / cellSize) * cellSize;
            }

            return(gridCells);
        }
示例#2
0
        /// <summary>
        /// Adds a grid result for a specific taxon to a total result.
        /// </summary>
        /// <param name="taxonId">The taxon id.</param>
        /// <param name="taxonResult">The taxon result.</param>
        /// <param name="totalResult">The total result.</param>
        private void AddTaxonResult(
            int taxonId,
            IList <IGridCellSpeciesObservationCount> taxonResult,
            Dictionary <IGridCellBase, Dictionary <int, IGridCellSpeciesObservationCount> > totalResult)
        {
            foreach (IGridCellSpeciesObservationCount gridCell in taxonResult)
            {
                if (!totalResult.ContainsKey(gridCell))
                {
                    var newGridCell = new GridCellBase();
                    gridCell.CopyPropertiesTo(newGridCell);
                    totalResult.Add(newGridCell, new Dictionary <int, IGridCellSpeciesObservationCount>());
                }

                totalResult[gridCell].Add(taxonId, gridCell);
            }
        }