public frmImportRaster(Raster sourceRaster, Surface refSurface, Purposes ePurpose, string sNoun) { // This call is required by the designer. InitializeComponent(); Cursor = Cursors.WaitCursor; NeedsForcedProjection = false; Text = "Add Existing " + sNoun; grpProjectRaaster.Text = "GCD " + sNoun; Purpose = ePurpose; SourceRaster = sourceRaster; txtSourceRaster.Text = sourceRaster.GISFileInfo.FullName; if (ePurpose == Purposes.FirstDEM) { ExtImporter = new ExtentAdjusterNoReference(sourceRaster.Extent); } else { ReferenceSurface = refSurface; if (Purpose == Purposes.SubsequentDEM || Purpose == Purposes.ReferenceSurface) { ExtImporter = new ExtentAdjusterWithReference(sourceRaster.Extent, refSurface.Raster.Extent); } else { ExtImporter = new ExtentAdjusterFixed(sourceRaster.Extent, refSurface.Raster.Extent); } } Cursor = Cursors.Default; }
public void AdjustDimensions() { // Moving the top coordinate by two cells. Note other coordinates should not move. decimal cellWidth = 1.510000m; ExtentRectangle dummySrc2 = new ExtentRectangle(1600.345m, 19.12345m, -cellWidth, cellWidth, 2, 2); { ExtentAdjusterNoReference t2 = new ExtentAdjusterNoReference(dummySrc2); ExtentAdjusterBase t3 = t2.AdjustDimensions(t2.OutExtent.Top + (2m * 1.51m), t2.OutExtent.Right, t2.OutExtent.Bottom, t2.OutExtent.Left); Assert.IsTrue(t3.OutExtent.IsDivisible()); Assert.AreEqual(t3.OutExtent.Top, 1603.62m); // 1600.61 + 3.02 Assert.AreEqual(t3.OutExtent.Right, 22.65m); // unchanged Assert.AreEqual(t3.OutExtent.Bottom, 1596.07m); // unchanged Assert.AreEqual(t3.OutExtent.Left, 18.12m); // unchanged } { // Add irregular value to top and ensure output is divisible ExtentAdjusterNoReference t3 = new ExtentAdjusterNoReference(dummySrc2); Assert.IsTrue(t3.OutExtent.IsDivisible()); ExtentAdjusterBase t4 = t3.AdjustDimensions(t3.OutExtent.Top + 0.0003456m, t3.OutExtent.Right, t3.OutExtent.Bottom, t3.OutExtent.Left); Assert.IsTrue(t4.OutExtent.IsDivisible()); } { // Add irregular value to all dimensions ExtentAdjusterNoReference t3 = new ExtentAdjusterNoReference(dummySrc2); Assert.IsTrue(t3.OutExtent.IsDivisible()); ExtentAdjusterBase t4 = t3.AdjustDimensions(t3.OutExtent.Top + 0.0003456m, t3.OutExtent.Right + 1.513334566m, t3.OutExtent.Bottom - 12.321m, t3.OutExtent.Left - 19.11111m); Assert.IsTrue(t4.OutExtent.IsDivisible()); } }
public void AdjustCellSize() { // Moving the top coordinate by two cells. Note other coordinates should not move. decimal cellWidth = 1.510000m; ExtentRectangle dummySrc2 = new ExtentRectangle(1600.345m, 19.12345m, -cellWidth, cellWidth, 2, 2); { ExtentAdjusterNoReference t2 = new ExtentAdjusterNoReference(dummySrc2); ExtentAdjusterBase t3 = t2.AdjustCellSize(2m); Assert.IsTrue(t3.OutExtent.IsDivisible()); Assert.AreEqual(t3.OutExtent.Top, 1602m); Assert.AreEqual(t3.OutExtent.Right, 26m); Assert.AreEqual(t3.OutExtent.Bottom, 1594m); Assert.AreEqual(t3.OutExtent.Left, 18m); } }
public void AdjustPrecision() { // Moving the top coordinate by two cells. Note other coordinates should not move. decimal cellWidth = 1.510000m; ExtentRectangle dummySrc2 = new ExtentRectangle(1600.345m, 19.12345m, -cellWidth, cellWidth, 2, 2); // Reduce precision to 1 ExtentAdjusterNoReference t2 = new ExtentAdjusterNoReference(dummySrc2); ExtentAdjusterBase t3 = t2.AdjustPrecision(1); Assert.IsTrue(t3.OutExtent.IsDivisible()); Assert.AreEqual(t3.OutExtent.CellWidth, 1.5m); Assert.AreEqual(t3.Precision, 1); // Now reduce it again to zero ExtentAdjusterBase t4 = ((ExtentAdjusterNoReference)t3).AdjustPrecision(0); Assert.IsTrue(t4.OutExtent.IsDivisible()); Assert.AreEqual(t4.OutExtent.CellWidth, 2m); Assert.AreEqual(t4.Precision, 0); }
public void GetInitialNumDecimalsTest() { // Easy usual scenarios Assert.AreEqual(0, ExtentAdjusterBase.GetInitialNumDecimals(2m)); Assert.AreEqual(1, ExtentAdjusterBase.GetInitialNumDecimals(0.1m)); Assert.AreEqual(2, ExtentAdjusterBase.GetInitialNumDecimals(0.01m)); Assert.AreEqual(3, ExtentAdjusterBase.GetInitialNumDecimals(0.001m)); Assert.AreEqual(4, ExtentAdjusterBase.GetInitialNumDecimals(0.0001m)); Assert.AreEqual(5, ExtentAdjusterBase.GetInitialNumDecimals(0.00001m)); Assert.AreEqual(6, ExtentAdjusterBase.GetInitialNumDecimals(0.000001m)); Assert.AreEqual(7, ExtentAdjusterBase.GetInitialNumDecimals(0.0000001m)); Assert.AreEqual(0, ExtentAdjusterBase.GetInitialNumDecimals(10m)); Assert.AreEqual(0, ExtentAdjusterBase.GetInitialNumDecimals(100m)); Assert.AreEqual(0, ExtentAdjusterBase.GetInitialNumDecimals(1000m)); Assert.AreEqual(0, ExtentAdjusterBase.GetInitialNumDecimals(10000m)); // More tricky... // So close to that we might as well just drop the decimals Assert.AreEqual(0, ExtentAdjusterBase.GetInitialNumDecimals(10.0003m)); Assert.AreEqual(0, ExtentAdjusterBase.GetInitialNumDecimals(2.000000000000040102m)); Assert.AreEqual(1, ExtentAdjusterBase.GetInitialNumDecimals(2.500000000000040102m)); }
private void UpdateOutputExtent(object sender, EventArgs e) { ExtentAdjusterBase temp = ExtImporter; if (sender == valTop || sender == valRight || sender == valBottom || sender == valLeft) { temp = ExtImporter.AdjustDimensions(valTop.Value, valRight.Value, valBottom.Value, valLeft.Value); } else if (sender == valCellSize) { if (valCellSize.Value <= 0m) { valCellSize.Value = ExtImporter.OutExtent.CellWidth; return; } temp = ExtImporter.AdjustCellSize(valCellSize.Value); } else if (sender == valPrecision) { temp = ExtImporter.AdjustPrecision((ushort)valPrecision.Value); } // Turn off event firing valTop.ValueChanged -= UpdateOutputExtent; valBottom.ValueChanged -= UpdateOutputExtent; valRight.ValueChanged -= UpdateOutputExtent; valLeft.ValueChanged -= UpdateOutputExtent; valCellSize.ValueChanged -= UpdateOutputExtent; valPrecision.ValueChanged -= UpdateOutputExtent; // Update the extent adjustor ExtImporter = temp; // Update output control values valCellSize.DecimalPlaces = ExtImporter.Precision; valTop.DecimalPlaces = ExtImporter.Precision; valLeft.DecimalPlaces = ExtImporter.Precision; valRight.DecimalPlaces = ExtImporter.Precision; valBottom.DecimalPlaces = ExtImporter.Precision; valTop.Value = ExtImporter.OutExtent.Top; valLeft.Value = ExtImporter.OutExtent.Left; valRight.Value = ExtImporter.OutExtent.Right; valBottom.Value = ExtImporter.OutExtent.Bottom; valCellSize.Value = ExtImporter.OutExtent.CellWidth; valPrecision.Value = ExtImporter.Precision; // Colour the numeric up down boxes based on whether they match the original extent valTop.ForeColor = SourceRaster.Extent.Top == ExtImporter.OutExtent.Top ? System.Drawing.Color.DarkGreen : System.Drawing.Color.Black; valLeft.ForeColor = SourceRaster.Extent.Left == ExtImporter.OutExtent.Left ? System.Drawing.Color.DarkGreen : System.Drawing.Color.Black; valRight.ForeColor = SourceRaster.Extent.Right == ExtImporter.OutExtent.Right ? System.Drawing.Color.DarkGreen : System.Drawing.Color.Black; valBottom.ForeColor = SourceRaster.Extent.Bottom == ExtImporter.OutExtent.Bottom ? System.Drawing.Color.DarkGreen : System.Drawing.Color.Black; txtProjCols.Text = ExtImporter.OutExtent.Cols.ToString("#,##0"); txtProjRows.Text = ExtImporter.OutExtent.Rows.ToString("#,##0"); UnitsNet.Units.LengthUnit hUnits = SourceRaster.Proj.HorizontalUnit; txtProjWidth.Text = string.Format("{0}{1}", ExtImporter.OutExtent.Width, UnitsNet.Length.GetAbbreviation(hUnits)); txtProjHeight.Text = string.Format("{0}{1}", ExtImporter.OutExtent.Height, UnitsNet.Length.GetAbbreviation(hUnits)); txtInterpolationMethod.Text = ExtImporter.RequiresResampling ? "Bilinear Interpolation" : "None (straight cell-wise copy)"; // Turn on event firing valTop.ValueChanged += UpdateOutputExtent; valBottom.ValueChanged += UpdateOutputExtent; valRight.ValueChanged += UpdateOutputExtent; valLeft.ValueChanged += UpdateOutputExtent; valCellSize.ValueChanged += UpdateOutputExtent; valPrecision.ValueChanged += UpdateOutputExtent; }