Esempio n. 1
0
        /// <summary>
        /// Calculates species observation count per polygon and taxa.
        /// </summary>
        /// <param name="taxonIds">The taxon ids.</param>
        /// <returns>
        /// A dictionary where the key is a polygon description.
        /// The value is a dictionary where the key is TaxonId and the value is species observation count.
        /// </returns>
        public TaxonSpecificSpeciesObservationCountPerPolygonResult CalculateSpeciesObservationCountPerPolygonAndTaxa(List <int> taxonIds)
        {
            Dictionary <string, Dictionary <int, long> > speciesObservationData = new Dictionary <string, Dictionary <int, long> >();
            FeatureCollection featureCollection = GetFeatureCollection();
            List <int>        taxonIdList       = new List <int>(taxonIds);

            if (taxonIdList.IsEmpty())
            {
                taxonIdList.Add(0);
            }

            if (MySettings.Calculation.SummaryStatistics.WfsSummaryStatisticsLayerId.HasValue &&
                featureCollection != null && featureCollection.Features.Count > 0)
            {
                SpeciesObservationSearchCriteriaManager searchCriteriaManager =
                    new SpeciesObservationSearchCriteriaManager(UserContext);
                SpeciesObservationSearchCriteria searchCriteria = searchCriteriaManager.CreateSearchCriteria(MySettings);
                DataContext      dataContext             = new DataContext(UserContext);
                CoordinateSystem displayCoordinateSystem = MySettings.Presentation.Map.DisplayCoordinateSystem;

                foreach (Feature feature in featureCollection.Features)
                {
                    string             featureDescription = GetFeatureDescription(feature);
                    List <DataPolygon> dataPolygons       = GetDataPolygons(feature);
                    searchCriteria.Polygons = dataPolygons.ToPolygons(dataContext);

                    foreach (int taxonId in taxonIdList)
                    {
                        searchCriteria.TaxonIds = new List <int>();
                        searchCriteria.TaxonIds.Add(taxonId);

                        long speciesObservationCount = CoreData.AnalysisManager.GetSpeciesObservationCountBySearchCriteria(UserContext, searchCriteria, displayCoordinateSystem);
                        if (!speciesObservationData.ContainsKey(featureDescription))
                        {
                            speciesObservationData.Add(featureDescription, new Dictionary <int, long>());
                        }

                        speciesObservationData[featureDescription].Add(taxonId, speciesObservationCount);
                    }
                }
            }

            TaxonList             taxonList = CoreData.TaxonManager.GetTaxa(UserContext, taxonIdList);
            List <TaxonViewModel> taxaList  = taxonList.GetGenericList().ToTaxonViewModelList();
            TaxonSpecificSpeciesObservationCountPerPolygonResult result = new TaxonSpecificSpeciesObservationCountPerPolygonResult()
            {
                Taxa = taxaList,
                SpeciesObservationCountPerPolygon = speciesObservationData
            };

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Adds the headers.
        /// </summary>
        /// <param name="worksheet">The worksheet.</param>
        private void AddHeaders(ExcelWorksheet worksheet, TaxonSpecificSpeciesObservationCountPerPolygonResult data)
        {
            var columnIndex = 2;

            //Add row with column headers
            worksheet.Cells[1, 1].Value = "Polygon";

            foreach (var taxon in data.Taxa)
            {
                worksheet.Cells[1, columnIndex].Value = string.Format("{0} (TaxonId {1})", taxon.ScientificName, taxon.TaxonId);
                columnIndex++;
            }
        }
Esempio n. 3
0
        private void AddSpeciesObservationsData(ExcelWorksheet worksheet, TaxonSpecificSpeciesObservationCountPerPolygonResult data)
        {
            var columnIndex    = 1;
            var rowIndex       = 2;
            var maxColumnIndex = data.Taxa.Count + 1;

            // Data values
            foreach (var pair in data.SpeciesObservationCountPerPolygon)
            {
                worksheet.Cells[rowIndex, columnIndex].Value = pair.Key.Replace("<br />", "\n");
                columnIndex++;

                foreach (var taxon in data.Taxa)
                {
                    long speciesObservationCount = 0;
                    pair.Value.TryGetValue(taxon.TaxonId, out speciesObservationCount);

                    if (FormatCountAsOccurrence)
                    {
                        int binaryVal = speciesObservationCount > 0 ? 1 : 0;
                        worksheet.Cells[rowIndex, columnIndex].Value = binaryVal;
                    }
                    else
                    {
                        worksheet.Cells[rowIndex, columnIndex].Value = speciesObservationCount;
                    }
                    columnIndex++;
                }

                columnIndex = 1;
                rowIndex++;
            }

            // Format style from second row to last row
            using (var range = worksheet.Cells[2, 1, rowIndex, maxColumnIndex])
            {
                range.Style.WrapText = true;
            }
        }