/// <summary> /// Import an SIT formatted dataset. /// mdb, accdb, xls, or xlsx are supported /// </summary> private static void Method1() { string excelPath = @"C:\Program Files (x86)\Operational-Scale CBM-CFS3\Tutorials\Tutorial 6\Tutorial6.xls"; string projectPath = @"C:\Program Files (x86)\Operational-Scale CBM-CFS3\Projects\tutorial6\tutorial6.mdb"; var data = Sitplugin.ParseSITData( path: excelPath, AgeClassTableName: "AgeClasses$", ClassifiersTableName: "Classifiers$", DisturbanceEventsTableName: "DistEvents$", DisturbanceTypesTableName: "DistType$", InventoryTableName: "Inventory$", TransitionRulesTableName: "Transitions$", YieldTableName: "Growth$"); Sitplugin sitplugin = new Sitplugin( outputPath: projectPath, initializeMapping: false, dataset: data); sitplugin.SetSingleSpatialUnit(42); //see archive index tblSPUDefault/tblAdminBoundaryDefault/tblEcoBoundaryDefault for code definitions sitplugin.SetSpeciesClassifier("Species");//the classifier name as defined in the spreadsheet sitplugin.SetNonForestClassifier("Forest type"); // in the following mappings, the left value is something that appears in the import data, // and the right value is something that appears in the archive index database. sitplugin.MapSpecies("Hispaniolan pine", "Pine"); sitplugin.MapSpecies("Nonforest", "Not stocked"); sitplugin.MapSpecies("Improved pine stock", "Pine"); sitplugin.MapNonForest("Afforestation", "Gleysolic"); sitplugin.MapNonForest("Natural forest", Sitplugin.ForestOnly); sitplugin.MapNonForest("Control", Sitplugin.ForestOnly); sitplugin.MapDisturbanceType("Fire", "Wildfire"); sitplugin.MapDisturbanceType("Firewood collection", "Firewood Collection - post logging"); sitplugin.MapDisturbanceType("Clearcut", "Clear-cut with slash-burn"); sitplugin.MapDisturbanceType("Afforestation", "Afforestation"); sitplugin.MapDisturbanceType("Hurricane", "Generic 50% mortality"); 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); }