private static void AddChartTransitionVariables(SyncroSimLayoutItemCollection items, Project project) { string AmountLabel = null; string UnitsLabel = null; TerminologyUnit TermUnit = 0; DataSheet dsterm = project.GetDataSheet(Strings.DATASHEET_TERMINOLOGY_NAME); TerminologyUtilities.GetAmountLabelTerminology(dsterm, ref AmountLabel, ref TermUnit); UnitsLabel = TerminologyUtilities.TerminologyUnitToString(TermUnit); string disp = string.Format(CultureInfo.InvariantCulture, "{0} ({1})", AmountLabel, UnitsLabel); SyncroSimLayoutItem Normal = new SyncroSimLayoutItem(Strings.TRANSITION_AMOUNT_VARIABLE_NAME, disp, false); SyncroSimLayoutItem Proportion = new SyncroSimLayoutItem(Strings.TRANSITION_PROPORTION_VARIABLE_NAME, "Proportion", false); Normal.Properties.Add(new MetaDataProperty("dataSheet", "stsim_OutputStratumTransition")); Proportion.Properties.Add(new MetaDataProperty("dataSheet", "stsim_OutputStratumTransition")); Normal.Properties.Add(new MetaDataProperty("column", "Amount")); Proportion.Properties.Add(new MetaDataProperty("column", "Amount")); Normal.Properties.Add(new MetaDataProperty("skipTimestepZero", "True")); Proportion.Properties.Add(new MetaDataProperty("skipTimestepZero", "True")); Normal.Properties.Add(new MetaDataProperty("defaultValue", "0.0")); Proportion.Properties.Add(new MetaDataProperty("defaultValue", "0.0")); items.Add(Normal); items.Add(Proportion); }
private ExportColumnCollection CreateColumnCollection() { ExportColumnCollection c = new ExportColumnCollection(); string AmountLabel = null; string UnitsLabel = null; TerminologyUnit TermUnit = 0; string PrimaryStratumLabel = null; string SecondaryStratumLabel = null; string TertiaryStratumLabel = null; DataSheet dsterm = this.Project.GetDataSheet(Strings.DATASHEET_TERMINOLOGY_NAME); string TimestepLabel = TerminologyUtilities.GetTimestepUnits(this.Project); TerminologyUtilities.GetAmountLabelTerminology(dsterm, ref AmountLabel, ref TermUnit); TerminologyUtilities.GetStratumLabelTerminology(dsterm, ref PrimaryStratumLabel, ref SecondaryStratumLabel, ref TertiaryStratumLabel); UnitsLabel = TerminologyUtilities.TerminologyUnitToString(TermUnit); string AmountTitle = string.Format(CultureInfo.InvariantCulture, "{0} ({1})", AmountLabel, UnitsLabel); c.Add(new ExportColumn("ScenarioID", "Scenario ID")); c.Add(new ExportColumn("ScenarioName", "Scenario")); c.Add(new ExportColumn("Iteration", "Iteration")); c.Add(new ExportColumn("Timestep", TimestepLabel)); c.Add(new ExportColumn("Stratum", PrimaryStratumLabel)); c.Add(new ExportColumn("SecondaryStratum", SecondaryStratumLabel)); c.Add(new ExportColumn("TertiaryStratum", TertiaryStratumLabel)); c.Add(new ExportColumn("StateClass", "State Class")); c.Add(new ExportColumn("AgeMin", "Age Min")); c.Add(new ExportColumn("AgeMax", "Age Max")); c.Add(new ExportColumn("Amount", AmountTitle)); c["Amount"].DecimalPlaces = 2; c["Amount"].Alignment = ColumnAlignment.Right; return(c); }
private void RefreshCalculatedValues() { DataRow drProp = this.DataFeed.GetDataSheet(Strings.DATASHEET_SPPIC_NAME).GetDataRow(); if (drProp == null) { return; } //Num Cells int NumCells = DataTableUtilities.GetDataInt(drProp[Strings.DATASHEET_SPPIC_NUM_CELLS_COLUMN_NAME]); this.TextBoxNumCells.Text = NumCells.ToString(CultureInfo.InvariantCulture); //Get the units and refresh the units labels - the default Raster Cell Units is Metres^2 string srcSizeUnits = DataTableUtilities.GetDataStr(drProp[Strings.DATASHEET_SPPIC_CELL_SIZE_UNITS_COLUMN_NAME]); string srcAreaUnits = srcSizeUnits + "^2"; string amountlabel = null; TerminologyUnit destUnitsVal = 0; TerminologyUtilities.GetAmountLabelTerminology( this.Project.GetDataSheet(Strings.DATASHEET_TERMINOLOGY_NAME), ref amountlabel, ref destUnitsVal); string destAreaLbl = TerminologyUtilities.TerminologyUnitToString(destUnitsVal); srcAreaUnits = srcAreaUnits.ToLower(CultureInfo.InvariantCulture); amountlabel = amountlabel.ToLower(CultureInfo.InvariantCulture); destAreaLbl = destAreaLbl.ToLower(CultureInfo.InvariantCulture); this.LabelRasterCellArea.Text = string.Format(CultureInfo.InvariantCulture, "Cell size ({0}):", srcAreaUnits); this.LabelCalcCellArea.Text = string.Format(CultureInfo.InvariantCulture, "Cell size ({0}):", destAreaLbl); this.LabelCalcTtlAmount.Text = string.Format(CultureInfo.InvariantCulture, "Total {0} ({1}):", amountlabel, destAreaLbl); // Calculate Cell Area in raster's native units float cellSize = DataTableUtilities.GetDataSingle(drProp[Strings.DATASHEET_SPPIC_CELL_SIZE_COLUMN_NAME]); double cellArea = Math.Pow(cellSize, 2); this.TextBoxCellArea.Text = cellArea.ToString("N4", CultureInfo.InvariantCulture); // Calc Cell Area in terminology units double cellAreaTU = 0; if (!CheckBoxCellSizeOverride.Checked) { cellAreaTU = InitialConditionsSpatialDataSheet.CalcCellArea(cellArea, srcSizeUnits, destUnitsVal); this.TextBoxCellAreaCalc.Text = cellAreaTU.ToString("N4", CultureInfo.InvariantCulture); drProp[Strings.DATASHEET_SPPIC_CELL_AREA_COLUMN_NAME] = cellAreaTU; TextBoxCellAreaCalc.ReadOnly = true; } else { cellAreaTU = DataTableUtilities.GetDataDbl(drProp[Strings.DATASHEET_SPPIC_CELL_AREA_COLUMN_NAME]); TextBoxCellAreaCalc.ReadOnly = false; } // Now calculate total area in the specified terminology units var ttlArea = cellAreaTU * NumCells; this.TextBoxTotalArea.Text = ttlArea.ToString("N4", CultureInfo.InvariantCulture); }
internal void InternalExport(string location, ExportType exportType, bool showMessage) { string AmountLabel = null; TerminologyUnit TermUnit = 0; DataSheet dsterm = this.Project.GetDataSheet(Strings.DATASHEET_TERMINOLOGY_NAME); ExportColumnCollection columns = this.CreateColumnCollection(); TerminologyUtilities.GetAmountLabelTerminology(dsterm, ref AmountLabel, ref TermUnit); string WorksheetName = string.Format(CultureInfo.InvariantCulture, "{0} by Transition and State", AmountLabel); if (exportType == ExportType.ExcelFile) { this.ExcelExport(location, columns, this.CreateReportQuery(false), WorksheetName); } else { columns.Remove("ScenarioName"); this.CSVExport(location, columns, this.CreateReportQuery(true)); if (showMessage) { FormsUtilities.InformationMessageBox("Data saved to '{0}'.", location); } } }
/// <summary> /// Gets the amount label terminology /// </summary> /// <param name="store"></param> /// <param name="terminologyDataSheet"></param> /// <param name="amountLabel"></param> /// <param name="amountUnits"></param> /// <remarks></remarks> public static void GetAmountLabelTerminology( DataSheet terminologyDataSheet, ref string amountLabel, ref TerminologyUnit amountUnits) { DataRow dr = terminologyDataSheet.GetDataRow(); amountLabel = "Amount"; amountUnits = TerminologyUnit.None; if (dr != null) { if (dr[Strings.DATASHEET_TERMINOLOGY_AMOUNT_LABEL_COLUMN_NAME] != DBNull.Value) { amountLabel = Convert.ToString( dr[Strings.DATASHEET_TERMINOLOGY_AMOUNT_LABEL_COLUMN_NAME], CultureInfo.InvariantCulture); } if (dr[Strings.DATASHEET_TERMINOLOGY_AMOUNT_UNITS_COLUMN_NAME] != DBNull.Value) { int value = Convert.ToInt32( dr[Strings.DATASHEET_TERMINOLOGY_AMOUNT_UNITS_COLUMN_NAME], CultureInfo.InvariantCulture); amountUnits = (TerminologyUnit)value; } } }
/// <summary> /// Converts a terminology unit to its corresponding string /// </summary> /// <param name="unit"></param> /// <returns></returns> /// <remarks></remarks> public static string TerminologyUnitToString(TerminologyUnit unit) { if (unit == TerminologyUnit.Acres) { return("Acres"); } else if (unit == TerminologyUnit.Hectares) { return("Hectares"); } else if (unit == TerminologyUnit.SquareKilometers) { return("Square Kilometers"); } else if (unit == TerminologyUnit.SquareMiles) { return("Square Miles"); } else if (unit == TerminologyUnit.None) { return("None"); } Debug.Assert(false); return(null); }
private void CreateExcelReport(string fileName) { string AmountLabel = null; TerminologyUnit AmountLabelUnits = 0; string ReportQuery = CreateReportQuery(false); DataTable ReportData = this.GetDataTableForReport(ReportQuery); DataSheet dsterm = this.Project.GetDataSheet(Strings.DATASHEET_TERMINOLOGY_NAME); TerminologyUtilities.GetAmountLabelTerminology(dsterm, ref AmountLabel, ref AmountLabelUnits); string WorksheetName = string.Format(CultureInfo.InvariantCulture, "{0} by State Class", AmountLabel); ExportTransformer.ExcelExport(fileName, this.CreateColumnCollection(), ReportData, WorksheetName); }
protected override void OnDataSheetChanged(DataSheetMonitorEventArgs e) { base.OnDataSheetChanged(e); string AmountLabel = null; TerminologyUnit AmountUnits = TerminologyUnit.None; TerminologyUtilities.GetAmountLabelTerminology(e.DataSheet, ref AmountLabel, ref AmountUnits); this.Columns[Strings.DATASHEET_TRANSITION_SIZE_DISTRIBUTION_MAXIMUM_AREA_COLUMN_NAME].DisplayName = (string.Format(CultureInfo.InvariantCulture, "Maximum {0} ({1})", AmountLabel, TerminologyUtilities.TerminologyUnitToString(AmountUnits))); }
protected override void OnDataSheetChanged(DataSheetMonitorEventArgs e) { base.OnDataSheetChanged(e); string amountlabel = null; TerminologyUnit units = 0; string unitsLbl = null; TerminologyUtilities.GetAmountLabelTerminology(e.DataSheet, ref amountlabel, ref units); unitsLbl = TerminologyUtilities.TerminologyUnitToString(units).ToLower(CultureInfo.InvariantCulture); this.LabelTotalAmount.Text = string.Format(CultureInfo.InvariantCulture, "Total ({0}):", unitsLbl); this.LabelCellSize.Text = string.Format(CultureInfo.InvariantCulture, "Cell size ({0}):", unitsLbl); this.TextBoxNumCells.Enabled = (this.ShouldEnableView() && (!this.CheckBoxCalcFromDist.Checked)); }
protected override void OnDataSheetChanged(DataSheetMonitorEventArgs e) { base.OnDataSheetChanged(e); string AmountLabel = null; TerminologyUnit AmountUnits = TerminologyUnit.None; TerminologyUtilities.GetAmountLabelTerminology(e.DataSheet, ref AmountLabel, ref AmountUnits); this.Columns[Strings.DATASHEET_AMOUNT_COLUMN_NAME].DisplayName = (string.Format(CultureInfo.InvariantCulture, "Target {0} ({1})", AmountLabel, TerminologyUtilities.TerminologyUnitToString(AmountUnits))); this.Columns[Strings.DATASHEET_DISTRIBUTIONTYPE_COLUMN_NAME].DisplayName = string.Format(CultureInfo.InvariantCulture, "Target {0} Distribution", AmountLabel); this.Columns[Strings.DATASHEET_DISTRIBUTION_FREQUENCY_COLUMN_NAME].DisplayName = string.Format(CultureInfo.InvariantCulture, "Target {0} Sampling Frequency", AmountLabel); this.Columns[Strings.DATASHEET_DISTRIBUTIONSD_COLUMN_NAME].DisplayName = string.Format(CultureInfo.InvariantCulture, "Target {0} SD", AmountLabel); this.Columns[Strings.DATASHEET_DISTRIBUTIONMIN_COLUMN_NAME].DisplayName = string.Format(CultureInfo.InvariantCulture, "Target {0} Min", AmountLabel); this.Columns[Strings.DATASHEET_DISTRIBUTIONMAX_COLUMN_NAME].DisplayName = string.Format(CultureInfo.InvariantCulture, "Target {0} Max", AmountLabel); }
private void OnTerminologyChanged(DataSheetMonitorEventArgs e) { string Primary = null; string Secondary = null; string Tertiary = null; string AmountLabel = null; TerminologyUnit AmountUnits = TerminologyUnit.None; TerminologyUtilities.GetStratumLabelTerminology(e.DataSheet, ref Primary, ref Secondary, ref Tertiary); TerminologyUtilities.GetAmountLabelTerminology(e.DataSheet, ref AmountLabel, ref AmountUnits); this.m_FilesDataGrid.Columns[PRIMARY_STRATUM_FILE_NAME_COLUMN_INDEX].HeaderText = BuildLowerCaseLabel(Primary); this.m_FilesDataGrid.Columns[SECONDARY_STRATUM_FILE_NAME_COLUMN_INDEX].HeaderText = BuildLowerCaseLabel(Secondary); this.m_FilesDataGrid.Columns[TERTIARY_STRATUM_FILE_NAME_COLUMN_INDEX].HeaderText = BuildLowerCaseLabel(Tertiary); this.RefreshCalculatedValues(); }
protected override void OnRowsAdded(object sender, DataSheetRowEventArgs e) { base.OnRowsAdded(sender, e); var ThisData = this.GetData(); DataSheet dsProp = this.GetDataSheet(Strings.DATASHEET_SPPIC_NAME); DataRow drProp = dsProp.GetDataRow(); if (drProp == null && ThisData.DefaultView.Count > 0) { dsProp.BeginAddRows(); drProp = dsProp.GetData().NewRow(); DataRow FirstRow = ThisData.DefaultView[0].Row; StochasticTimeRaster FirstRast = this.LoadRaster(FirstRow, Strings.DATASHEET_SPIC_STRATUM_FILE_COLUMN_NAME); if (FirstRast.IntCells == null) { FirstRast.LoadData(); } drProp[Strings.DATASHEET_SPPIC_NUM_ROWS_COLUMN_NAME] = FirstRast.Height; drProp[Strings.DATASHEET_SPPIC_NUM_COLUMNS_COLUMN_NAME] = FirstRast.Width; drProp[Strings.DATASHEET_SPPIC_NUM_CELLS_COLUMN_NAME] = FirstRast.GetNumberValidCells(); drProp[Strings.DATASHEET_SPPIC_XLLCORNER_COLUMN_NAME] = FirstRast.XllCorner; drProp[Strings.DATASHEET_SPPIC_YLLCORNER_COLUMN_NAME] = FirstRast.YllCorner; drProp[Strings.DATASHEET_SPPIC_CELL_SIZE_COLUMN_NAME] = FirstRast.CellSize; drProp[Strings.DATASHEET_SPPIC_CELL_SIZE_UNITS_COLUMN_NAME] = FirstRast.CellSizeUnits; drProp[Strings.DATASHEET_SPPIC_SRS_COLUMN_NAME] = FirstRast.Projection; drProp[Strings.DATASHEET_SPPIC_CELL_AREA_OVERRIDE_COLUMN_NAME] = false; string amountlabel = null; TerminologyUnit destUnitsVal = 0; double cellArea = System.Math.Pow((double)FirstRast.CellSize, 2); TerminologyUtilities.GetAmountLabelTerminology(this.Project.GetDataSheet(Strings.DATASHEET_TERMINOLOGY_NAME), ref amountlabel, ref destUnitsVal); drProp[Strings.DATASHEET_SPPIC_CELL_AREA_COLUMN_NAME] = CalcCellArea(cellArea, FirstRast.CellSizeUnits, destUnitsVal); dsProp.Changes.Add(new ChangeRecord(this, "Added raster metadata")); dsProp.GetData().Rows.Add(drProp); dsProp.EndAddRows(); } }
private void ValidateNormalSplit() { string psl = null; string ssl = null; string tsl = null; string aml = null; TerminologyUnit amu = 0; DataSheet tds = this.Project.GetDataSheet(Strings.DATASHEET_TERMINOLOGY_NAME); TerminologyUtilities.GetStratumLabelTerminology(tds, ref psl, ref ssl, ref tsl); TerminologyUtilities.GetAmountLabelTerminology(tds, ref aml, ref amu); //We don't support splits by secondary strata for spatial runs as this time if (this.IsSpatial) { ExceptionUtils.ThrowInvalidOperationException("Cannot split by '{0}' for a spatial model run.", ssl); } //If there are less than 2 secondary strata records referenced by //Initial Conditions Distribution we cannot do a split by secondary strata List <int> l = this.GetApplicableSecondaryStrata(); if (l.Count < 2) { ExceptionUtils.ThrowInvalidOperationException("Cannot split by '{0}' because there are fewer than two references to '{1}' in Initial Conditions Distribution.", ssl, ssl); } //If there are Transition Targets with NULL secondary stata then add a warning if (NullValueExists(this.ResultScenario.GetDataSheet(Strings.DATASHEET_TRANSITION_TARGET_NAME).GetData(), Strings.DATASHEET_SECONDARY_STRATUM_ID_COLUMN_NAME)) { this.RecordStatus(StatusType.Warning, string.Format(CultureInfo.InvariantCulture, "Run is splitting by '{0}' but Transition Targets are not specified by '{1}'. Allocating targets in proportion to '{2}'.", ssl, ssl, aml)); } //If there are Transition Attribute Targets with NULL secondary stata then add a warning if (NullValueExists(this.ResultScenario.GetDataSheet(Strings.DATASHEET_TRANSITION_ATTRIBUTE_TARGET_NAME).GetData(), Strings.DATASHEET_SECONDARY_STRATUM_ID_COLUMN_NAME)) { this.RecordStatus(StatusType.Warning, string.Format(CultureInfo.InvariantCulture, "Run is splitting by '{0}' but Transition Attribute Targets are not specified by '{1}'. Allocating targets in proportion to '{2}'.", ssl, ssl, aml)); } }
/// <summary> /// Convert the Cell Area as specified in the raster units to Cell Area as specified in user-configurable Terminology Units /// </summary> /// <param name="srcCellArea">The Cell Area in the raster files native units</param> /// <param name="srcSizeUnits">The native linear size units of the raster files</param> /// <param name="destAreaUnits">The specified Area Units</param> /// <returns>The calculated Cell Area</returns> /// <remarks></remarks> internal static double CalcCellArea(double srcCellArea, string srcSizeUnits, TerminologyUnit destAreaUnits) { double convFactor = 0; // Convert the Source Area to M2 srcSizeUnits = srcSizeUnits.Replace(" ", "_"); // replace space with an underscore // Convert from ft^2 to M2 if ((srcSizeUnits.ToUpper(CultureInfo.InvariantCulture) == RasterCellSizeUnit.Foot.ToString().ToUpper(CultureInfo.InvariantCulture)) || (srcSizeUnits.ToUpper(CultureInfo.InvariantCulture) == RasterCellSizeUnit.Foot_US.ToString().ToUpper(CultureInfo.InvariantCulture)) || (srcSizeUnits.ToUpper(CultureInfo.InvariantCulture) == RasterCellSizeUnit.US_survey_foot.ToString().ToUpper(CultureInfo.InvariantCulture))) { convFactor = 0.092903; } else if ( (srcSizeUnits.ToUpper(CultureInfo.InvariantCulture) == RasterCellSizeUnit.Metre.ToString().ToUpper(CultureInfo.InvariantCulture)) || (srcSizeUnits.ToUpper(CultureInfo.InvariantCulture) == RasterCellSizeUnit.Meter.ToString().ToUpper(CultureInfo.InvariantCulture)) || (srcSizeUnits.ToUpper(CultureInfo.InvariantCulture) == RasterCellSizeUnit.Meters.ToString().ToUpper(CultureInfo.InvariantCulture))) { // No conversion needed for Meters convFactor = 1; } else if ( (srcSizeUnits.ToUpper(CultureInfo.InvariantCulture) == RasterCellSizeUnit.Undefined.ToString().ToUpper(CultureInfo.InvariantCulture)) || (srcSizeUnits.ToUpper(CultureInfo.InvariantCulture) == RasterCellSizeUnit.Undetermined.ToString().ToUpper(CultureInfo.InvariantCulture))) { return(0); } var areaM2 = srcCellArea * convFactor; // Now lets convert M2 to Terminology Units //Calculate the total area and cell size switch (destAreaUnits) { case TerminologyUnit.Acres: // 1m2 = 0.000247105 Acres convFactor = 0.000247105; break; case TerminologyUnit.Hectares: // 1m2 = 0.0001 Hectares convFactor = 0.0001; break; case TerminologyUnit.SquareKilometers: // 1m2 = 1e-6 Km2 convFactor = 0.000001; break; case TerminologyUnit.SquareMiles: // 1m2 = 3.861e-7 Mi2 convFactor = 0.0000003861; break; default: convFactor = 0; break; } return(areaM2 * convFactor); }