Example #1
0
        public IList <IGridCellSpeciesObservationCount> GetSpeciesObservationGridCellResultFromWebService(IUserContext userContext, MySettings mySettings)
        {
            var speciesObservationSearchCriteriaManager     = new SpeciesObservationSearchCriteriaManager(userContext);
            SpeciesObservationSearchCriteria searchCriteria = speciesObservationSearchCriteriaManager.CreateSearchCriteria(mySettings);
            ICoordinateSystem coordinateSystem = new CoordinateSystem();

            coordinateSystem.Id = CoordinateSystemId.GoogleMercator;
            GridStatisticsSetting gridStatisticsSetting = mySettings.Calculation.GridStatistics;
            IGridSpecification    gridSpecification     = new GridSpecification();

            if (gridStatisticsSetting.CoordinateSystemId.HasValue)
            {
                gridSpecification.GridCoordinateSystem = (GridCoordinateSystem)gridStatisticsSetting.CoordinateSystemId;
            }
            else
            {
                gridSpecification.GridCoordinateSystem = GridCoordinateSystem.SWEREF99_TM;
            }

            if (gridStatisticsSetting.GridSize.HasValue)
            {
                gridSpecification.GridCellSize            = gridStatisticsSetting.GridSize.Value;
                gridSpecification.IsGridCellSizeSpecified = true;
            }
            IList <IGridCellSpeciesObservationCount> gridCellObservations = CoreData.AnalysisManager.GetGridSpeciesObservationCounts(userContext, searchCriteria, gridSpecification, coordinateSystem);

            // Add result to cache
            return(gridCellObservations);
        }
Example #2
0
        /// <summary>
        /// Calculates the species observation grid.
        /// </summary>
        /// <param name="taxonIds">The taxon ids.</param>
        /// <param name="gridCoordinateSystem">The grid coordinate system.</param>
        /// <returns>List of grid cells data.</returns>
        public IList <IGridCellSpeciesObservationCount> CalculateSpeciesObservationGrid(List <int> taxonIds, GridCoordinateSystem?gridCoordinateSystem)
        {
            var speciesObservationSearchCriteriaManager     = new SpeciesObservationSearchCriteriaManager(UserContext);
            SpeciesObservationSearchCriteria searchCriteria = speciesObservationSearchCriteriaManager.CreateSearchCriteria(MySettings);

            searchCriteria.TaxonIds = taxonIds;

            CoordinateSystem displayCoordinateSystem = MySettings.Presentation.Map.DisplayCoordinateSystem;
            //CoordinateSystem displayCoordinateSystem = new CoordinateSystem(MapSettings.CoordinateSystemId); // todo - såhär borde det se ut
            GridStatisticsSetting gridStatisticsSetting = MySettings.Calculation.GridStatistics;
            GridSpecification     gridSpecification     = new GridSpecification();

            if (gridCoordinateSystem.HasValue)
            {
                gridSpecification.GridCoordinateSystem = gridCoordinateSystem.Value;
            }
            else
            {
                if (gridStatisticsSetting.CoordinateSystemId.HasValue)
                {
                    gridSpecification.GridCoordinateSystem = (GridCoordinateSystem)gridStatisticsSetting.CoordinateSystemId;
                }
                else
                {
                    gridSpecification.GridCoordinateSystem = GridCoordinateSystem.SWEREF99_TM;
                }
            }

            if (gridStatisticsSetting.GridSize.HasValue)
            {
                gridSpecification.GridCellSize            = gridStatisticsSetting.GridSize.Value;
                gridSpecification.IsGridCellSizeSpecified = true;
            }

            gridSpecification.GridCellGeometryType = GridCellGeometryType.Polygon;

            // todo - implement check that the number of possible grid cells aren't too large.
            // todo - perhaps this check should be in the service
            ////long numberOfGridCellsThatWillBeGenerated = GisTools.GridCellManager.CalculateNumberOfGridCells(gridSpecification, searchCriteria.Polygons, searchCriteria.RegionGuids);
            ////if (numberOfGridCellsThatWillBeGenerated > MAX_NUMBER_OF_GRID_CELLS)
            ////{
            ////    throw new ArgumentException(string.Format("The cell size is too small, which would have resulted in possibly {0} grid cells. The limit lies at {1}.", numberOfGridCellsThatWillBeGenerated, MAX_NUMBER_OF_GRID_CELLS));
            ////}

            var gridCellObservations = CoreData.AnalysisManager.GetGridSpeciesObservationCounts(UserContext, searchCriteria, gridSpecification, displayCoordinateSystem);

            if (MySettings.Calculation.GridStatistics.GenerateAllGridCells)
            {
                gridCellObservations = AddEmptyGridCells(gridCellObservations, gridSpecification, displayCoordinateSystem);
                gridCellObservations = RemoveGridCellsOutsideBounds(gridCellObservations, gridSpecification);
            }

            gridCellObservations = gridCellObservations.OrderBy(x => x.Identifier).ToList();
            return(gridCellObservations);
        }
Example #3
0
        /// <summary>
        /// Calculates the species observation grid.
        /// </summary>
        /// <param name="taxonIds">The taxon ids.</param>
        /// <param name="gridCoordinateSystem">The grid coordinate system.</param>
        /// <param name="bottom"></param>
        /// <param name="left"></param>
        /// <param name="right"></param>
        /// <param name="top"></param>
        /// <param name="zoom"></param>
        /// <param name="gridSize"></param>
        /// <returns>List of grid cells data.</returns>
        public IList <IGridCellSpeciesObservationCount> CalculateSpeciesObservationGrid(List <int> taxonIds, GridCoordinateSystem?gridCoordinateSystem, double bottom, double left, double right, double top, int zoom, int?gridSize)
        {
            var speciesObservationSearchCriteriaManager     = new SpeciesObservationSearchCriteriaManager(UserContext);
            SpeciesObservationSearchCriteria searchCriteria = speciesObservationSearchCriteriaManager.CreateSearchCriteria(MySettings);

            // remove spatial filter?
            searchCriteria.Polygons    = null;
            searchCriteria.RegionGuids = null;
            searchCriteria.TaxonIds    = taxonIds;

            CoordinateSystem      displayCoordinateSystem = MySettings.Presentation.Map.DisplayCoordinateSystem;
            GridStatisticsSetting gridStatisticsSetting   = MySettings.Calculation.GridStatistics;
            GridSpecification     gridSpecification       = new GridSpecification();

            if (gridCoordinateSystem.HasValue)
            {
                gridSpecification.GridCoordinateSystem = gridCoordinateSystem.Value;
            }
            else
            {
                if (gridStatisticsSetting.CoordinateSystemId.HasValue)
                {
                    gridSpecification.GridCoordinateSystem = (GridCoordinateSystem)gridStatisticsSetting.CoordinateSystemId;
                }
                else
                {
                    gridSpecification.GridCoordinateSystem = GridCoordinateSystem.SWEREF99_TM;
                }
            }

            gridSpecification.GridCellSize            = gridSize.HasValue ? gridSize.Value : ZoomMappings[zoom];
            gridSpecification.IsGridCellSizeSpecified = true;
            gridSpecification.GridCellGeometryType    = GridCellGeometryType.Polygon;
            searchCriteria.Polygons = new List <IPolygon>();
            searchCriteria.Polygons.Add(GetPolygon(bottom, left, right, top));
            IList <IGridCellSpeciesObservationCount> gridCellObservations = CoreData.AnalysisManager.GetGridSpeciesObservationCounts(UserContext, searchCriteria, gridSpecification, displayCoordinateSystem);

            gridCellObservations = gridCellObservations.OrderBy(x => x.Identifier).ToList();
            return(gridCellObservations);
        }
        public void GridStatisticsSettingPropertyTest()
        {
            GridStatisticsSetting setting = new GridStatisticsSetting();

            setting.ResultCacheNeedsRefresh = false;

            //************ Check all settings at startup as designed *************************
            //These setting is active at startup
            Assert.IsTrue(setting.HasActiveSettings);
            Assert.IsTrue(setting.HasSettings);
            Assert.IsTrue(setting.IsActive);
            Assert.IsTrue(setting.CalculateNumberOfObservations);
            Assert.IsTrue(setting.CalculateNumberOfTaxa);
            CoordinateSystemId enumDisplayStatus = ((CoordinateSystemId)setting.CoordinateSystemId);
            string             stringValue       = enumDisplayStatus.ToString();

            Assert.IsTrue(stringValue.Equals(CoordinateSystemId.SWEREF99.ToString()));
            Assert.IsTrue(setting.GridSize == 10000);
            // This setting is default at start up, cash needs to be updated
            Assert.IsTrue(setting.IsSettingsDefault());
            Assert.IsFalse(setting.ResultCacheNeedsRefresh);

            //************ Update settings and test  *************************
            setting.CalculateNumberOfObservations = false;
            setting.CoordinateSystemId            = 2;
            setting.GridSize = 20000;

            Assert.IsTrue(setting.HasActiveSettings);
            Assert.IsTrue(setting.HasSettings);
            // These setting is active at startup
            Assert.IsTrue(setting.IsActive);
            Assert.IsFalse(setting.CalculateNumberOfObservations);
            Assert.IsTrue(setting.CalculateNumberOfTaxa);
            enumDisplayStatus = ((CoordinateSystemId)setting.CoordinateSystemId);
            stringValue       = enumDisplayStatus.ToString();
            Assert.IsTrue(stringValue.Equals(CoordinateSystemId.Rt90_25_gon_v.ToString()));
            Assert.IsTrue(setting.GridSize == 20000);
            // This setting is default at start up
            Assert.IsFalse(setting.IsSettingsDefault());
            Assert.IsTrue(setting.ResultCacheNeedsRefresh);

            // Set default values and check again
            setting.ResetSettings();
            Assert.IsTrue(setting.HasActiveSettings);
            Assert.IsTrue(setting.HasSettings);
            Assert.IsTrue(setting.IsActive);
            Assert.IsTrue(setting.CalculateNumberOfObservations);
            Assert.IsTrue(setting.CalculateNumberOfTaxa);
            Assert.IsTrue(setting.IsSettingsDefault());
            Assert.IsTrue(setting.ResultCacheNeedsRefresh);
            enumDisplayStatus = ((CoordinateSystemId)setting.CoordinateSystemId);
            stringValue       = enumDisplayStatus.ToString();
            Assert.IsTrue(stringValue.Equals(CoordinateSystemId.SWEREF99.ToString()));
            Assert.IsTrue(setting.GridSize == 10000);
            // Now we change CalculateNumberOfSpeciesfromObsData setting
            setting.CalculateNumberOfTaxa = false;
            setting.GridSize = 50000;

            Assert.IsTrue(setting.HasActiveSettings);
            Assert.IsTrue(setting.HasSettings);
            // These setting is active at startup
            Assert.IsTrue(setting.IsActive);
            Assert.IsTrue(setting.CalculateNumberOfObservations);
            Assert.IsFalse(setting.CalculateNumberOfTaxa);
            enumDisplayStatus = ((CoordinateSystemId)setting.CoordinateSystemId);
            stringValue       = enumDisplayStatus.ToString();
            Assert.IsTrue(stringValue.Equals(CoordinateSystemId.SWEREF99.ToString()));
            Assert.IsTrue(setting.GridSize == 50000);
            // This setting is not default and cash needs to be updated
            Assert.IsFalse(setting.IsSettingsDefault());
            Assert.IsTrue(setting.ResultCacheNeedsRefresh);

            // Set default values
            setting.ResetSettings();
            // Now we change CalculateNumberOfSpeciesfromObsData and CalculateNumberOfObservationsfromObsData setting
            setting.CalculateNumberOfObservations = false;
            setting.CalculateNumberOfTaxa         = false;
            setting.GridSize           = 0;
            setting.CoordinateSystemId = 0;
            // TODO GridStatistics settings are always true
            //Assert.IsFalse(setting.HasActiveSettings);
            //Assert.IsFalse(setting.HasSettings);
            //// These setting is active at startup
            //Assert.IsTrue(setting.IsActive);
            Assert.IsFalse(setting.CalculateNumberOfObservations);
            Assert.IsFalse(setting.CalculateNumberOfTaxa);
            enumDisplayStatus = ((CoordinateSystemId)setting.CoordinateSystemId);
            stringValue       = enumDisplayStatus.ToString();
            Assert.IsTrue(stringValue.Equals(CoordinateSystemId.None.ToString()));
            Assert.IsTrue(setting.GridSize == 0);
            // This setting is not default and cash needs to be updated
            Assert.IsFalse(setting.IsSettingsDefault());
            Assert.IsTrue(setting.ResultCacheNeedsRefresh);

            // Set default values
            setting.ResetSettings();
            //Set this setting not to be active
            setting.IsActive = false;
            Assert.IsFalse(setting.HasActiveSettings);
            Assert.IsTrue(setting.HasSettings);
            // These setting is active at startup
            Assert.IsFalse(setting.IsActive);
            Assert.IsTrue(setting.CalculateNumberOfObservations);
            Assert.IsTrue(setting.CalculateNumberOfTaxa);
            enumDisplayStatus = ((CoordinateSystemId)setting.CoordinateSystemId);
            stringValue       = enumDisplayStatus.ToString();
            Assert.IsTrue(stringValue.Equals(CoordinateSystemId.SWEREF99.ToString()));
            Assert.IsTrue(setting.GridSize == 10000);
            // This setting is default at start up and no cash needs to be updated
            Assert.IsTrue(setting.IsSettingsDefault());
            Assert.IsTrue(setting.ResultCacheNeedsRefresh);

            setting = new GridStatisticsSetting();
            setting.ResultCacheNeedsRefresh = false;
            //Set alreday existing value and check that cash in not needed to be updated
            setting.CalculateNumberOfTaxa = true;
            Assert.IsTrue(setting.IsSettingsDefault());
            // TODO not required to always update cash ...Assert.IsFalse(setting.ResultCacheNeedsRefresh);
        }