Example #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="rTemplate"></param>
        /// <param name="newRect"></param>
        /// <param name="rOutputRaster"></param>
        public PointDensity(Raster rDEM, Vector vPointCloud, Raster OutputRaster, RasterOperators.KernelShapes eKernel, decimal fSize)
            : base(new List <Raster>() { rDEM }, OutputRaster)
        {
            _vinput   = vPointCloud;
            _routput  = OutputRaster;
            _kshape   = eKernel;
            _fsize    = (double)fSize;
            _fsizedec = fSize;

            // set the rows to be a certain multiple of fSize windows
            chunkRows = (int)Math.Ceiling((NUMWINDOWS * fSize) / Math.Abs(rDEM.Extent.CellHeight));

            // Calling this again after setting the rows will give us a nicer chunk size
            SetOpExtent(OpExtent);
            VectorChunkExtent = ChunkExtent.Buffer(_fsizedec);
            switch (eKernel)
            {
            case RasterOperators.KernelShapes.Circle:
                area = Math.PI * Math.Pow((double)fSize, 2);
                break;

            case RasterOperators.KernelShapes.Square:
                area = Math.Pow((double)fSize * 2, 2);
                break;
            }
        }
Example #2
0
        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();
        }
        /// <summary>
        /// Output Constructor
        /// </summary>
        /// <param name="sDescription">Some descriptive text for the status bar / Log files</param>
        /// <param name="rRasters"></param>
        /// <param name="bufferCells"></param>
        /// <param name="rOutputRaster"></param>
        public WindowOverlapOperator(List <Raster> rRasters, int bufferCells, List <Raster> rOutputRasters = null) :
            base(rRasters, rOutputRasters)
        {
            BufferCells = bufferCells;
            _vOffset    = -BufferCells;
            _chunkCache = new List <List <T[]> >(BufferLength);

            dWindow = new List <T[]>();
            foreach (Raster rN in _inputRasters)
            {
                dWindow.Add(new T[BufferCellNum]);
            }

            // 1 is the convention for windowed mode for good reason
            ChunkExtent.Rows = 1;
            chunkRows        = 1;
            ChunkExtent.Cols = OpExtent.Cols;

            // We add rows to the end so the operation goes over the end of the file
            OriginalOpBottom = OpExtent.Bottom;
            OpExtent.Rows   += BufferCells;
            WindowExtent     = new ExtentRectangle(ChunkExtent.Top - OpExtent.CellHeight,
                                                   ChunkExtent.Left - OpExtent.CellWidth,
                                                   OpExtent.CellHeight,
                                                   OpExtent.CellWidth,
                                                   BufferLength,
                                                   BufferLength);
        }
Example #4
0
        public void BufferTest()
        {
            ExtentRectangle rOrig = new ExtentRectangle(20, 20, -1, 1, 20, 20);
            ExtentRectangle rA1   = rOrig.Buffer(10.0m);

            Assert.AreEqual(rA1.Top, 30.0m);
            Assert.AreEqual(rA1.Bottom, -10.0m);
            Assert.AreEqual(rA1.Left, 10.0m);
            Assert.AreEqual(rA1.Right, 50.0m);
            Assert.AreEqual(rA1.Rows, 40);
            Assert.AreEqual(rA1.Cols, 40);

            Assert.AreEqual(rA1.CellHeight, -1m);
            Assert.AreEqual(rA1.CellWidth, 1m);
            Assert.AreEqual(rA1.Height, 40.0m);
            Assert.AreEqual(rA1.Width, 40.0m);
            Assert.AreEqual(rA1.MaxArrID, 1599);

            // we can do it by number of cells too
            ExtentRectangle rA2 = rOrig.Buffer((int)11);

            Assert.AreEqual(rA2.Top, 31.0m);
            Assert.AreEqual(rA2.Bottom, -11.0m);
            Assert.AreEqual(rA2.Left, 9.0m);
            Assert.AreEqual(rA2.Right, 51.0m);
            Assert.AreEqual(rA2.Rows, 42);
            Assert.AreEqual(rA2.Cols, 42);

            Assert.AreEqual(rA2.CellHeight, -1m);
            Assert.AreEqual(rA2.CellWidth, 1m);
            Assert.AreEqual(rA2.Height, 42.0m);
            Assert.AreEqual(rA2.Width, 42.0m);
            Assert.AreEqual(rA2.MaxArrID, 1763);
        }
Example #5
0
        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());
            }
        }
Example #6
0
        public void CellAreaTest()
        {
            UnitGroup       ug  = new UnitGroup(VolumeUnit.CubicMeter, AreaUnit.SquareMeter, LengthUnit.Meter, LengthUnit.Meter);
            ExtentRectangle rA2 = new ExtentRectangle(new FileInfo(DirHelpers.GetTestRasterPath("Slopey980-950.tif")));

            Assert.AreEqual(rA2.CellArea(ug).SquareMeters, 0.01, 0.000000000001);
        }
Example #7
0
        public void RelativeId()
        {
            ExtentRectangle rTest1 = new ExtentRectangle(4, 6, -1, 1, 10, 10);
            ExtentRectangle rTest2 = new ExtentRectangle(5, 3, -1, 1, 8, 8);

            Assert.AreEqual(rTest1.RelativeId(0, rTest1), 0);
            Assert.AreEqual(rTest1.RelativeId(0, rTest2), 11);
            Assert.AreEqual(rTest2.RelativeId(0, rTest1), -1);
            Assert.AreEqual(rTest2.RelativeId(0, rTest2), 0);

            Assert.AreEqual(rTest1.RelativeId(1, rTest1), 1);
            Assert.AreEqual(rTest1.RelativeId(1, rTest2), 12);
            Assert.AreEqual(rTest2.RelativeId(1, rTest1), -1);
            Assert.AreEqual(rTest2.RelativeId(1, rTest2), 1);

            Assert.AreEqual(rTest1.RelativeId(24, rTest1), 24);
            Assert.AreEqual(rTest1.RelativeId(24, rTest2), 31);
            Assert.AreEqual(rTest2.RelativeId(24, rTest1), -1);
            Assert.AreEqual(rTest2.RelativeId(24, rTest2), 24);

            Assert.AreEqual(rTest1.RelativeId(25, rTest1), 25);
            Assert.AreEqual(rTest1.RelativeId(25, rTest2), -1);
            Assert.AreEqual(rTest2.RelativeId(25, rTest1), -1);
            Assert.AreEqual(rTest2.RelativeId(25, rTest2), 25);

            Assert.AreEqual(rTest1.RelativeId(99, rTest1), 99);
            Assert.AreEqual(rTest1.RelativeId(99, rTest2), -1);
            Assert.AreEqual(rTest2.RelativeId(99, rTest1), -1);
            Assert.AreEqual(rTest2.RelativeId(99, rTest2), -1);
        }
Example #8
0
 public FakeRaster(int Top, int Left, decimal cellHeight, decimal cellWidth, U[,] grid) :
     base(0, 0, -0.1m, 0.1m, grid.GetLength(1), grid.GetLength(0),
          Conversion.MinValueDouble <U>(), Raster.RasterDriver.GTiff, floatType, fakeproj, fakeunit)
 {
     _inputgrid  = grid;
     Extent      = new ExtentRectangle(Top, Left, cellHeight, cellWidth, grid.GetLength(0), grid.GetLength(1));
     _outputGrid = new U[grid.GetLength(0), grid.GetLength(1)];
     _outputGrid.Fill <U>(NodataValue <U>());
 }
Example #9
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="rInput"></param>
 /// <param name="rOutputRaster"></param>
 /// <param name="newRect"></param>
 public ExtendedCopy(Raster rInput, Raster rOutputRaster, ExtentRectangle newRect) :
     base(new List <Raster> {
     rInput
 }, new List <Raster> {
     rOutputRaster
 })
 {
     SetOpExtent(newRect);
 }
Example #10
0
 public TestCBCOp(List <Raster> rRasters, Raster rOutputRaster, ExtentRectangle newExtent) : base(rRasters, new List <Raster> {
     rOutputRaster
 })
 {
     SetOpExtent(newExtent);
     Assert.AreEqual(rRasters.Count, _inputRasters.Count);
     Assert.AreEqual(1, _outputRasters.Count);
     Assert.IsFalse(OpDone);
 }
Example #11
0
 public void BuildPyramidsInterfaceTest()
 {
     using (ITempDir tmp = TempDir.Create())
     {
         Raster          rTempl          = new Raster(new FileInfo(DirHelpers.GetTestRasterPath("AngledSlopey950-980E.tif")));
         ExtentRectangle newExtReal      = rTempl.Extent.Buffer(15);
         Raster          rTemplateOutput = RasterOperators.ExtendedCopy(rTempl, new FileInfo(Path.Combine(tmp.Name, "PyramidTest.tif")), newExtReal);
         RasterOperators.BuildPyramids(new FileInfo(Path.Combine(tmp.Name, "PyramidTest.tif")));
     }
 }
Example #12
0
        public void RowCol2IdTest()
        {
            ExtentRectangle rTest1 = new ExtentRectangle(5, 6, -1, 1, 100, 100);

            Assert.AreEqual(rTest1.RowCol2Id(2, 3), 102);
            Assert.AreEqual(rTest1.RowCol2Id(1, 1), 0);
            Assert.AreEqual(rTest1.RowCol2Id(1, 2), 1);
            Assert.AreEqual(rTest1.RowCol2Id(2, 1), 100);
            Assert.AreEqual(rTest1.RowCol2Id(100, 100), 9999);
        }
        public override ExtentAdjusterBase AdjustDimensions(decimal top, decimal right, decimal bottom, decimal left)
        {
            int rows = (int)Utility.DynamicMath.SafeDivision(Math.Max(top - bottom, 0), OutExtent.CellWidth);
            int cols = (int)Utility.DynamicMath.SafeDivision(Math.Max(right - left, 0), OutExtent.CellWidth);

            ExtentRectangle rawExtent = new ExtentRectangle(top, left, OutExtent.CellHeight, OutExtent.CellWidth, rows, cols);
            ExtentRectangle divExtent = rawExtent.GetDivisibleExtent();

            return(new ExtentAdjusterNoReference(SrcExtent, divExtent, Precision));
        }
        public override ExtentAdjusterBase AdjustCellSize(decimal cellSize)
        {
            ExtentRectangle rawExtent = new ExtentRectangle(OutExtent);

            rawExtent.CellWidth  = cellSize;
            rawExtent.CellHeight = OutExtent.CellHeight < 0 ? cellSize * -1m : cellSize;
            ExtentRectangle divExtent = rawExtent.GetDivisibleExtent();

            return(new ExtentAdjusterNoReference(SrcExtent, divExtent, Precision));
        }
Example #15
0
        private readonly decimal fx; // old cell width / new cellwidth

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="rInput"></param>
        /// <param name="newRect"></param>
        /// <param name="rOutputRaster"></param>
        public BilinearResample(Raster rInput, ExtentRectangle newRect, Raster rOutputRaster) :
            base(new List <Raster> {
            rInput
        }, rOutputRaster)
        {
            fy = rInput.Extent.CellHeight / newRect.CellHeight;
            fx = rInput.Extent.CellWidth / newRect.CellWidth;

            SetOpExtent(newRect);
        }
Example #16
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="srcextent">Extent of the source raster that is being adjusted</param>
        public ExtentAdjusterBase(ExtentRectangle srcextent)
        {
            _SrcExtent   = srcextent;
            _numDecimals = GetInitialNumDecimals(srcextent.CellWidth);

            ExtentRectangle temp = new ExtentRectangle(srcextent);

            temp.CellWidth  = Math.Round(srcextent.CellWidth, _numDecimals);
            temp.CellHeight = temp.CellWidth * (srcextent.CellHeight < 0 ? -1m : 1m);
            _OutExtent      = temp.GetDivisibleExtent();
        }
Example #17
0
        /// <summary>
        /// Just a simple init function to put all the pieces we want in place
        /// </summary>
        /// <param name="rOutRaster"></param>
        /// <param name="newExt"></param>
        private void _init(List <Raster> rRasters, List <Raster> rOutputRasters)
        {
            chunkRows = 10;
            _vOffset  = 0;

            _lastStatusInvoke = Stopwatch.StartNew();

#if DEBUG
            tmr_overall      = Stopwatch.StartNew();
            tmr_rasterread   = new Stopwatch();
            tmr_rasterwrite  = new Stopwatch();
            tmr_calculations = new Stopwatch();
            num_reads        = 0;
            num_writes       = 0;
            num_calcs        = 0;
#endif

            OpDone = false;

            if (rRasters.Count > 0)
            {
                InExtent = rRasters[0].Extent;

                // Do a union on the inputextent
                foreach (Raster rRa in rRasters)
                {
                    AddInputRaster(rRa);
                }
            }
            else if (rOutputRasters.Count > 0)
            {
                InExtent = rOutputRasters[0].Extent;
            }

            if (rOutputRasters.Count > 0)
            {
                // Do a union on the inputextent
                foreach (Raster rRout in rOutputRasters)
                {
                    AddOutputRaster(rRout);
                }
            }
            else
            {
                // Sometimes we need an output nodataval even when we don't have an output raster
                // (think FIS for error rasters
                outNodataVals.Add(rRasters[0].NodataValue <T>());
            }

            // Last thing we do is set the nodata value (which is suprisingly hard to do)
            SetNodataValue();

            StateChange(OpStatus.States.Initialized);
        }
Example #18
0
        public void ExtentRectangleTest()
        {
            ExtentRectangle rA2 = new ExtentRectangle(new FileInfo(DirHelpers.GetTestRasterPath("Slopey980-950.tif")));

            Assert.AreEqual(rA2.Top, -10019.0m);
            Assert.AreEqual(rA2.Bottom, -10029.0m);
            Assert.AreEqual(rA2.Left, -9979.0m);
            Assert.AreEqual(rA2.Right, -9969.0m);
            Assert.AreEqual(rA2.Rows, 100);
            Assert.AreEqual(rA2.Cols, 100);

            Assert.AreEqual(rA2.CellHeight, -0.1m);
            Assert.AreEqual(rA2.CellWidth, 0.1m);
            Assert.AreEqual(rA2.Height, 10.0m);
            Assert.AreEqual(rA2.Width, 10.0m);
            Assert.AreEqual(rA2.MaxArrID, 9999);

            CollectionAssert.AreEqual(rA2.Transform, new double[6] {
                -9979, 0.1, 0, -10019, 0, -0.1
            });

            // Now let's try a copy constructor
            ExtentRectangle rA1 = new ExtentRectangle(rA2);

            Assert.AreEqual(rA2.Top, rA1.Top);
            Assert.AreEqual(rA2.Bottom, rA1.Bottom);
            Assert.AreEqual(rA2.Left, rA1.Left);
            Assert.AreEqual(rA2.Right, rA1.Right);
            Assert.AreEqual(rA2.Rows, rA1.Rows);
            Assert.AreEqual(rA2.Cols, rA1.Cols);

            Assert.AreEqual(rA2.CellHeight, rA1.CellHeight);
            Assert.AreEqual(rA2.CellWidth, rA1.CellWidth);
            Assert.AreEqual(rA2.Height, rA1.Height);
            Assert.AreEqual(rA2.Width, rA1.Width);
            Assert.AreEqual(rA2.MaxArrID, rA1.MaxArrID);

            // Now try the manual constructor
            ExtentRectangle rA3 = new ExtentRectangle(5, 6, -1, 1, 100, 94);

            Assert.AreEqual(rA3.Top, 5.0m);
            Assert.AreEqual(rA3.Bottom, -95.0m);
            Assert.AreEqual(rA3.Left, 6.0m);
            Assert.AreEqual(rA3.Right, 100.0m);
            Assert.AreEqual(rA3.Rows, 100);
            Assert.AreEqual(rA3.Cols, 94);

            Assert.AreEqual(rA3.CellHeight, -1m);
            Assert.AreEqual(rA3.CellWidth, 1m);
            Assert.AreEqual(rA3.Height, 100.0m);
            Assert.AreEqual(rA3.Width, 94.0m);
            Assert.AreEqual(rA3.MaxArrID, 9399);
        }
Example #19
0
        /// <summary>
        /// Sometimes we want to add an output raster after the constructor has been called
        /// </summary>
        /// <param name="rOutput"></param>
        protected void AddOutputRaster(Raster rOutput)
        {
            if (_outputRasters.Count > 1)
            {
                Raster.ValidateSameMeta(_outputRasters[0], rOutput);
            }

            _outputRasters.Add(rOutput);
            outNodataVals.Add(rOutput.NodataValue <T>());

            InExtent = InExtent.Union(rOutput.Extent);
        }
Example #20
0
        public void BilinearResampleTest()
        {
            using (ITempDir tmp = TempDir.Create())
            {
                Raster          rTempl     = new Raster(new FileInfo(DirHelpers.GetTestRasterPath("AngledSlopey950-980E.tif")));
                ExtentRectangle newExtReal = new ExtentRectangle(rTempl.Extent);
                newExtReal.CellHeight = newExtReal.CellHeight * 2;
                newExtReal.CellWidth  = newExtReal.CellWidth * 2;

                Raster rTemplateOutput = RasterOperators.BilinearResample(rTempl, new FileInfo(Path.Combine(tmp.Name, "BilinearResample.tif")), newExtReal);
                Debug.WriteLine("Test Done");
            }
        }
Example #21
0
        /// <summary>
        /// Sometimes we want to add an input raster after the constructor has been called
        /// </summary>
        /// <param name="rInput"></param>
        protected void AddInputRaster(Raster rInput)
        {
            if (_inputRasters.Count > 1)
            {
                Raster.ValidateSameMeta(_inputRasters[0], rInput, true);
            }

            _inputRasters.Add(rInput);
            inNodataVals.Add(rInput.NodataValue <T>());

            InExtent = InExtent.Union(rInput.Extent);
            rInput.Open();
        }
Example #22
0
        /// <summary>
        /// Chunk op implementation
        /// </summary>
        /// <param name="data"></param>
        /// <param name="outChunk"></param>
        protected override void ChunkOp(List <double[]> data, List <double[]> outBuffers)
        {
            // Get all the points in this chunk
            VectorChunkExtent       = ChunkExtent.Buffer(_fsizedec);
            List <Geometry>[,] bins = BinPoints(_vinput.GeometriesIntersectExtent(VectorChunkExtent));

            for (int cid = 0; cid < outBuffers[0].Length; cid++)
            {
                // Save us a metric Tonne of effort by giving up on nodatavals in the DEM
                if (data[0][cid] == inNodataVals[0])
                {
                    outBuffers[0][cid] = outNodataVals[0];
                }
                else
                {
                    double outval = 0;

                    decimal[] cidxy = ChunkExtent.Id2XY(cid);
                    Geometry  pt2   = new Geometry(wkbGeometryType.wkbPoint);
                    pt2.AddPoint((double)cidxy[0], (double)cidxy[1], 0);

                    List <int[]> bins2test = GetRelevantBins(pt2);

                    // create a circle and then buffer it.
                    foreach (int[] binids in bins2test)
                    {
                        if (binids[0] < bins.GetLength(0) && binids[1] < bins.GetLength(1))
                        {
                            foreach (Geometry pt in bins[binids[0], binids[1]])
                            {
                                // If we're a circle we have to do a more expensive operation now
                                if (_kshape == RasterOperators.KernelShapes.Circle)
                                {
                                    if (InsideRadius(pt, pt2))
                                    {
                                        outval++;
                                    }
                                }
                                else if (InsideSquare(pt, pt2))
                                {
                                    outval++;
                                }
                            }
                        }
                    }
                    outBuffers[0][cid] = outval / area;
                }
            }
        }
Example #23
0
        public void GetTranslationTest()
        {
            ExtentRectangle rA1 = new ExtentRectangle(0, 0, -1, 1, 30, 30);
            ExtentRectangle rA2 = new ExtentRectangle(3, 2, -1, 1, 30, 30);

            // Returns (x,y) ==> (col,row)
            int[] tr1 = rA1.GetTranslation(rA2);
            int[] tr2 = rA2.GetTranslation(rA1);

            Assert.AreEqual(tr1[0], 2);
            Assert.AreEqual(tr1[1], 3);

            Assert.AreEqual(tr2[0], -tr1[0]);
            Assert.AreEqual(tr2[1], -tr1[1]);
        }
Example #24
0
        public void IsConcurrentTest()
        {
            ExtentRectangle rA1   = new ExtentRectangle(5, 6, -1, 1, 100, 100);
            ExtentRectangle rYES1 = new ExtentRectangle(5, 6, -1, 1, 100, 100);
            ExtentRectangle rNo1  = new ExtentRectangle(4, 6, -1, 1, 100, 100);
            ExtentRectangle rNo2  = new ExtentRectangle(5, 5, -1, 1, 100, 100);
            ExtentRectangle rNo3  = new ExtentRectangle(5, 6, 1, 1, 100, 100);
            ExtentRectangle rNo4  = new ExtentRectangle(5, 6, -1, -1, 100, 100);

            Assert.IsTrue(rA1.IsConcurrent(rYES1));
            Assert.IsFalse(rA1.IsConcurrent(rNo1));
            Assert.IsFalse(rA1.IsConcurrent(rNo2));
            Assert.IsFalse(rA1.IsConcurrent(rNo3));
            Assert.IsFalse(rA1.IsConcurrent(rNo4));
        }
Example #25
0
        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 override ExtentAdjusterBase AdjustPrecision(ushort precision)
        {
            decimal rawCellWidth  = (decimal)Math.Round((double)OutExtent.CellWidth, precision);
            decimal rawCellHeight = (decimal)Math.Round((double)OutExtent.CellHeight, precision);

            // Abort if f the new precision causes the cell width or height to be zero.
            // e.g. cell width is 0.5 and the user passes precision 0
            if (rawCellWidth == 0m || rawCellHeight == 0m)
            {
                return(this);
            }

            ExtentRectangle rawExtent = new ExtentRectangle(OutExtent.Top, OutExtent.Left, rawCellHeight, rawCellWidth, OutExtent.Rows, OutExtent.Cols);
            ExtentRectangle divExtent = rawExtent.GetDivisibleExtent();

            return(new ExtentAdjusterNoReference(SrcExtent, divExtent, precision));
        }
Example #27
0
        public void IsOrthogonalTest()
        {
            ExtentRectangle rA1 = new ExtentRectangle(5, 6, -1, 1, 100, 100);
            ExtentRectangle rB1 = new ExtentRectangle(1, 3.0m, -1, 1, 100, 100);
            ExtentRectangle rC1 = new ExtentRectangle(2, 7, -1, 1, 100, 100);
            ExtentRectangle rD1 = new ExtentRectangle(4.1m, 6.0m, -1, 1, 100, 100);

            Assert.AreEqual(rA1.MaxArrID, 9999);

            // Positive Tests
            Assert.IsTrue(rA1.IsOrthogonal(rA1));
            Assert.IsTrue(rA1.IsOrthogonal(rB1) && rB1.IsOrthogonal(rA1));
            Assert.IsTrue(rA1.IsOrthogonal(rC1) && rC1.IsOrthogonal(rA1));

            // Negative Tests
            Assert.IsFalse(rA1.IsOrthogonal(rD1) || rD1.IsOrthogonal(rA1));
        }
Example #28
0
        /// <summary>
        /// Sometimes we want to enforce the extent even though it calculates automatically.
        /// </summary>
        /// <param name="newRect"></param>
        protected void SetOpExtent(ExtentRectangle newRect)
        {
            OpExtent = newRect;

            // Now initialize our window rectangle
            int chunkXsize = OpExtent.Cols;
            int chunkYsize = chunkRows;

            if (OpExtent.Rows < chunkYsize)
            {
                chunkYsize = OpExtent.Rows;
            }
            ChunkExtent = new ExtentRectangle(OpExtent.Top, OpExtent.Left, OpExtent.CellHeight, OpExtent.CellWidth, chunkYsize, chunkXsize);

            foreach (Raster outraster in _outputRasters)
            {
                outraster.Extent = OpExtent;
            }
        }
Example #29
0
        public void IntersectTest()
        {
            ExtentRectangle rA1 = new ExtentRectangle(0, 0, -1, 1, 30, 30);
            ExtentRectangle rA2 = new ExtentRectangle(20, 20, -1, 1, 30, 30);

            ExtentRectangle rTest = rA1.Intersect(rA2);

            Assert.AreEqual(rTest.Top, 0.0m);
            Assert.AreEqual(rTest.Bottom, -10.0m);
            Assert.AreEqual(rTest.Left, 20.0m);
            Assert.AreEqual(rTest.Right, 30.0m);
            Assert.AreEqual(rTest.Rows, 10);
            Assert.AreEqual(rTest.Cols, 10);

            Assert.AreEqual(rTest.CellHeight, -1m);
            Assert.AreEqual(rTest.CellWidth, 1m);
            Assert.AreEqual(rTest.Height, 10.0m);
            Assert.AreEqual(rTest.Width, 10.0m);
            Assert.AreEqual(rTest.MaxArrID, 99);
        }
Example #30
0
        public void Id2RowColTest()
        {
            ExtentRectangle rTest1 = new ExtentRectangle(5, 6, -1, 1, 100, 50);

            CollectionAssert.AreEqual(rTest1.Id2RowCol(52), new int[2] {
                2, 3
            });
            CollectionAssert.AreEqual(rTest1.Id2RowCol(0), new int[2] {
                1, 1
            });
            CollectionAssert.AreEqual(rTest1.Id2RowCol(1), new int[2] {
                1, 2
            });
            CollectionAssert.AreEqual(rTest1.Id2RowCol(100), new int[2] {
                3, 1
            });
            CollectionAssert.AreEqual(rTest1.Id2RowCol(4999), new int[2] {
                100, 50
            });
        }