示例#1
0
        public string getSppComp(List <TREE> list)
        // for calculating a species string for a set of trees
        {
            List <SpeciesList> _spplist = new List <SpeciesList>();
            bool   added = false;
            double batot = 0;

            foreach (var tree in list)
            {
                if (tree.TREESTATUSCODE == "L" || tree.TREESTATUSCODE == "V")
                {
                    var ba = Math.Pow(tree.DBH, 2) * Math.PI;
                    foreach (var itm in _spplist)
                    {
                        if (itm.spp == tree.SPECIESCODE)
                        {
                            itm.BA = itm.BA + ba;
                            batot  = batot + ba;
                            added  = true;
                        }
                    }
                    if (!added)
                    {
                        _spplist.Add(new SpeciesList()
                        {
                            spp = tree.SPECIESCODE, BA = ba
                        });
                        batot = batot + ba;
                        added = false;
                    }
                    added = false;
                }
            }
            // now that list of species is made, sort it, and build a species string
            string             sppcomp      = "";
            List <SpeciesList> _spplistsort = _spplist.OrderByDescending(x => x.BA).ToList();
            List <PickerItems> _masterlist  = PickerService.SpeciesMaster().ToList();

            if (batot > 0)
            {
                foreach (var itm in _spplistsort)
                {
                    if (!UseAlphaSpecies)
                    {
                        sppcomp = sppcomp + itm.spp.ToString() + " " + (Math.Round((itm.BA / batot) * 100)).ToString() + "% ";
                    }
                    else
                    {
                        sppcomp = sppcomp + PickerService.GetValue(_masterlist, itm.spp) + " " + (Math.Round((itm.BA / batot) * 100)).ToString() + "% ";
                    }
                }
            }

            return(sppcomp);
        }