public void ExtendedCopyTest() { // First try it with a real file using (ITempDir tmp = TempDir.Create()) { Raster rTempl = new Raster(new FileInfo(DirHelpers.GetTestRasterPath("Slopey950-980.tif"))); ExtentRectangle newExtReal = rTempl.Extent.Buffer(15); Raster rTemplateOutput = RasterOperators.ExtendedCopy(rTempl, new FileInfo(Path.Combine(tmp.Name, "ExtendedCopyRasterTestBuffer.tif")), newExtReal); ExtentRectangle newExtReal2 = rTempl.Extent.Buffer(5); newExtReal2.Rows = (int)newExtReal2.Rows / 2; newExtReal2.Cols = (int)newExtReal2.Cols / 3; Raster rTemplateOutput2 = RasterOperators.ExtendedCopy(rTempl, new FileInfo(Path.Combine(tmp.Name, "ExtendedCopyRasterTestSlice.tif")), newExtReal2); } Raster Raster1 = new FakeRaster <int>(10, 20, -1, 1, new int[, ] { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 } }); int[,] outgrid = new int[7, 8]; outgrid.Fill(-999); Raster rOutput = new FakeRaster <int>(10, 20, -1, 1, outgrid); ExtentRectangle newExt = Raster1.Extent.Buffer(2); Internal.Operators.ExtendedCopy <int> copyOp = new Internal.Operators.ExtendedCopy <int>(Raster1, rOutput, new ExtentRectangle(newExt)); copyOp.RunWithOutput(); }
public void BinPointsTest() { Raster rDEM = new Raster(new FileInfo(DirHelpers.GetTestRootPath(@"PointDensity\GrandCanyon\RASTER1m.tif"))); Vector rPtDensity = new Vector(new FileInfo(DirHelpers.GetTestRootPath(@"PointDensity\GrandCanyon\R2_HybridData_2004_05.shp"))); Raster circleOut = new FakeRaster <double>(rDEM); PointDensity circletest = new PointDensity(rDEM, rPtDensity, circleOut, RasterOperators.KernelShapes.Square, 5.0m); List <Geometry> pts = new List <Geometry>() { pointMaker((double)circletest.ChunkExtent.Left, (double)circletest.ChunkExtent.Top), pointMaker((double)circletest.ChunkExtent.Left + 5, (double)circletest.ChunkExtent.Top), pointMaker((double)circletest.ChunkExtent.Left + 10, (double)circletest.ChunkExtent.Top), pointMaker((double)circletest.ChunkExtent.Left, (double)circletest.ChunkExtent.Top - 5), pointMaker((double)circletest.ChunkExtent.Left, (double)circletest.ChunkExtent.Top - 10), }; List <Geometry>[,] bins = circletest.BinPoints(pts); // Now make sure we still have our 5 points in the right boxes Assert.AreEqual(bins[1, 1].Count, 1); Assert.AreEqual(bins[1, 2].Count, 1); Assert.AreEqual(bins[1, 3].Count, 1); Assert.AreEqual(bins[2, 1].Count, 1); Assert.AreEqual(bins[3, 1].Count, 1); }
public void TranslateCIDToBinIDTest() { Raster rDEM = new Raster(new FileInfo(DirHelpers.GetTestRootPath(@"PointDensity\GrandCanyon\RASTER1m.tif"))); Vector rPtDensity = new Vector(new FileInfo(DirHelpers.GetTestRootPath(@"PointDensity\GrandCanyon\R2_HybridData_2004_05.shp"))); Raster circleOut = new FakeRaster <double>(rDEM); PointDensity circletest = new PointDensity(rDEM, rPtDensity, circleOut, RasterOperators.KernelShapes.Square, 5.0m); int[] topleft = circletest.TranslateCIDToBinID(pointMaker((double)circletest.ChunkExtent.Left, (double)circletest.ChunkExtent.Top)); CollectionAssert.AreEqual(topleft, new int[2] { 1, 1 }); int[] topleft1 = circletest.TranslateCIDToBinID(pointMaker((double)circletest.ChunkExtent.Left + 5.0, (double)circletest.ChunkExtent.Top)); CollectionAssert.AreEqual(topleft1, new int[2] { 2, 1 }); int[] topright = circletest.TranslateCIDToBinID(pointMaker((double)circletest.ChunkExtent.Right, (double)circletest.ChunkExtent.Top)); CollectionAssert.AreEqual(topright, new int[2] { 120, 1 }); int[] bottomleft = circletest.TranslateCIDToBinID(pointMaker((double)circletest.ChunkExtent.Left, (double)circletest.ChunkExtent.Bottom)); CollectionAssert.AreEqual(bottomleft, new int[2] { 1, 11 }); int[] bottomright = circletest.TranslateCIDToBinID(pointMaker((double)circletest.ChunkExtent.Right, (double)circletest.ChunkExtent.Bottom)); CollectionAssert.AreEqual(bottomright, new int[2] { 120, 11 }); }
public void TestEventRaised() { // This is a test object to collect all the progress events List <int> receivedEvents = new List <int>(); // Now we define an action to run when the progress event fires. Do tjis in whatever function // You're calling Interface.cs from EventHandler <OpStatus> receivedEventsHandler = delegate(object sender, OpStatus e) { receivedEvents.Add(e.Progress); }; ////////////////////////////////// <Interface.cs> //////////////////////////////////////////// // Now we fake what's happening inside Interface.cs" FakeRaster <int> Raster1 = new FakeRaster <int>(0, 0, -1, 1, new int[, ] { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 } }); TestOp <int> theTest = new TestOp <int>(new List <Raster> { Raster1 }); theTest.ProgressEvent += receivedEventsHandler; theTest.OpDescription = "Running Test Event"; // Here's where the delegate is assigned to the theTest.Run(); ////////////////////////////////// </Interface.cs> //////////////////////////////////////////// // Now make sure our list contains the events (doesn't have to be a list. You could update a UI control instead) CollectionAssert.Contains(receivedEvents, 0); CollectionAssert.Contains(receivedEvents, 100); }
public void SetOpExtentTest() { FakeRaster <int> Raster1 = new FakeRaster <int>(0, 0, -1, 1, new int[, ] { { 0, 1, 2, -999 }, { 3, 4, 5, -999 }, { 6, 7, 8, -999 }, { 0, 1, 2, -999 }, { 3, 4, 5, -999 }, { 6, 7, 8, -999 }, { 0, 1, 2, -999 }, { 3, 4, 5, -999 }, { 6, 7, 8, -999 }, { 0, 1, 2, -999 }, { 3, 4, 5, -999 }, { 6, 7, 8, -999 } }); int[,] output = new int[, ] { { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } }; Raster rOutput3 = new FakeRaster <int>(0, 0, -1, 1, new int[, ] { { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } }); TestWOOOp <int> theTest3 = new TestWOOOp <int>(new List <Raster> { Raster1 }, 3, rOutput3); theTest3.BuffOpExtent(5); }
public void WindowOverlapOperatorTest() { FakeRaster <int> Raster1 = new FakeRaster <int>(0, 0, -1, 1, new int[, ] { { 0, 1, 2, -999 }, { 3, 4, 5, -999 }, { 6, 7, 8, -999 }, { 0, 1, 2, -999 }, { 3, 4, 5, -999 }, { 6, 7, 8, -999 }, { 0, 1, 2, -999 }, { 3, 4, 5, -999 }, { 6, 7, 8, -999 }, { 0, 1, 2, -999 }, { 3, 4, 5, -999 }, { 6, 7, 8, -999 } }); int[,] output = new int[, ] { { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } }; Raster rOutput1 = new FakeRaster <int>(0, 0, -1, 1, output); TestWOOOp <int> theTest1 = new TestWOOOp <int>(new List <Raster> { Raster1 }, 1, rOutput1); theTest1.RunWithOutput(); CollectionAssert.AreEqual(Raster1._inputgrid, ((FakeRaster <int>)rOutput1)._outputGrid); Raster rOutput2 = new FakeRaster <int>(0, 0, -1, 1, output); TestWOOOp <int> theTest2 = new TestWOOOp <int>(new List <Raster> { Raster1 }, 2, rOutput2); theTest2.RunWithOutput(); CollectionAssert.AreEqual(Raster1._inputgrid, ((FakeRaster <int>)rOutput2)._outputGrid); Raster rOutput3 = new FakeRaster <int>(0, 0, -1, 1, output); TestWOOOp <int> theTest3 = new TestWOOOp <int>(new List <Raster> { Raster1 }, 3, rOutput3); theTest3.RunWithOutput(); CollectionAssert.AreEqual(Raster1._inputgrid, ((FakeRaster <int>)rOutput3)._outputGrid); }
public void InsideRadiusTest() { Raster rDEM = new Raster(new FileInfo(DirHelpers.GetTestRootPath(@"PointDensity\GrandCanyon\RASTER1m.tif"))); Vector rPtDensity = new Vector(new FileInfo(DirHelpers.GetTestRootPath(@"PointDensity\GrandCanyon\R2_HybridData_2004_05.shp"))); Raster circleOut = new FakeRaster <double>(rDEM); PointDensity circletest = new PointDensity(rDEM, rPtDensity, circleOut, RasterOperators.KernelShapes.Circle, 5.0m); Geometry origin = pointMaker(0, 0); Assert.IsTrue(circletest.InsideRadius(origin, origin)); Assert.IsTrue(circletest.InsideRadius(origin, pointMaker(0, 2))); Assert.IsTrue(circletest.InsideRadius(origin, pointMaker(2, 0))); Assert.IsTrue(circletest.InsideRadius(origin, pointMaker(1, 1))); Assert.IsFalse(circletest.InsideRadius(origin, pointMaker(0, 5.1))); Assert.IsFalse(circletest.InsideRadius(origin, pointMaker(2, 6.0))); Assert.IsFalse(circletest.InsideRadius(origin, pointMaker(5, 5))); Assert.IsFalse(circletest.InsideRadius(origin, pointMaker(5.1, 5.1))); }
public void GetChunkTest() { FakeRaster <int> Raster1 = new FakeRaster <int>(10, 20, -1, 1, new int[, ] { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 } }); FakeRaster <int> rOutput = new FakeRaster <int>(10, 20, -1, 1, new int[, ] { { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } }); TestOp <int> theTest = new TestOp <int>(new List <Raster> { Raster1 }, rOutput); List <int[]> data = new List <int[]>() { new int[theTest.ChunkExtent.Cols * theTest.ChunkExtent.Rows] }; theTest.GetChunk(data); CollectionAssert.AreEqual(data[0], Raster1._inputgrid.Make1DArray <int>()); }
public void CellByCellOperatorTest() { FakeRaster <int> Raster1 = new FakeRaster <int>(0, 0, -1, 1, new int[, ] { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 } }); FakeRaster <int> Raster2 = new FakeRaster <int>(0, 0, -1, 1, new int[, ] { { 1, 0, 0, 1 }, { 0, 1, 1, 0 }, { 0, 2, 0, 0 } }); int[,] rExpected = new int[, ] { { 2, 2, 3, 5 }, { 5, 7, 8, 8 }, { 9, 12, 11, 12 } }; Raster rOutput = new FakeRaster <int>(0, 0, -1, 1, new int[, ] { { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } }); TestCBCOp <int> theTest = new TestCBCOp <int>(new List <Raster> { Raster1, Raster2 }, rOutput); theTest.Run(); //CollectionAssert.AreEqual(rOutput._outputGrid, rExpected); }
public void BaseInitTest() { FakeRaster <int> Raster1 = new FakeRaster <int>(0, 0, -1, 1, new int[, ] { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 } }); FakeRaster <int> Raster2 = new FakeRaster <int>(0, 0, -1, 1, new int[, ] { { 1, 0, 0, 1 }, { 0, 1, 1, 0 }, { 0, 2, 0, 0 } }); int[,] rExpected = new int[, ] { { 2, 2, 3, 5 }, { 5, 7, 8, 8 }, { 9, 12, 11, 12 } }; FakeRaster <int> rOutput = new FakeRaster <int>(0, 0, -1, 1, new int[, ] { { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } }); TestOp <int> theTest = new TestOp <int>(new List <Raster> { Raster1, Raster2 }, rOutput); theTest.TestRunWithOutput(); CollectionAssert.AreEqual(rOutput._outputGrid, rExpected); }
public void NextChunkTest() { FakeRaster <int> Raster1 = new FakeRaster <int>(10, 20, -1, 1, new int[, ] { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 } }); FakeRaster <int> rOutput = new FakeRaster <int>(10, 20, -1, 1, new int[, ] { { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } }); TestOp <int> theTest = new TestOp <int>(new List <Raster> { Raster1 }, rOutput); Assert.AreEqual(theTest.ChunkExtent.Top, 10); Assert.AreEqual(theTest.ChunkExtent.Left, 20); Assert.AreEqual(theTest.ChunkExtent.Rows, 3); Assert.AreEqual(theTest.ChunkExtent.Cols, 4); Assert.AreEqual(theTest.ChunkExtent.CellHeight, -1); Assert.AreEqual(theTest.ChunkExtent.CellWidth, 1); theTest.NextChunk(); Assert.IsTrue(theTest.OpDone); }
public void GetRelevantBinsTest() { Raster rDEM = new Raster(new FileInfo(DirHelpers.GetTestRootPath(@"PointDensity\GrandCanyon\RASTER1m.tif"))); Vector rPtDensity = new Vector(new FileInfo(DirHelpers.GetTestRootPath(@"PointDensity\GrandCanyon\R2_HybridData_2004_05.shp"))); Raster circleOut = new FakeRaster <double>(rDEM); PointDensity circletest = new PointDensity(rDEM, rPtDensity, circleOut, RasterOperators.KernelShapes.Square, 5.0m); List <int[]> topleft = circletest.GetRelevantBins(pointMaker((double)circletest.ChunkExtent.Left, (double)circletest.ChunkExtent.Top)); List <int[]> expectedTopLeft = new List <int[]> { new int[2] { 0, 0 }, new int[2] { 0, 1 }, new int[2] { 0, 2 }, new int[2] { 1, 0 }, new int[2] { 1, 1 }, new int[2] { 1, 2 }, new int[2] { 2, 0 }, new int[2] { 2, 1 }, new int[2] { 2, 2 }, }; for (int i = 0; i < topleft.Count; i++) { CollectionAssert.AreEqual(topleft[i], expectedTopLeft[i]); } List <int[]> bottomright = circletest.GetRelevantBins(pointMaker((double)circletest.ChunkExtent.Right, (double)circletest.ChunkExtent.Bottom)); List <int[]> expectedBottomRight = new List <int[]> { new int[2] { 119, 10 }, new int[2] { 119, 11 }, new int[2] { 119, 12 }, new int[2] { 120, 10 }, new int[2] { 120, 11 }, new int[2] { 120, 12 }, new int[2] { 121, 10 }, new int[2] { 121, 11 }, new int[2] { 121, 12 }, }; for (int i = 0; i < bottomright.Count; i++) { CollectionAssert.AreEqual(bottomright[i], expectedBottomRight[i]); } }
public TestOp(List <Raster> rRasters, FakeRaster <T> rOutput, ExtentRectangle newExtent) : base(rRasters, rOutput) { SetOpExtent(newExtent); Assert.AreEqual(rRasters.Count, _inputRasters.Count); Assert.IsFalse(OpDone); }
public TestOp(List <Raster> rRasters, FakeRaster <T> rOutput) : base(rRasters, rOutput) { Assert.AreEqual(rRasters.Count, _inputRasters.Count); Assert.IsFalse(OpDone); }
public void NodataTests() { Raster intRaster = new FakeRaster <int>(10, 20, -1, 1, new int[, ] { { 1 } }); Raster floatRaster = new FakeRaster <float>(10, 20, -1, 1, new float[, ] { { 1.0f } }); Raster doubleRaster = new FakeRaster <double>(10, 20, -1, 1, new double[, ] { { 1.0 } }); Raster byteRaster = new FakeRaster <byte>(10, 20, -1, 1, new byte[, ] { { 0x20 } }); intRaster.origNodataVal = int.MinValue; floatRaster.origNodataVal = float.MinValue; doubleRaster.origNodataVal = double.MinValue; byteRaster.origNodataVal = byte.MinValue; Raster OUTfloatRaster1 = new FakeRaster <float>(10, 20, -1, 1, new float[, ] { { 0.0f } }) { origNodataVal = 0 // Set Purposely wrong }; TestOp <float> theTest1 = new TestOp <float>(new List <Raster> { floatRaster }, OUTfloatRaster1); float expected = floatRaster.NodataValue <float>(); Assert.AreEqual(theTest1.inNodataVals[0], expected); Assert.AreEqual(OUTfloatRaster1.NodataValue <float>(), expected); Raster OUTdoubleRaster1 = new FakeRaster <double>(10, 20, -1, 1, new double[, ] { { 0.0 } }) { origNodataVal = 0 // Set Purposely wrong }; TestOp <double> theTest2 = new TestOp <double>(new List <Raster> { floatRaster }, OUTdoubleRaster1); double expected2 = floatRaster.NodataValue <double>(); Assert.AreEqual(theTest2.outNodataVals[0], expected2); Assert.AreEqual(OUTdoubleRaster1.NodataValue <double>(), floatRaster.NodataValue <double>()); Raster OUTfloatRaster2 = new FakeRaster <float>(10, 20, -1, 1, new float[, ] { { 0.0f } }) { origNodataVal = 0 // Set Purposely wrong }; TestOp <double> theTest3 = new TestOp <double>(new List <Raster> { doubleRaster }, OUTfloatRaster2); double expected3 = floatRaster.NodataValue <double>(); Assert.AreEqual(theTest3.outNodataVals[0], expected3); Assert.AreEqual(OUTfloatRaster2.NodataValue <double>(), expected3); Raster OUTfloatRaster3 = new FakeRaster <float>(10, 20, -1, 1, new float[, ] { { 0.0f } }) { origNodataVal = 0 // Set Purposely wrong }; TestOp <float> theTest4 = new TestOp <float>(new List <Raster> { intRaster }, OUTfloatRaster3); float expected4 = intRaster.NodataValue <float>(); Assert.AreEqual(theTest4.outNodataVals[0], expected4); Assert.AreEqual(OUTfloatRaster3.NodataValue <double>(), expected4); Raster OUTintRaster = new FakeRaster <int>(10, 20, -1, 1, new int[, ] { { 0 } }) { origNodataVal = 0 // Set Purposely wrong }; TestOp <float> theTest5 = new TestOp <float>(new List <Raster> { doubleRaster }, OUTintRaster); float expected5 = floatRaster.NodataValue <float>(); Assert.AreEqual(theTest5.outNodataVals[0], expected5); Assert.AreEqual(OUTintRaster.NodataValue <float>(), expected5); }
public void BaseInitTestReal() { // First try it with a real file using (ITempDir tmp = TempDir.Create()) { Raster rTemplateRaster = new Raster(new FileInfo(DirHelpers.GetTestRasterPath("AngledSlopey950-980E.tif"))); FakeRaster <float> rOut = new FakeRaster <float>(rTemplateRaster); TestOp <float> theTest = new TestOp <float>(new List <Raster> { rTemplateRaster }, rOut); // before we set the new extent Assert.AreEqual(theTest.InExtent.ToString(), "-9979 -10029.0 -9969.0 -10019"); Assert.AreEqual(theTest.OpExtent.ToString(), "-9979 -10029.0 -9969.0 -10019"); Assert.AreEqual(theTest.ChunkExtent.ToString(), "-9979 -10020.0 -9969.0 -10019"); Assert.IsFalse(theTest.OpDone); // Now get the first chunk theTest.NextChunk(); Assert.AreEqual(theTest.InExtent.ToString(), "-9979 -10029.0 -9969.0 -10019"); Assert.AreEqual(theTest.OpExtent.ToString(), "-9979 -10029.0 -9969.0 -10019"); Assert.AreEqual(theTest.ChunkExtent.ToString(), "-9979 -10021.0 -9969.0 -10020"); Assert.IsFalse(theTest.OpDone); // Get to the end somehow. This raster is only 100 rows tall so 100 nexts should be // well past the end int counter = 0; while (!theTest.OpDone && counter < 100) { counter++; theTest.NextChunk(); } Assert.AreEqual(theTest.ChunkExtent.ToString(), "-9979 -10029.0 -9969.0 -10029"); Assert.IsTrue(theTest.OpDone); // Now let's try with a different extent int buffer = 100; TestOp <float> theTest2 = new TestOp <float>(new List <Raster> { rTemplateRaster }, rOut, rTemplateRaster.Extent.Buffer(buffer)); Assert.AreEqual(theTest2.InExtent.ToString(), "-9979 -10029.0 -9969.0 -10019"); Assert.AreEqual(theTest2.OpExtent.ToString(), "-9989 -10039.0 -9959.0 -10009"); Assert.AreEqual(theTest2.ChunkExtent.ToString(), "-9989 -10010.0 -9959.0 -10009"); Assert.IsFalse(theTest2.OpDone); // Now get the first chunk theTest2.NextChunk(); Assert.AreEqual(theTest2.InExtent.ToString(), "-9979 -10029.0 -9969.0 -10019"); Assert.AreEqual(theTest2.OpExtent.ToString(), "-9989 -10039.0 -9959.0 -10009"); Assert.AreEqual(theTest2.ChunkExtent.ToString(), "-9989 -10011.0 -9959.0 -10010"); Assert.IsFalse(theTest2.OpDone); // Get to the end somehow. This raster is only 200 rows tall so 100 nexts should be // well past the end counter = 0; while (!theTest2.OpDone && counter < 100) { counter++; theTest2.NextChunk(); } Assert.AreEqual(theTest2.ChunkExtent.ToString(), "-9989 -10039.0 -9959.0 -10039"); Assert.IsTrue(theTest2.OpDone); } }