//"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(); }
public Sitplugin Load(string json) { Sitplugin sitplugin = null; JObject obj = JObject.Parse(json); string outputPath = System.IO.Path.GetFullPath((string)obj["output_path"]); string archive_index_db_path = null; if (obj["archive_index_db_path"] != null) { archive_index_db_path = System.IO.Path.GetFullPath((string)obj["archive_index_db_path"]); } var mappingConfig = obj["mapping_config"]; if (mappingConfig == null) { throw new Exception("missing mapping_config section"); } bool initialize_mapping = mappingConfig["initialize_mapping"] == null ? false : (bool)mappingConfig["initialize_mapping"]; CBMSIT.UserData.UserDataSet userData = null; if (obj["import_config"] != null) { var importConfig = obj["import_config"]; if (importConfig["path"] != null) { userData = Sitplugin.ParseSITData( path: System.IO.Path.GetFullPath((string)importConfig["path"]), AgeClassTableName: (string)importConfig["ageclass_table_name"], ClassifiersTableName: (string)importConfig["classifiers_table_name"], DisturbanceEventsTableName: (string)importConfig["disturbance_events_table_name"], DisturbanceTypesTableName: (string)importConfig["disturbance_types_table_name"], InventoryTableName: (string)importConfig["inventory_table_name"], TransitionRulesTableName: (string)importConfig["transition_rules_table_name"], YieldTableName: (string)importConfig["yield_table_name"]); } else if (importConfig["ageclass_path"] != null) { userData = Sitplugin.ParseSITDataText( ageClassPath: System.IO.Path.GetFullPath((string)importConfig["ageclass_path"]), classifiersPath: System.IO.Path.GetFullPath((string)importConfig["classifiers_path"]), disturbanceEventsPath: System.IO.Path.GetFullPath((string)importConfig["disturbance_events_path"]), disturbanceTypesPath: System.IO.Path.GetFullPath((string)importConfig["disturbance_types_path"]), inventoryPath: System.IO.Path.GetFullPath((string)importConfig["inventory_path"]), transitionRulesPath: System.IO.Path.GetFullPath((string)importConfig["transition_rules_path"]), yieldPath: System.IO.Path.GetFullPath((string)importConfig["yield_path"])); } else { throw new Exception("error in import_config section"); } sitplugin = new Sitplugin(outputPath, initialize_mapping, userData, archive_index_database_path: archive_index_db_path); MapSpatialUnits(sitplugin, mappingConfig["spatial_units"]); MapSpecies(sitplugin, mappingConfig["species"]); MapNonForest(sitplugin, mappingConfig["nonforest"]); MapDisturbanceTypes(sitplugin, mappingConfig["disturbance_types"]); } else if (obj["data"] != null) { sitplugin = new Sitplugin(outputPath, initialize_mapping, archive_index_database_path: archive_index_db_path); sitplugin.AddAgeClasses( (int)obj["data"]["age_class"]["age_class_size"], (int)obj["data"]["age_class"]["num_age_classes"]); foreach (var c in obj["data"]["classifiers"]) { sitplugin.AddClassifier((string)c); } MapSpatialUnits(sitplugin, mappingConfig["spatial_units"]); MapSpecies(sitplugin, mappingConfig["species"]); MapNonForest(sitplugin, mappingConfig["nonforest"]); MapDisturbanceTypes(sitplugin, mappingConfig["disturbance_types"]); LoadConfigDataObjects(sitplugin, obj["data"]); } else { throw new Exception("expected one of 'import_config', or 'data' in configuration"); } return(sitplugin); }