Exemple #1
0
        private IList <IGridCellSpeciesObservationCount> AddEmptyGridCells(IList <IGridCellSpeciesObservationCount> gridCellObservations, GridSpecification gridSpecification, ICoordinateSystem displayCoordinateSystem)
        {
            long numberOfGridCellsThatWillBeGenerated = GisTools.GridCellManager.CalculateNumberOfGridCells(gridSpecification);

            if (numberOfGridCellsThatWillBeGenerated > MAX_NUMBER_OF_GRID_CELLS)
            {
                throw new ArgumentException(string.Format("The cell size is too small, which would have resulted in the {0} grid cells. The limit lies at {1}.", numberOfGridCellsThatWillBeGenerated, MAX_NUMBER_OF_GRID_CELLS));
            }

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

            List <GridCellBase>  allGridCells     = GisTools.GridCellManager.GenerateGrid(gridSpecification, displayCoordinateSystem);
            List <IGridCellBase> dataGridCells    = gridCellObservations.Cast <IGridCellBase>().ToList();
            List <IGridCellBase> missingGridCells = GisTools.GridCellManager.GetMissingGridCells(allGridCells.Cast <IGridCellBase>().ToList(), dataGridCells);

            foreach (IGridCellBase missingGridCell in missingGridCells)
            {
                GridCellSpeciesObservationCount gridCellSpeciesObservationCount = new GridCellSpeciesObservationCount();
                gridCellSpeciesObservationCount.ObservationCount = 0;
                missingGridCell.CopyPropertiesTo(gridCellSpeciesObservationCount);
                gridCellObservations.Add(gridCellSpeciesObservationCount);
            }

            return(gridCellObservations);
        }
Exemple #2
0
        public string GetSpeciesObservationAOOEOOAsGeoJson(int?alphaValue = null, bool useCenterPoint = false)
        {
            var gridResult = GetSpeciesObservationGridResultFromCacheIfAvailableOrElseCalculate();

            if (gridResult == null)
            {
                return(null);
            }

            //Convert SpeciesObservationGridResult to List<IGridCellSpeciesObservationCount>
            //Todo Cache List<IGridCellSpeciesObservationCount> from service and not SpeciesObservationGridResult var gridCellsc = CalculateSpeciesObservationGrid();
            var gridCells = new List <IGridCellSpeciesObservationCount>();

            foreach (var sourceCell in gridResult.Cells)
            {
                var targetCell = new GridCellSpeciesObservationCount();

                if (sourceCell.BoundingBox != null)
                {
                    var linearRing = new LinearRing()
                    {
                        Points = new DataId32List <IPoint>()
                    };

                    foreach (var point in sourceCell.BoundingBox)
                    {
                        linearRing.Points.Add(new Data.Point(point[0], point[1]));
                    }
                    var firstPoint = sourceCell.BoundingBox[0]; //Add first point to close ring
                    linearRing.Points.Add(new Data.Point(firstPoint[0], firstPoint[1]));

                    var boundingBoxPolygon = new Data.Polygon()
                    {
                        LinearRings = new DataId32List <ILinearRing>()
                    };
                    boundingBoxPolygon.LinearRings.Add(linearRing);
                    targetCell.GridCellBoundingBox = boundingBoxPolygon;
                }

                if (sourceCell.OriginalBoundingBox != null && sourceCell.OriginalBoundingBox.Length == 4)
                {
                    targetCell.OrginalGridCellBoundingBox = new Data.BoundingBox
                    {
                        Min = new Data.Point(sourceCell.OriginalBoundingBox[0, 0], sourceCell.OriginalBoundingBox[0, 1]),
                        Max = new Data.Point(sourceCell.OriginalBoundingBox[1, 0], sourceCell.OriginalBoundingBox[1, 1])
                    };
                }

                if (sourceCell.CentreCoordinate != null)
                {
                    targetCell.GridCellCentreCoordinate = new Data.Point(sourceCell.CentreCoordinateX, sourceCell.CentreCoordinateY);
                }
                targetCell.OrginalGridCellCentreCoordinate = new Data.Point(sourceCell.OriginalCentreCoordinateX, sourceCell.OriginalCentreCoordinateY);
                targetCell.ObservationCount     = sourceCell.ObservationCount;
                targetCell.GridCellSize         = sourceCell.GridCellSize;
                targetCell.CoordinateSystem     = MySettings.Presentation.Map.DisplayCoordinateSystem;
                targetCell.GridCoordinateSystem = sourceCell.Srid.ToGridCoordinateSystem();

                gridCells.Add(targetCell);
            }

            return(CoreData.AnalysisManager.GetSpeciesObservationAOOEOOAsGeoJson(UserContext, gridCells, alphaValue ?? 0, useCenterPoint));
        }