コード例 #1
0
        //"Hispaniolan pine", "Pine");
        //"Nonforest", "Not stocked");
        //"Improved pine stock", "Pine");
        /// <summary>
        /// build up a dataset with code instead of import an SIT formatted dataset
        /// </summary>
        private static void Method2()
        {
            string projectPath = @"C:\Program Files (x86)\Operational-Scale CBM-CFS3\Projects\myproject\myproject.mdb";
            string dirname     = System.IO.Path.GetDirectoryName(projectPath);

            if (!System.IO.Directory.Exists(dirname))
            {
                System.IO.Directory.CreateDirectory(dirname);
            }
            //when initialize mapping is true, incoming sit
            //data must be named exactly as the definitions in the archive index
            Sitplugin sitplugin = new Sitplugin(
                outputPath: projectPath,
                initializeMapping: true);

            //define ten year age class size, with 20 values (200 years)
            int numAgeClasses = 20;

            sitplugin.AddAgeClasses(10, numAgeClasses);

            sitplugin.AddClassifier("admin");
            sitplugin.AddClassifier("eco");
            sitplugin.SetAdminEcoMapping("admin", "eco");

            sitplugin.AddClassifier("species");
            sitplugin.SetSpeciesClassifier("species");

            sitplugin.AddClassifier("group");

            sitplugin.AddInventory(
                classifierSet: "British Columbia,Pacific Maritime,Spruce,g1",//note exact naming is required when " initializeMapping: true"
                age: 100,
                area: 10,
                spatialReference: 100,
                HistoricDisturbance: "Wildfire",
                MostRecentDisturbance: "Clearcut harvesting with salvage");

            List <double> FakeGrowthCurve = Enumerable.Range(0, numAgeClasses)
                                            .Select(a => 200 / (1 + Math.Exp(-0.5 * (a - numAgeClasses / 2.0)))).ToList();

            sitplugin.AddYield(
                classifierSet: "British Columbia,Pacific Maritime,Spruce,?",
                leadingSpeciesClassifierValue: "Spruce",
                values: FakeGrowthCurve);

            sitplugin.AddDisturbanceEvent(
                classifierSet: "?,?,?,?",//when spatial reference is used, events do not use a classifier set
                disturbanceType: "Clearcut harvesting with salvage",
                timestep: 100,
                target: 5,
                targetType: "Area",
                spatialReference: 100);

            sitplugin.Import();
        }
コード例 #2
0
        private static void LoadConfigDataObjects(Sitplugin plugin, JToken dataConfig)
        {
            var parseClassifierSet = new Func <JToken, string>((t) =>
            {
                return(String.Join(",", t.Select(a => (string)a)));
            });

            foreach (var i in dataConfig["inventory"])
            {
                plugin.AddInventory(
                    classifierSet: parseClassifierSet(i["classifier_set"]),
                    area: (double)i["area"],
                    age: (int)i["age"],
                    spatialReference: Unpack(i, "spatial_reference", -1),
                    delay: Unpack(i, "delay", 0),
                    unfcccLandClass: Unpack(i, "unfccc_land_class", 0),
                    HistoricDisturbance: Unpack(i, "historic_disturbance", (string)null),
                    MostRecentDisturbance: Unpack(i, "last_pass_disturbance", (string)null));
            }

            foreach (var i in dataConfig["disturbance_events"])
            {
                plugin.AddDisturbanceEvent(
                    classifierSet: parseClassifierSet(i["classifier_set"]),
                    disturbanceType: (string)i["disturbance_type"],
                    timestep: (int)i["time_step"],
                    target: (double)i["target"],
                    targetType: (string)i["target_type"],
                    sort: (string)i["sort"],
                    spatialReference: Unpack(i, "spatial_reference", -1),
                    ageMin: Unpack(i, "age_min", -1),
                    ageMax: Unpack(i, "age_max", -1),
                    efficiency: Unpack(i, "efficiency", 1.0),
                    eligibility: i["eligibility"]?.Select(a => (double)a).ToArray());
            }

            foreach (var i in dataConfig["yield"])
            {
                plugin.AddYield(
                    classifierSet: parseClassifierSet(i["classifier_set"]),
                    leadingSpeciesClassifierValue: (string)i["leading_species_classifier_value"],
                    values: i["values"].Select(a => (double)a).ToList());
            }

            if (dataConfig["transition_rules"] != null)
            {
                foreach (var i in dataConfig["transition_rules"])
                {
                    plugin.AddTransitionRule(
                        classifierSetSource: parseClassifierSet(i["classifier_set_source"]),
                        classifierSetTarget: parseClassifierSet(i["classifier_set_target"]),
                        disturbanceType: (string)i["disturbance_type"],
                        percent: Unpack(i, "percent", 100.0),
                        spatialReference: Unpack(i, "spatial_reference", -1),
                        ageMin: Unpack(i, "age_min", -1),
                        ageMax: Unpack(i, "age_max", -1),
                        resetAge: Unpack(i, "reset_age", -1),
                        regenDelay: Unpack(i, "regen_delay", 0));
                }
            }
        }