示例#1
0
        private void LoadForest()
        {
            var directory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

            var lines = File.ReadAllLines(System.IO.Path.Combine(directory, "Data.csv"));

            string[] ids = new[] { "Abie.bals", "Acer.rubr", "Acer.sacc", "Betu.papy", "Popu.gran", "Popu.trem", "Quer.rubr", "Tili.amer" };

            int index = 0;

            foreach (var line in lines)
            {
                var strValues = line.Split(',');

                double basalRadius = Parse(strValues[0]);
                double crownRadius = Parse(strValues[1]);
                double crownHeight = Parse(strValues[2]);
                double treeHeight  = Parse(strValues[3]);
                // skipping y
                double x = Parse(strValues[5]);
                // skipping id
                string speciesID = strValues[7];
                if (speciesID == "")
                {
                    speciesID = ids[index % 8];
                }

                ForestItem forestItem = new ForestItem
                {
                    TrunkWidth  = 2 * basalRadius,
                    TreeHeight  = treeHeight,
                    CrownHeight = crownHeight,
                    CrownWidth  = 2 * crownRadius,
                    SpeciesID   = speciesID,
                    X           = x
                };

                forest.Add(forestItem);
                index++;
            }
        }
示例#2
0
        private void LoadForest()
        {
            var lines = File.ReadAllLines(@"..\..\Data.csv");

            string[] ids = new[] { "Abie.bals", "Acer.rubr", "Acer.sacc", "Betu.papy", "Popu.gran", "Popu.trem", "Quer.rubr", "Tili.amer" };

            int index = 0;

            foreach (var line in lines)
            {
                var strValues = line.Split(',');

                double basalRadius = Parse(strValues[0]);
                double crownRadius = Parse(strValues[1]);
                double crownHeight = Parse(strValues[2]);
                double treeHeight  = Parse(strValues[3]);
                // skipping y
                double x = Parse(strValues[5]);
                // skipping id
                string speciesID = strValues[7];
                if (speciesID == "")
                {
                    speciesID = ids[index % 8];
                }

                ForestItem forestItem = new ForestItem
                {
                    TrunkWidth  = 2 * basalRadius,
                    TreeHeight  = treeHeight,
                    CrownHeight = crownHeight,
                    CrownWidth  = 2 * crownRadius,
                    SpeciesID   = speciesID,
                    X           = x
                };

                forest.Add(forestItem);
                index++;
            }
        }