Beispiel #1
0
        public void CreateBilFileFromRegularGrid()
        {
            var gdalFunctionStore = new GdalFunctionStore();

            var gridCoverage = new RegularGridCoverage();

            gridCoverage.Components.Clear();
            var newComponent = new Variable <float>();

            gridCoverage.Components.Add(newComponent);


            gridCoverage.Resize(3, 2, 10, 20, new Coordinate(200, 2000));

            //create a sequence of numbers: 1 , 2, 3, 4, 5, 6,
            var originalValues = new float[] { 1, 2, 3, 4, 5, 6 };

            gridCoverage.SetValues(originalValues);
            string path = TestHelper.GetCurrentMethodName() + ".bil";

            //TODO: get rid of this strang method.
            //do store.CreateNew(path)
            //   store.Functions.Add(gridCoverage)
            //this is more like the other stores
            gdalFunctionStore.CreateNew(path);
            gdalFunctionStore.Functions.Add(gridCoverage);


            var clone = gdalFunctionStore.Grid;

            Assert.AreEqual(gdalFunctionStore, clone.Store);
            Assert.IsTrue(originalValues.SequenceEqual(gdalFunctionStore.GetVariableValues <float>(clone.Components[0])));
            //replace data in first column
            clone.SetValues(new float[] { 0, 0 }, new VariableValueFilter <double>(clone.X, new double[] { 200 }));
            Assert.IsTrue(new float[] { 0, 2, 3, 0, 5, 6 }.SequenceEqual(gdalFunctionStore.GetVariableValues <float>(clone.Components[0])));

            Assert.AreEqual(2000, clone.Origin.Y);
            Assert.AreEqual(200, clone.Origin.X);
            Assert.AreEqual(3, clone.SizeX);
            Assert.AreEqual(2, clone.SizeY);
            Assert.AreEqual(10, clone.DeltaX);
            Assert.AreEqual(20, clone.DeltaY);
            gdalFunctionStore.Close();


            gdalFunctionStore = new GdalFunctionStore();
            //reread file to see wether it contains the right data.
            gdalFunctionStore.Open(path);
            var grid = (IRegularGridCoverage)gdalFunctionStore.Functions.First(f => f is IRegularGridCoverage);

            Assert.IsTrue(new float[] { 0, 2, 3, 0, 5, 6 }.SequenceEqual(gdalFunctionStore.GetVariableValues <float>(grid.Components[0])));
            Assert.AreEqual(2000, grid.Origin.Y);
            Assert.AreEqual(200, grid.Origin.X);
            Assert.AreEqual(3, grid.SizeX);
            Assert.AreEqual(2, grid.SizeY);
            Assert.AreEqual(10, grid.DeltaX);
            Assert.AreEqual(20, grid.DeltaY);
        }
        public void ResizeIsFast()
        {
            //TODO: make this really fast by optimizing resize...
            IRegularGridCoverage grid = new RegularGridCoverage();

            TestHelper.AssertIsFasterThan(431, "Resized to 1000x1000", () => grid.Resize(1000, 1000, 1, 1));

            Assert.AreEqual(1000000, grid.Components[0].Values.Count);
            log.InfoFormat("This is still toooooo slow!");
        }
        public void Resize()
        {
            var originalGrid = new RegularGridCoverage(2, 2, 5, 5);

            originalGrid.Resize(2, 4, 8, 16, new Coordinate(10, 100));
            Assert.AreEqual(2, originalGrid.SizeX);
            Assert.AreEqual(4, originalGrid.SizeY);
            Assert.AreEqual(8, originalGrid.DeltaX);
            Assert.AreEqual(16, originalGrid.DeltaY);
            Assert.AreEqual(10, originalGrid.X.Values[0]);
            Assert.AreEqual(100, originalGrid.Y.Values[0]);
        }
        public void ResizeAndAddTime()
        {
            var coverage = new RegularGridCoverage()
            {
                IsTimeDependent = true
            };

            coverage.Resize(2, 2, 1, 1);
            coverage.SetValues(new double[4] {
                0.0, 0.0, 0.0, 0.0
            }, new VariableValueFilter <DateTime>(coverage.Time, DateTime.Now));
        }
        public void ResizeSetsDefaultValues()
        {
            IRegularGridCoverage grid = new RegularGridCoverage();

            grid.Components[0].DefaultValue = 5.0;

            grid.Resize(10, 10, 1, 1);

            //check the values
            var variable = (IVariable <double>)grid.Components[0];

            Assert.IsTrue(variable.Values.All(v => v == 5.0));
        }
Beispiel #6
0
        public void CreateTiffFileFromRegularGrid()
        {
            var gdalFunctionStore = new GdalFunctionStore();


            var gridCoverage = new RegularGridCoverage();

            gridCoverage.Resize(3, 2, 10, -20, new Coordinate(200, 2000));
            gridCoverage.Components.RemoveAt(0);
            gridCoverage.Components.Add(new Variable <float>());


            var inputData = new float[] { 1, 2, 3, 4, 5, 6 };

            gridCoverage.SetValues(inputData);
            const string path = "CreateTiffFileFromRegularGrid.tiff";

            gdalFunctionStore.CreateNew(path);
            gdalFunctionStore.Functions.Add(gridCoverage);
            gdalFunctionStore.Close();

            gdalFunctionStore = new GdalFunctionStore();
            //reread file to see wether it contains the right data.
            gdalFunctionStore.Open(path);
            var grid = (IRegularGridCoverage)gdalFunctionStore.Functions.First(f => f is IRegularGridCoverage);

            Assert.IsTrue(inputData.SequenceEqual(gdalFunctionStore.GetVariableValues <float>(grid.Components[0])));
            Assert.AreEqual(gridCoverage.Origin.Y, grid.Origin.Y);
            Assert.AreEqual(gridCoverage.Origin.X, grid.Origin.X);
            Assert.AreEqual(gridCoverage.SizeX, grid.SizeX);
            Assert.AreEqual(gridCoverage.SizeY, grid.SizeY);
            Assert.AreEqual(gridCoverage.DeltaX, grid.DeltaX);
            Assert.AreEqual(gridCoverage.DeltaY, grid.DeltaY);
            //updating tiff file
            //values before: 2,5

            // TODO: make it readable!
            Assert.IsTrue((new float[] { 2, 5 }).SequenceEqual(gdalFunctionStore.GetVariableValues <float>(grid.Components[0],
                                                                                                           new VariableValueFilter <double>(
                                                                                                               grid.X,
                                                                                                               new double[] { 210 }))));
            grid.SetValues(new[] { 0, 10.5f }, new VariableValueFilter <double>(grid.X, new double[] { 210 }));
            //values after: 0,10
            Assert.IsTrue(
                (new[] { 0, 10.5f }).SequenceEqual(gdalFunctionStore.GetVariableValues <float>(grid.Components[0],
                                                                                               new VariableValueFilter <double>(grid.X,
                                                                                                                                new double[]
                                                                                                                                { 210 }))));
        }
        public void RegularGridResize()
        {
            IRegularGridCoverage regularGridCoverage = new RegularGridCoverage();

            regularGridCoverage.Resize(100, 50, 10, 20);
            Assert.AreEqual(100, regularGridCoverage.X.Values.Count);
            Assert.AreEqual(0, regularGridCoverage.X.Values[0]);
            Assert.AreEqual(10, regularGridCoverage.X.Values[1]);
            Assert.AreEqual(990, regularGridCoverage.X.Values[99]);

            Assert.AreEqual(50, regularGridCoverage.Y.Values.Count);
            Assert.AreEqual(0, regularGridCoverage.Y.Values[0]);
            Assert.AreEqual(20, regularGridCoverage.Y.Values[1]);
            Assert.AreEqual(980, regularGridCoverage.Y.Values[49]);
        }
Beispiel #8
0
        public void ResizeIsFast()
        {
            IRegularGridCoverage grid = new RegularGridCoverage();
            var startTime             = DateTime.Now;

            grid.Resize(1000, 1000, 1, 1);
            var stoptime = DateTime.Now;
            var dt       = (stoptime - startTime).TotalMilliseconds;

            Console.WriteLine(dt);

            Assert.Less(dt, 1550); // <<< DON'T INCREASE UNLESS THERE IS REALLY NO OTHER CHOICE (REQUIREMENTS CHANGED)

            Assert.AreEqual(1000000, grid.Components[0].Values.Count);
            log.InfoFormat("Resized to 1000x1000 in {0}", dt);
            log.InfoFormat("This is still toooooo slow!");
        }
        private static RegularGridCoverage GetCoverageWithDataIn2000And2002And2004()
        {
            var t2000 = new DateTime(2000, 1, 1);
            var t2002 = new DateTime(2002, 1, 1);
            var t2004 = new DateTime(2004, 1, 1);
            var coverage = new RegularGridCoverage { IsTimeDependent = true };
            var timeArgument = coverage.Time;
            coverage.Resize(2, 2, 1, 1);
            //set 0,0,0,0 in slice 2000
            coverage.SetValues(new double[] { 0, 0, 0, 0 }, new VariableValueFilter<DateTime>(timeArgument, t2000));
            //set 10,10,10,10 in 2002
            coverage.SetValues(new double[] { 10, 10, 10, 10 }, new VariableValueFilter<DateTime>(timeArgument, t2002));
            //set 100,100,100,100 in 2004
            coverage.SetValues(new double[] { 100, 100, 100, 100 }, new VariableValueFilter<DateTime>(timeArgument, t2004));

            return coverage;
        }
Beispiel #10
0
        private static RegularGridCoverage GetCoverageWithDataIn2000And2002And2004()
        {
            var t2000    = new DateTime(2000, 1, 1);
            var t2002    = new DateTime(2002, 1, 1);
            var t2004    = new DateTime(2004, 1, 1);
            var coverage = new RegularGridCoverage {
                IsTimeDependent = true
            };
            var timeArgument = coverage.Time;

            coverage.Resize(2, 2, 1, 1);
            //set 0,0,0,0 in slice 2000
            coverage.SetValues(new[] { 0, 0, 0, 0 }, new VariableValueFilter <DateTime>(timeArgument, t2000));
            //set 10,10,10,10 in 2002
            coverage.SetValues(new[] { 10, 10, 10, 10 }, new VariableValueFilter <DateTime>(timeArgument, t2002));
            //set 100,100,100,100 in 2004
            coverage.SetValues(new[] { 100, 100, 100, 100 }, new VariableValueFilter <DateTime>(timeArgument, t2004));

            return(coverage);
        }
Beispiel #11
0
        public void CreateAscFileFromRegularGridUsingFloatValueType()
        {
            var gridCoverage = new RegularGridCoverage();

            gridCoverage.Components.Clear();
            gridCoverage.Components.Add(new Variable <float>());

            gridCoverage.Resize(3, 3, 20, 20, new Coordinate(50, 70));

            var inputData = new[] { 1.0f, 2.0f, 3.5f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f };

            gridCoverage.SetValues(inputData);

            var path = TestHelper.GetCurrentMethodName() + ".asc";

            var store = new GdalFunctionStore();

            store.CreateNew(path);
            store.Functions.Add(gridCoverage);
            store.Close();

            // reread file to see wether it contains the right data.
            store = new GdalFunctionStore();
            store.Open(path);
            var grid = store.Grid;

            grid.Components[0].GetValues <float>()
            .Should().Have.SameSequenceAs(new float[] { 1.0f, 2.0f, 3.5f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f });

            Assert.AreEqual(gridCoverage.Origin.Y, grid.Origin.Y);
            Assert.AreEqual(gridCoverage.Origin.X, grid.Origin.X);
            Assert.AreEqual(gridCoverage.SizeX, grid.SizeX);
            Assert.AreEqual(gridCoverage.SizeY, grid.SizeY);
            Assert.AreEqual(gridCoverage.DeltaX, grid.DeltaX);
            Assert.AreEqual(gridCoverage.DeltaY, grid.DeltaY);
        }
 public void ResizeAndAddTime()
 {
     var coverage = new RegularGridCoverage() {IsTimeDependent = true};
     coverage.Resize(2,2,1,1);
     coverage.SetValues(new double[4]{0.0,0.0,0.0,0.0},new VariableValueFilter<DateTime>(coverage.Time,DateTime.Now));
 }
 public void Resize()
 {
     var originalGrid = new RegularGridCoverage(2, 2, 5, 5);
     originalGrid.Resize(2, 4, 8, 16, new Coordinate(10, 100));
     Assert.AreEqual(2, originalGrid.SizeX);
     Assert.AreEqual(4, originalGrid.SizeY);
     Assert.AreEqual(8, originalGrid.DeltaX);
     Assert.AreEqual(16, originalGrid.DeltaY);
     Assert.AreEqual(10, originalGrid.X.Values[0]);
     Assert.AreEqual(100, originalGrid.Y.Values[0]);
 }
        public void RegularGridResize()
        {
            IRegularGridCoverage regularGridCoverage = new RegularGridCoverage();
            regularGridCoverage.Resize(100, 50, 10, 20);
            Assert.AreEqual(100, regularGridCoverage.X.Values.Count);
            Assert.AreEqual(0, regularGridCoverage.X.Values[0]);
            Assert.AreEqual(10, regularGridCoverage.X.Values[1]);
            Assert.AreEqual(990, regularGridCoverage.X.Values[99]);

            Assert.AreEqual(50, regularGridCoverage.Y.Values.Count);
            Assert.AreEqual(0, regularGridCoverage.Y.Values[0]);
            Assert.AreEqual(20, regularGridCoverage.Y.Values[1]);
            Assert.AreEqual(980, regularGridCoverage.Y.Values[49]);
        }
        public void ResizeIsFast()
        {
            //TODO: make this really fast by optimizing resize...
            IRegularGridCoverage grid = new RegularGridCoverage();

            TestHelper.AssertIsFasterThan(431, "Resized to 1000x1000", () => grid.Resize(1000, 1000, 1, 1));

            Assert.AreEqual(1000000, grid.Components[0].Values.Count);
            log.InfoFormat("This is still toooooo slow!");
        }
 public void ResizeSetsDefaultValues()
 {
     IRegularGridCoverage grid = new RegularGridCoverage();
     grid.Components[0].DefaultValue = 5.0;
     
     grid.Resize(10, 10, 1, 1);
     
     //check the values
     var variable = (IVariable<double>)grid.Components[0];
     Assert.IsTrue(variable.Values.All(v=>v== 5.0));
 }
        public void CreateBilFileFromRegularGrid()
        {
            var gdalFunctionStore = new GdalFunctionStore();

            var gridCoverage = new RegularGridCoverage();

            gridCoverage.Components.Clear();
            var newComponent = new Variable<float>();
            gridCoverage.Components.Add(newComponent);


            gridCoverage.Resize(3, 2, 10, 20, new Coordinate(200, 2000));

            //create a sequence of numbers: 1 , 2, 3, 4, 5, 6,
            var originalValues = new float[] {1, 2, 3, 4, 5, 6};
            gridCoverage.SetValues(originalValues);
            string path = TestHelper.GetCurrentMethodName() + ".bil";

            //TODO: get rid of this strang method.
            //do store.CreateNew(path)
            //   store.Functions.Add(gridCoverage)
            //this is more like the other stores
            gdalFunctionStore.CreateNew(path);
            gdalFunctionStore.Functions.Add(gridCoverage);


            var clone = gdalFunctionStore.Grid;
            Assert.AreEqual(gdalFunctionStore, clone.Store);
            Assert.IsTrue(originalValues.SequenceEqual(gdalFunctionStore.GetVariableValues<float>(clone.Components[0])));
            //replace data in first column
            clone.SetValues(new float[] { 0, 0 }, new VariableValueFilter<double>(clone.X, new double[] { 200 }));
            Assert.IsTrue(new float[] {0, 2, 3, 0, 5, 6}.SequenceEqual(gdalFunctionStore.GetVariableValues<float>(clone.Components[0])));

            Assert.AreEqual(2000, clone.Origin.Y);
            Assert.AreEqual(200, clone.Origin.X);
            Assert.AreEqual(3, clone.SizeX);
            Assert.AreEqual(2, clone.SizeY);
            Assert.AreEqual(10, clone.DeltaX);
            Assert.AreEqual(20, clone.DeltaY);
            gdalFunctionStore.Close();


            gdalFunctionStore = new GdalFunctionStore();
            //reread file to see wether it contains the right data.
            gdalFunctionStore.Open(path);
            var grid = (IRegularGridCoverage) gdalFunctionStore.Functions.First(f => f is IRegularGridCoverage);
            Assert.IsTrue(new float[] {0, 2, 3, 0, 5, 6}.SequenceEqual(gdalFunctionStore.GetVariableValues<float>(grid.Components[0])));
            Assert.AreEqual(2000, grid.Origin.Y);
            Assert.AreEqual(200, grid.Origin.X);
            Assert.AreEqual(3, grid.SizeX);
            Assert.AreEqual(2, grid.SizeY);
            Assert.AreEqual(10, grid.DeltaX);
            Assert.AreEqual(20, grid.DeltaY);

        }
        public void CreateTiffFileFromRegularGrid()
        {
            var gdalFunctionStore = new GdalFunctionStore();


            var gridCoverage = new RegularGridCoverage();
            gridCoverage.Resize(3, 2, 10, -20, new Coordinate(200, 2000));
            gridCoverage.Components.RemoveAt(0);
            gridCoverage.Components.Add(new Variable<float>());


            var inputData = new float[] {1, 2, 3, 4, 5, 6};
            gridCoverage.SetValues(inputData);
            const string path = "CreateTiffFileFromRegularGrid.tiff";
            gdalFunctionStore.CreateNew(path);
            gdalFunctionStore.Functions.Add(gridCoverage);
            gdalFunctionStore.Close();

            gdalFunctionStore = new GdalFunctionStore();
            //reread file to see wether it contains the right data.
            gdalFunctionStore.Open(path);
            var grid = (IRegularGridCoverage) gdalFunctionStore.Functions.First(f => f is IRegularGridCoverage);
            Assert.IsTrue(inputData.SequenceEqual(gdalFunctionStore.GetVariableValues<float>(grid.Components[0])));
            Assert.AreEqual(gridCoverage.Origin.Y, grid.Origin.Y);
            Assert.AreEqual(gridCoverage.Origin.X, grid.Origin.X);
            Assert.AreEqual(gridCoverage.SizeX, grid.SizeX);
            Assert.AreEqual(gridCoverage.SizeY, grid.SizeY);
            Assert.AreEqual(gridCoverage.DeltaX, grid.DeltaX);
            Assert.AreEqual(gridCoverage.DeltaY, grid.DeltaY);
            //updating tiff file
            //values before: 2,5
            
            // TODO: make it readable!
            Assert.IsTrue((new float[] {2, 5}).SequenceEqual(gdalFunctionStore.GetVariableValues<float>(grid.Components[0],
                                                                                              new VariableValueFilter<double>(
                                                                                                  grid.X,
                                                                                                  new double[] {210}))));
            grid.SetValues(new[] {0, 10.5f}, new VariableValueFilter<double>(grid.X, new double[] {210}));
            //values after: 0,10
            Assert.IsTrue(
                (new[] {0, 10.5f}).SequenceEqual(gdalFunctionStore.GetVariableValues<float>(grid.Components[0],
                                                                                            new VariableValueFilter<double>(grid.X,
                                                                                                                            new double[]
                                                                                                                                {210}))));
        }
        public void CreateAscFileFromRegularGridUsingFloatValueType()
        {
            var gridCoverage = new RegularGridCoverage();
           
            gridCoverage.Components.Clear();
            gridCoverage.Components.Add(new Variable<float>());

            gridCoverage.Resize(3, 3, 20, 20, new Coordinate(50, 70));

            var inputData = new[] {1.0f, 2.0f, 3.5f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f};
            gridCoverage.SetValues(inputData);

            var path = TestHelper.GetCurrentMethodName() + ".asc";

            var store = new GdalFunctionStore();
            store.CreateNew(path);
            store.Functions.Add(gridCoverage);
            store.Close();
            
            // reread file to see wether it contains the right data.
            store = new GdalFunctionStore();
            store.Open(path);
            var grid = store.Grid;

            grid.Components[0].GetValues<float>()
                .Should().Have.SameSequenceAs(new float[] {1.0f, 2.0f, 3.5f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f});

            Assert.AreEqual(gridCoverage.Origin.Y, grid.Origin.Y);
            Assert.AreEqual(gridCoverage.Origin.X, grid.Origin.X);
            Assert.AreEqual(gridCoverage.SizeX, grid.SizeX);
            Assert.AreEqual(gridCoverage.SizeY, grid.SizeY);
            Assert.AreEqual(gridCoverage.DeltaX, grid.DeltaX);
            Assert.AreEqual(gridCoverage.DeltaY, grid.DeltaY);
        }
        public void ResizeIsFast()
        {
            IRegularGridCoverage grid = new RegularGridCoverage();
            var startTime = DateTime.Now;
            grid.Resize(1000, 1000, 1, 1);
            var stoptime = DateTime.Now;
            var dt = (stoptime - startTime).TotalMilliseconds;
            Console.WriteLine(dt);

            Assert.Less(dt, 1550); // <<< DON'T INCREASE UNLESS THERE IS REALLY NO OTHER CHOICE (REQUIREMENTS CHANGED)

            Assert.AreEqual(1000000, grid.Components[0].Values.Count);
            log.InfoFormat("Resized to 1000x1000 in {0}", dt);
            log.InfoFormat("This is still toooooo slow!");
        }