public void CheckEnvelope()
        {
            string filePath = @"..\..\..\..\data\RasterData\Schematisatie.bil";
            GdalFunctionStore store = new GdalFunctionStore
                                                    {
                                                        Path = Path.GetFullPath(filePath)
                                                    };

            IRegularGridCoverage regularGridCoverage = store.Grid;

            Assert.IsNotNull(store);

            //check wether geometry has been updated in the right manner.
            Assert.AreEqual(0, regularGridCoverage.Geometry.Envelope.EnvelopeInternal.MinX, 0.1);
            Assert.AreEqual(60, regularGridCoverage.Geometry.Envelope.EnvelopeInternal.MaxX, 0.1);

            Assert.AreEqual(0, regularGridCoverage.Geometry.Envelope.EnvelopeInternal.MinY, 0.1);
            Assert.AreEqual(60, regularGridCoverage.Geometry.Envelope.EnvelopeInternal.MaxY, 0.1);

            Assert.AreEqual(3, regularGridCoverage.SizeY);
            Assert.AreEqual(3, regularGridCoverage.SizeX);

            
            Assert.AreEqual(20.0, regularGridCoverage.DeltaX, 0.1);
            Assert.AreEqual(-20.0, regularGridCoverage.DeltaY, 0.1);

            //check wether lower left corner lies at (0, 0)
            Assert.AreEqual(0.0, regularGridCoverage.Origin.X, 0.1);
            Assert.AreEqual(60.0, regularGridCoverage.Origin.Y, 0.1);


        }
Пример #2
0
        public void GetInterpolatedValue()
        {
            string path = rasterDataPath + "SchematisatieInt.bil";

            var functionStore = new GdalFunctionStore {
                Path = path
            };

            functionStore.Open();
            var grid = (IRegularGridCoverage)functionStore.Functions.First(f => f is IRegularGridCoverage);

            grid.X.InterpolationType = ApproximationType.Constant;
            grid.X.ExtrapolationType = ApproximationType.Constant;
            grid.Y.InterpolationType = ApproximationType.Constant;
            grid.Y.ExtrapolationType = ApproximationType.Constant;
            var values = new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            var index  = 0;

            for (int j = 0; j < 3; j++)
            {
                for (int i = 0; i < 3; i++)
                {
                    var x = 10.0 + 20 * i;
                    var y = 50.0 - 20 * j;

                    var value = grid.Evaluate <int>(new VariableValueFilter <double>(grid.X, new[] { x }),
                                                    new VariableValueFilter <double>(grid.Y, new[] { y }));
                    Assert.AreEqual(values[index], value);
                    index++;
                }
            }
        }
Пример #3
0
        public void CloneFunctionStoredInGdalFunctionStore()
        {
            var path = TestHelper.GetCurrentMethodName() + ".tif";

            var store = new GdalFunctionStore();

            store.CreateNew(path);

            const int deltaX = 1;
            const int deltaY = 10;
            var       grid   = new RegularGridCoverage(2, 2, deltaX, deltaY);

            grid.SetValues(new[] { 1, 2, 3, 4 });

            store.Functions.Add(grid);

            // create grid clone and check if function and cloned store are correct
            var clonedGrid = (RegularGridCoverage)grid.Clone();

            var clonedStore = (GdalFunctionStore)clonedGrid.Store;

            clonedStore.Functions.Count
            .Should().Be.EqualTo(4);

            clonedStore.Path
            .Should().Be.EqualTo(path);

            clonedGrid.GetValues <double>()
            .Should().Have.SameSequenceAs(new double[] { 1, 2, 3, 4 });
        }
        public void CheckEnvelope()
        {
            string            filePath = @"..\..\..\..\data\RasterData\Schematisatie.bil";
            GdalFunctionStore store    = new GdalFunctionStore
            {
                Path = Path.GetFullPath(filePath)
            };

            IRegularGridCoverage regularGridCoverage = store.Grid;

            Assert.IsNotNull(store);

            //check wether geometry has been updated in the right manner.
            Assert.AreEqual(0, regularGridCoverage.Geometry.Envelope.EnvelopeInternal.MinX, 0.1);
            Assert.AreEqual(60, regularGridCoverage.Geometry.Envelope.EnvelopeInternal.MaxX, 0.1);

            Assert.AreEqual(0, regularGridCoverage.Geometry.Envelope.EnvelopeInternal.MinY, 0.1);
            Assert.AreEqual(60, regularGridCoverage.Geometry.Envelope.EnvelopeInternal.MaxY, 0.1);

            Assert.AreEqual(3, regularGridCoverage.SizeY);
            Assert.AreEqual(3, regularGridCoverage.SizeX);


            Assert.AreEqual(20.0, regularGridCoverage.DeltaX, 0.1);
            Assert.AreEqual(-20.0, regularGridCoverage.DeltaY, 0.1);

            //check wether lower left corner lies at (0, 0)
            Assert.AreEqual(0.0, regularGridCoverage.Origin.X, 0.1);
            Assert.AreEqual(60.0, regularGridCoverage.Origin.Y, 0.1);
        }
Пример #5
0
        public void GetValuesWithSampleFilters()
        {
            //     1     2      3      4      5      6       7     8      9
            //    10     11*    12     13     14*    15     16     17*    18
            //    19     20     21     22     23     24     25     26     27
            //    28     29     30     31     32     33     34     35     36
            //    37     38*    39     40     41*    42     43     44*    45
            //    46     47     48     49     50     51     52     53     54
            //    55     56     57     58     59     60     61     62     63
            //    64     65*    66     67     68*    69     70     71*    72
            //    73     74     75     76     77     78     79     80     81

            string fileName = rasterDataPath + "SchematisatieInt9x9.asc";

            var functionStore = new GdalFunctionStore {
                Path = fileName
            };

            functionStore.Open();
            var grid = (IRegularGridCoverage)functionStore.Functions.First(f => f is IRegularGridCoverage);

            var sampleSize = 3;
            IMultiDimensionalArray <int> values = grid.GetValues <int>(
                new VariableAggregationFilter(grid.X, 4, 0, grid.X.Values.Count - 1),
                new VariableAggregationFilter(grid.Y, 4, 0, grid.Y.Values.Count - 1)
                );

            Assert.AreEqual(sampleSize * sampleSize, values.Count);
            //Assert.AreEqual(new[]{11,14,17,38,41,44,65,68,71}, values.ToArray());
            //Lower Left Corner Based
            Assert.AreEqual(new[] { 65, 68, 71, 38, 41, 44, 11, 14, 17 }, values.ToArray());
        }
Пример #6
0
        public void GetValuesWithVariableValueFilters()
        {
            string fileName      = rasterDataPath + "SchematisatieInt.bil";
            var    functionStore = new GdalFunctionStore {
                Path = fileName
            };

            functionStore.Open();
            var         grid   = (IRegularGridCoverage)functionStore.Functions.First(f => f is IRegularGridCoverage);
            IList <int> values = grid.GetValues <int>(
                new VariableValueFilter <double>(grid.X, grid.X.Values[0]),
                new VariableValueFilter <double>(grid.Y, grid.Y.Values[0])
                );

            Assert.AreEqual(1, values.Count);
            Assert.AreEqual(7, values[0]);

            values = grid.GetValues <int>(
                new VariableValueFilter <double>(grid.X, grid.X.Values[0]));
            Assert.AreEqual(3, values.Count);

            values = grid.GetValues <int>(
                new VariableValueFilter <double>(grid.X, grid.X.Values[1]),
                new VariableValueFilter <double>(grid.Y, grid.Y.Values[1])
                );
            Assert.AreEqual(5, values[0]);
        }
Пример #7
0
        public void ReadingAscFileShouldNotRequireHardReturnAtEndOfFile()
        {
            string fileName    = RasterDataPath + "test.ASC";
            var    newFileName = Path.GetFullPath(Path.GetFileName(fileName));

            File.Copy(Path.GetFullPath(fileName), newFileName, true);
            var fileInfo = new FileInfo(newFileName);

            if (fileInfo.IsReadOnly)
            {
                fileInfo.IsReadOnly = false;
            }

            var store = new GdalFunctionStore();

            store.Open(newFileName);


            var grid = (IRegularGridCoverage)store.Functions.First(f => f is IRegularGridCoverage);

            Assert.AreEqual(typeof(int), grid.Components[0].ValueType);
            IList <int> values = grid.GetValues <int>();

            Assert.AreEqual(-9999, grid.Components[0].NoDataValues[0]);
            //last value should be a no-data value
            Assert.AreEqual(-9999, values[grid.SizeX - 1], "Last value should be nodata value");
        }
Пример #8
0
        public void GetValuesWithAggregationFilter()
        {
            //  nRows 2566
            // nCols 1843
            // upper left corner of map
            // ULXMAP        124854.28
            // ULYMAP        523505.38
            // stepsize (m) for both dimensions
            // Xdim 20
            // Ydim 20

            string path = rasterDataPath + "Bodem.bil";

            var functionStore = new GdalFunctionStore {
                Path = path
            };

            functionStore.Open();
            //grid.GetValues()
            var grid = functionStore.Grid;

            //create filter for x and y to set xmin, xmax, ymin and ymax (VariableValueRangesFilter<>)
            var xFilter = new VariableAggregationFilter(grid.X, 18, 0, 1782);
            var yFilter = new VariableAggregationFilter(grid.Y, 25, 0, 2475);

            //get values between 130000-132000 and 526000-528000
            var values = grid.GetValues(xFilter, yFilter);

            //check count
            Assert.AreEqual(10000, values.Count);
        }
Пример #9
0
        public void ReadBilFileWithIntegerValues()
        {
            string path      = rasterDataPath + "SchematisatieInt.bil";
            string localPath = "SchematisatieInt.bil";

            File.Copy(path, localPath, true);
            File.Copy(path.Replace(".bil", ".hdr"), localPath.Replace(".bil", ".hdr"), true);
            var functionStore = new GdalFunctionStore {
                Path = localPath
            };

            functionStore.Open();
            var grid = (IRegularGridCoverage)functionStore.Functions.First(f => f is IRegularGridCoverage);

            Assert.AreEqual(typeof(int), grid.Components[0].ValueType);
            Assert.IsTrue(new[] { 7, 8, 9, 4, 5, 6, 1, 2, 3 }.SequenceEqual(functionStore.GetVariableValues <int>(grid.Components[0])));
            Assert.AreEqual(3, grid.X.Values.Count);
            Assert.IsTrue(new double[] { 0, 20, 40 }.SequenceEqual(grid.X.Values));
            Assert.IsTrue(new double[] { 0, 20, 40 }.SequenceEqual(grid.Y.Values));
            Assert.AreEqual(0, grid.Origin.X);
            Assert.AreEqual(0, grid.Origin.Y);
            //update some component values
            grid.SetValues(new int[] { 0, 0, 0 }, new VariableValueFilter <double>(grid.X, new double[] { 0 }));
            Assert.IsTrue(new[] { 0, 8, 9, 0, 5, 6, 0, 2, 3 }.SequenceEqual(functionStore.GetVariableValues <int>(grid.Components[0])));
        }
Пример #10
0
        public void OpenStoreWithNotExistingFileOnInvokingMethodOpenThrows()
        {
            const string path          = "someinvalidfile.bil";
            var          functionStore = new GdalFunctionStore();

            functionStore.Open(path);
        }
Пример #11
0
        public void OrderOfFunctionsAfterReopenShouldBeTheSame()
        {
            var path  = TestHelper.GetCurrentMethodName() + ".tif";
            var store = new GdalFunctionStore();

            store.CreateNew(path);
            var grid = new RegularGridCoverage(2, 2, 1, 1);

            store.Functions.Add(grid);

            // remember indices
            var indexGrid   = store.Functions.IndexOf(grid);
            var indexValues = store.Functions.IndexOf(grid.Components[0]);
            var indexX      = store.Functions.IndexOf(grid.X);
            var indexY      = store.Functions.IndexOf(grid.Y);

            store.Close();

            // re-open store and check if we functions are at the same indices
            var openedStore = new GdalFunctionStore();

            openedStore.Open(path);

            var openedGrid = openedStore.Grid;

            openedStore.Functions.IndexOf(openedGrid)
            .Should("index of grid coverage").Be.EqualTo(indexGrid);
            openedStore.Functions.IndexOf(openedGrid.Components[0])
            .Should("index of values component").Be.EqualTo(indexValues);
            openedStore.Functions.IndexOf(openedGrid.X)
            .Should("index of X").Be.EqualTo(indexX);
            openedStore.Functions.IndexOf(openedGrid.Y)
            .Should("index of Y").Be.EqualTo(indexY);
        }
Пример #12
0
        public void GetValuesWithVariableIndexRangeFilters()
        {
            string fileName = rasterDataPath + "SchematisatieInt.bil";

            var functionStore = new GdalFunctionStore {
                Path = fileName
            };

            functionStore.Open();
            var grid = (IRegularGridCoverage)functionStore.Functions.First(f => f is IRegularGridCoverage);

            IMultiDimensionalArray <int> values = grid.GetValues <int>(
                new VariableIndexRangeFilter(grid.X, 1, 2),
                new VariableIndexRangeFilter(grid.Y, 1, 2)
                );

            //7  8  9
            //4 *5 *6
            //1 *2 *3
            Assert.AreEqual(4, values.Count);
            Assert.AreEqual(5, values[0, 0]);
            Assert.AreEqual(6, values[0, 1]);
            Assert.AreEqual(2, values[1, 0]);
            Assert.AreEqual(3, values[1, 1]);
        }
Пример #13
0
        public void Clone()
        {
            var path = TestHelper.GetCurrentMethodName() + ".tif";

            var store = new GdalFunctionStore();

            store.CreateNew(path);

            var grid = new RegularGridCoverage(2, 2, 1, 1);

            grid.SetValues(new[] { 1, 2, 3, 4 });

            store.Functions.Add(grid);

            var clonedStore = (GdalFunctionStore)store.Clone();

            clonedStore.Functions.Count
            .Should().Be.EqualTo(4);

            clonedStore.Path
            .Should().Be.EqualTo(path);

            var clonedGrid = clonedStore.Functions.OfType <RegularGridCoverage>().FirstOrDefault();

            clonedGrid.GetValues <double>()
            .Should().Have.SameSequenceAs(new double[] { 1, 2, 3, 4 });
        }
Пример #14
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);
        }
Пример #15
0
        public void GetDataSetSizeForBIL()
        {
            string path  = rasterDataPath + "Bodem.bil";
            var    store = new GdalFunctionStore();

            store.Open(path);

            //file is about 18Mb so this work for this on.
            Assert.AreEqual(18916552, store.GetDatasetSize());
        }
Пример #16
0
        public void GetInterpolatedValue1()
        {
            string fileName = rasterDataPath + "SchematisatieInt.bil";

            var functionStore = new GdalFunctionStore();

            functionStore.Open(fileName);
            var grid = (IRegularGridCoverage)functionStore.Functions.First(f => f is IRegularGridCoverage);

            grid.Evaluate <int>(new VariableValueFilter <double>(grid.X, new double[] { 0.5 }), new VariableValueFilter <double>(grid.Y, new double[] { 0.5 }));
        }
Пример #17
0
        public void CheckDataTypeShouldBeFloat()
        {
            
            var path = rasterDataPath + "Schematisatie.bil";

            var functionStore = new GdalFunctionStore { Path = path };
            functionStore.Open();

            var grid = (IRegularGridCoverage)functionStore.Functions.First(f => f is IRegularGridCoverage);
            Assert.AreEqual(typeof(float),grid.Components[0].ValueType);
        }
Пример #18
0
        public void CheckDataTypeShouldBeFloat()
        {
            var path = rasterDataPath + "Schematisatie.bil";

            var functionStore = new GdalFunctionStore();

            functionStore.Open(path);

            var grid = (IRegularGridCoverage)functionStore.Functions.First(f => f is IRegularGridCoverage);

            Assert.AreEqual(typeof(float), grid.Components[0].ValueType);
        }
Пример #19
0
        public void WriteCoverageInMap()
        {
            var functionStore = new GdalFunctionStore();

            functionStore.CreateNew("file.map");

            var grid = new RegularGridCoverage(2, 2, 1, 1, typeof(float));

            grid.SetValues(new[] { 1, 2, 3, 4 });

            functionStore.Functions.Add(grid);
        }
Пример #20
0
        public void AddingFilteredFunctionShouldResetParent()
        {
            var grid = new RegularGridCoverage(2, 2, 1, 1, typeof(float));

            var filteredGrid = grid.Filter();

            string path  = rasterDataPath + "AddingFilteredFunctionShouldResetParent.bil";
            var    store = new GdalFunctionStore();

            store.CreateNew(path);

            store.Functions.Add(filteredGrid);
        }
Пример #21
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 }))));
        }
Пример #22
0
        public void StoringDoubleGridInBilFileShouldThrowException()
        {
            var path = TestHelper.GetCurrentMethodName() + ".bil";

            // create store and add grid
            var store = new GdalFunctionStore();

            store.CreateNew(path);

            var grid = new RegularGridCoverage(2, 2, 1, 1, typeof(float));

            grid.SetValues(new double[] { 1, 2, 3, 4 });

            store.Functions.Add(grid);
        }
Пример #23
0
        public void ReadUInt()
        {
            string fileName      = rasterDataPath + "SchematisatieUInt.bil";
            var    functionStore = new GdalFunctionStore();

            functionStore.Open(fileName);
            var grid = functionStore.Grid;

            grid.Components[0].ValueType
            .Should("Value type stored in the file").Be.EqualTo(typeof(uint));

            var values = functionStore.Grid.Components[0].Values;

            Assert.AreEqual(new[] { 7, 8, 9, 4, 5, 6, 1, 2, 3 }, values);
        }
Пример #24
0
        public void StoreShouldHaveCorrectFunctionsAfterAdd()
        {
            var functionStore = new GdalFunctionStore();

            functionStore.CreateNew(TestHelper.GetCurrentMethodName() + ".bil");

            var grid = new RegularGridCoverage(2, 2, 1, 1, typeof(float));

            grid.SetValues(new[] { 1, 2, 3, 4 });

            functionStore.Functions.Add(grid);

            functionStore.Functions.Count
            .Should("Added function should be: grid, values, x, y").Be.EqualTo(4);
        }
Пример #25
0
        public void CloneOfExternalBilFile()
        {
            string path = rasterDataPath + "bodem.bil";
            //File.SetAttributes(path,FileAttributes.ReadOnly);
            var store = new GdalFunctionStore();

            store.Open(path);

            var grid = store.Grid;
            //action!
            var clone      = (RegularGridCoverage)grid.Clone();
            var cloneStore = clone.Store;

            Assert.IsTrue(cloneStore is GdalFunctionStore);
            Assert.AreEqual(path, ((GdalFunctionStore)cloneStore).Path);
        }
Пример #26
0
        public void GettingCountOfGridComponentsShouldBeReallyFast()
        {
            string path  = rasterDataPath + "Bodem.bil";
            var    store = new GdalFunctionStore();

            store.Open(path);

            var grid = store.Grid;

            TestHelper.AssertIsFasterThan(42, () =>
            {
                for (int i = 0; i < 10000; i++)
                {
                    Assert.AreEqual(4729138, store.GetVariableValues <float>(grid.Components[0]).Count);
                }
            }, true);
        }
Пример #27
0
        public void GetRegularGridCoverageFromGdalStore()
        {
            string fileName = rasterDataPath + "SchematisatieInt.bil";

            var functionStore = new GdalFunctionStore();

            functionStore.Open(fileName);
            var grid =
                (IRegularGridCoverage)functionStore.Functions.FirstOrDefault(f => f is IRegularGridCoverage);

            Assert.AreEqual(20, grid.DeltaX);
            Assert.AreEqual(20, grid.DeltaY);

            Assert.AreEqual(3, grid.SizeX);
            Assert.AreEqual(3, grid.SizeY);

            Assert.AreEqual(3, grid.X.Values.Count);
            Assert.AreEqual(3, grid.X.Values.Count);
        }
Пример #28
0
        public void GetValuesWithVariableValueRangesFilter()
        {
            string path = rasterDataPath + "Bodem.bil";

            var functionStore = new GdalFunctionStore();

            functionStore.Open(path);
            //grid.GetValues()
            var grid = functionStore.Grid;

            //create filter for x and y to set xmin, xmax, ymin and ymax (VariableValueRangesFilter<>)
            var xFilter = new VariableValueRangesFilter <double>(grid.X, new[] { new Pair <double, double>(130000, 132000) });
            var yFilter = new VariableValueRangesFilter <double>(grid.Y, new[] { new Pair <double, double>(520000, 522000) });

            //get values between 130000-132000 and 526000-528000
            var values = grid.GetValues(xFilter, yFilter);

            //check count
            Assert.AreEqual(10201, values.Count);
        }
Пример #29
0
        public void ReadNominalBilFile()
        {
            string path = rasterDataPath + "NominalMap.bil";
            var functionStore = new GdalFunctionStore { Path = path };
            functionStore.Open();
            var grid = (IRegularGridCoverage)functionStore.Functions.First(f => f is IRegularGridCoverage);
            Assert.AreEqual(typeof(Int32), grid.Components[0].ValueType);

            var expectedValues = new Int32[]
                                     {
                                         3, 3, 3, 4, -999, -999,
                                         3, 3, 3, 4, 4, -999,
                                         3, 3, 3, 3, 3, 3,
                                         1, 1, 1, 2, 2, 2,
                                         1, 1, 1, 2, 2, 2,
                                         1, 1, 1, 2, 2, 2
                                     };
            Assert.IsTrue(expectedValues.SequenceEqual<Int32>(grid.Components[0].GetValues<Int32>()));
        
          
        }
Пример #30
0
        public void AddGridShouldAddCorrectFunctionsToStore()
        {
            var store = new GdalFunctionStore();

            store.CreateNew(TestHelper.GetCurrentMethodName() + ".bil");

            var grid = new RegularGridCoverage(2, 2, 1, 1, typeof(float));

            grid.SetValues(new[] { 1, 2, 3, 4 });

            store.Functions.Add(grid);

            grid.Geometry
            .Should().Not.Be.Null();

            store.Functions.Count
            .Should("grid, values, x, y").Be.EqualTo(4);

            store.Functions.OfType <RegularGridCoverage>().FirstOrDefault()
            .Should().Be.EqualTo(grid);
        }
Пример #31
0
        public void MultiRasterBandTest()
        {
            string fileName = rasterDataPath + "4band.tif";

            var functionStore = new GdalFunctionStore {
                Path = fileName
            };

            functionStore.Open();

            var grid = (IRegularGridCoverage)functionStore.Functions.First(f => f is IRegularGridCoverage);

            //RasterBands to Components should be one to one. Tif -> 4 bands (values per ARGB channel)
            Assert.AreEqual(4, grid.Components.Count);

            var xFilter = new VariableValueFilter <double>(grid.X, grid.X.Values[9]);
            var yFilter = new VariableValueFilter <double>(grid.Y, grid.Y.Values[9]);

            var c1 = grid.Components[0].GetValues(xFilter, yFilter)[0];
            var c2 = grid.Components[1].GetValues(xFilter, yFilter)[0];
            var c3 = grid.Components[2].GetValues(xFilter, yFilter)[0];
            var c4 = grid.Components[3].GetValues(xFilter, yFilter)[0];

            Assert.AreEqual(255, c1);
            Assert.AreEqual(255, c2);
            Assert.AreEqual(255, c3);
            Assert.AreEqual(255, c4);

            // F = (value)(x,y) components - arguments

            /*
             * F........ grid coverage is a vector function
             * value.... grid contains n band variables (components)
             * x........ grid contains 2 variables for x and y
             * y
             */
            Assert.AreEqual(functionStore.Functions.Count, 7,
                            "store should contain 1 function for grid coverage, variable for 1st grid component and variables for x and y arguments");
        }
Пример #32
0
        public void StoreShouldHaveCorrectFunctionsAfterOpen()
        {
            var path = TestHelper.GetCurrentMethodName() + ".tif";

            // create store and add grid
            var store = new GdalFunctionStore();

            store.CreateNew(path);

            var grid = new RegularGridCoverage(2, 2, 1, 1);

            grid.SetValues(new[] { 1, 2, 3, 4 });

            store.Functions.Add(grid);

            store.Close();

            // re-open store and check if we have correct functions
            var openedStore = new GdalFunctionStore();

            openedStore.Open(path);

            openedStore.Functions.Count
            .Should("Added function should be: grid, values, x, y").Be.EqualTo(4);

            openedStore.Functions.OfType <RegularGridCoverage>().Count()
            .Should("Store should contain a single grid").Be.EqualTo(1);

            var openedGrid = openedStore.Functions.OfType <RegularGridCoverage>().FirstOrDefault();

            openedGrid.SizeX
            .Should().Be.EqualTo(2);

            openedGrid.SizeY
            .Should().Be.EqualTo(2);

            openedGrid.GetValues <double>()
            .Should().Have.SameSequenceAs(new double[] { 1, 2, 3, 4 });
        }
Пример #33
0
        public void ReadingATifFileShouldBeFast()
        {
            var    start = DateTime.Now;
            string path  = dataPath + "dvim3.tif";

            var functionStore = new GdalFunctionStore {
                Path = path
            };

            functionStore.Open();
            var grid = functionStore.Grid;

            Assert.AreEqual(1317, grid.X.Values.Count);
            Assert.AreEqual(1087, grid.Y.Values.Count);
            Assert.AreEqual(1431579, grid.Components[0].Values.Count);

            var duration = (DateTime.Now - start).TotalMilliseconds;

            log.DebugFormat("It tool {0} ms to read grid file {1}x{2}", duration, grid.SizeX, grid.SizeY);

            Assert.Less(duration, 1500, "It took too long to read tif file of 1,431,579 bytes");
        }
Пример #34
0
        public void StoringDoubleGridInBilFileShouldThrowException()
        {
            var path = TestHelper.GetCurrentMethodName() + ".bil";

            // create store and add grid
            var store = new GdalFunctionStore();
            store.CreateNew(path);

            var grid = new RegularGridCoverage(2, 2, 1, 1, typeof(float));
            grid.SetValues(new double[] {1, 2, 3, 4});

            store.Functions.Add(grid);
        }
Пример #35
0
        public void MultiRasterBandTest()
        {
            string fileName = rasterDataPath + "4band.tif";

            var functionStore = new GdalFunctionStore {Path = fileName};
            functionStore.Open();

            var grid = (IRegularGridCoverage) functionStore.Functions.First(f => f is IRegularGridCoverage);

            //RasterBands to Components should be one to one. Tif -> 4 bands (values per ARGB channel)
            Assert.AreEqual(4, grid.Components.Count);

            var xFilter = new VariableValueFilter<double>(grid.X, grid.X.Values[9]);
            var yFilter = new VariableValueFilter<double>(grid.Y, grid.Y.Values[9]);

            var c1 = grid.Components[0].GetValues(xFilter, yFilter)[0];
            var c2 = grid.Components[1].GetValues(xFilter, yFilter)[0];
            var c3 = grid.Components[2].GetValues(xFilter, yFilter)[0];
            var c4 = grid.Components[3].GetValues(xFilter, yFilter)[0];

            Assert.AreEqual(255, c1);
            Assert.AreEqual(255, c2);
            Assert.AreEqual(255, c3);
            Assert.AreEqual(255, c4);

            // F = (value)(x,y) components - arguments

            /*
             * F........ grid coverage is a vector function
             * value.... grid contains n band variables (components)
             * x........ grid contains 2 variables for x and y
             * y
             */
            Assert.AreEqual(functionStore.Functions.Count, 7,
                            "store should contain 1 function for grid coverage, variable for 1st grid component and variables for x and y arguments");
        }
Пример #36
0
        public void ReadingATifFileShouldBeFast()
        {
            var start = DateTime.Now;
            string path = dataPath + "dvim3.tif";

            var functionStore = new GdalFunctionStore {Path = path};
            functionStore.Open();
            var grid = functionStore.Grid;

            Assert.AreEqual(1317, grid.X.Values.Count);
            Assert.AreEqual(1087, grid.Y.Values.Count);
            Assert.AreEqual(1431579, grid.Components[0].Values.Count);

            var duration = (DateTime.Now - start).TotalMilliseconds;

            log.DebugFormat("It tool {0} ms to read grid file {1}x{2}", duration, grid.SizeX, grid.SizeY);

            Assert.Less(duration, 1500, "It took too long to read tif file of 1,431,579 bytes");
        }
Пример #37
0
        public void GetValuesWithVariableValueRangesFilter()
        {
            string path = rasterDataPath + "Bodem.bil";

            var functionStore = new GdalFunctionStore { Path = path };
            functionStore.Open();
            //grid.GetValues()
            var grid = functionStore.Grid;
            
            //create filter for x and y to set xmin, xmax, ymin and ymax (VariableValueRangesFilter<>)
            var xFilter = new VariableValueRangesFilter<double>(grid.X, new[] {new Pair<double, double>(130000, 132000)});
            var yFilter = new VariableValueRangesFilter<double>(grid.Y, new[] { new Pair<double, double>(520000, 522000)});
            
            //get values between 130000-132000 and 526000-528000
            var values = grid.GetValues(xFilter, yFilter);

            //check count
            Assert.AreEqual(10201, values.Count);
        }
Пример #38
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);
        }
Пример #39
0
        public void GetValuesWithVariableValueFilters()
        {
            string fileName = rasterDataPath + "SchematisatieInt.bil";
            var functionStore = new GdalFunctionStore {Path = fileName};
            functionStore.Open();
            var grid = (IRegularGridCoverage) functionStore.Functions.First(f => f is IRegularGridCoverage);
            IList<int> values = grid.GetValues<int>(
                new VariableValueFilter<double>(grid.X, grid.X.Values[0]),
                new VariableValueFilter<double>(grid.Y, grid.Y.Values[0])
                );
            Assert.AreEqual(1, values.Count);
            Assert.AreEqual(7, values[0]);

            values = grid.GetValues<int>(
                new VariableValueFilter<double>(grid.X, grid.X.Values[0]));
            Assert.AreEqual(3, values.Count);

            values = grid.GetValues<int>(
                new VariableValueFilter<double>(grid.X, grid.X.Values[1]),
                new VariableValueFilter<double>(grid.Y, grid.Y.Values[1])
                );
            Assert.AreEqual(5, values[0]);
        }
Пример #40
0
        public void GetInterpolatedValue1()
        {
            string fileName = rasterDataPath + "SchematisatieInt.bil";

            var functionStore = new GdalFunctionStore { Path = fileName };
            functionStore.Open();
            var grid = (IRegularGridCoverage)functionStore.Functions.First(f => f is IRegularGridCoverage);

            grid.Evaluate<int>(new VariableValueFilter<double>(grid.X, new double[] { 0.5 }), new VariableValueFilter<double>(grid.Y, new double[] { 0.5 }));

        }
Пример #41
0
        public void GetValuesWithSampleFilters()
        {
             //     1     2      3      4      5      6       7     8      9
             //    10     11*    12     13     14*    15     16     17*    18
             //    19     20     21     22     23     24     25     26     27
             //    28     29     30     31     32     33     34     35     36
             //    37     38*    39     40     41*    42     43     44*    45
             //    46     47     48     49     50     51     52     53     54
             //    55     56     57     58     59     60     61     62     63
             //    64     65*    66     67     68*    69     70     71*    72
             //    73     74     75     76     77     78     79     80     81

            string fileName = rasterDataPath + "SchematisatieInt9x9.asc";

            var functionStore = new GdalFunctionStore { Path = fileName };
            functionStore.Open();
            var grid = (IRegularGridCoverage)functionStore.Functions.First(f => f is IRegularGridCoverage);

            var sampleSize = 3;
            IMultiDimensionalArray<int> values = grid.GetValues<int>(
                new VariableAggregationFilter(grid.X, 4,0,grid.X.Values.Count-1),
                new VariableAggregationFilter(grid.Y, 4, 0, grid.Y.Values.Count - 1)
                );

            Assert.AreEqual(sampleSize * sampleSize, values.Count);
            //Assert.AreEqual(new[]{11,14,17,38,41,44,65,68,71}, values.ToArray());
            //Lower Left Corner Based
            Assert.AreEqual(new[] { 65, 68, 71, 38, 41, 44, 11, 14, 17 }, values.ToArray());
        }
Пример #42
0
        public void OrderOfFunctionsAfterReopenShouldBeTheSame()
        {
            var path = TestHelper.GetCurrentMethodName() + ".tif";
            var store = new GdalFunctionStore();
            store.CreateNew(path);
            var grid = new RegularGridCoverage(2, 2, 1, 1);
            store.Functions.Add(grid);

            // remember indices
            var indexGrid = store.Functions.IndexOf(grid);
            var indexValues = store.Functions.IndexOf(grid.Components[0]);
            var indexX = store.Functions.IndexOf(grid.X);
            var indexY = store.Functions.IndexOf(grid.Y);
            
            store.Close();

            // re-open store and check if we functions are at the same indices
            var openedStore = new GdalFunctionStore();
            openedStore.Open(path);

            var openedGrid = openedStore.Grid;

            openedStore.Functions.IndexOf(openedGrid)
                .Should("index of grid coverage").Be.EqualTo(indexGrid);
            openedStore.Functions.IndexOf(openedGrid.Components[0])
                .Should("index of values component").Be.EqualTo(indexValues);
            openedStore.Functions.IndexOf(openedGrid.X)
                .Should("index of X").Be.EqualTo(indexX);
            openedStore.Functions.IndexOf(openedGrid.Y)
                .Should("index of Y").Be.EqualTo(indexY);
        }
Пример #43
0
        public void StoreShouldHaveCorrectFunctionsAfterOpen()
        {
            var path = TestHelper.GetCurrentMethodName() + ".tif";

            // create store and add grid
            var store = new GdalFunctionStore();
            store.CreateNew(path);

            var grid = new RegularGridCoverage(2, 2, 1, 1);
            grid.SetValues(new[] { 1, 2, 3, 4 });

            store.Functions.Add(grid);

            store.Close();

            // re-open store and check if we have correct functions
            var openedStore = new GdalFunctionStore();
            openedStore.Open(path);

            openedStore.Functions.Count
                .Should("Added function should be: grid, values, x, y").Be.EqualTo(4);

            openedStore.Functions.OfType<RegularGridCoverage>().Count()
                .Should("Store should contain a single grid").Be.EqualTo(1);

            var openedGrid = openedStore.Functions.OfType<RegularGridCoverage>().FirstOrDefault();

            openedGrid.SizeX
                .Should().Be.EqualTo(2);

            openedGrid.SizeY
                .Should().Be.EqualTo(2);

            openedGrid.GetValues<double>()
                .Should().Have.SameSequenceAs(new double[] {1, 2, 3, 4});
        }
Пример #44
0
        public void AddGridShouldAddCorrectFunctionsToStore()
        {
            var store = new GdalFunctionStore();
            store.CreateNew(TestHelper.GetCurrentMethodName() + ".bil");

            var grid = new RegularGridCoverage(2, 2, 1, 1, typeof(float));
            grid.SetValues(new[] { 1, 2, 3, 4 });

            store.Functions.Add(grid);

            grid.Geometry
                .Should().Not.Be.Null();

            store.Functions.Count
                .Should("grid, values, x, y").Be.EqualTo(4);

            store.Functions.OfType<RegularGridCoverage>().FirstOrDefault()
                .Should().Be.EqualTo(grid);
        }
Пример #45
0
        public void Clone()
        {
            var path = TestHelper.GetCurrentMethodName() + ".tif";
            
            var store = new GdalFunctionStore();
            store.CreateNew(path);

            var grid = new RegularGridCoverage(2, 2, 1, 1);
            grid.SetValues(new[] { 1, 2, 3, 4 });

            store.Functions.Add(grid);

            var clonedStore = (GdalFunctionStore)store.Clone();

            clonedStore.Functions.Count
                .Should().Be.EqualTo(4);

            clonedStore.Path
                .Should().Be.EqualTo(path);

            var clonedGrid = clonedStore.Functions.OfType<RegularGridCoverage>().FirstOrDefault();

            clonedGrid.GetValues<double>()
                .Should().Have.SameSequenceAs(new double[] { 1, 2, 3, 4 });
        }
Пример #46
0
        public void CloneFunctionStoredInGdalFunctionStore()
        {
            var path = TestHelper.GetCurrentMethodName() + ".tif";

            var store = new GdalFunctionStore();
            store.CreateNew(path);

            const int deltaX = 1;
            const int deltaY = 10;
            var grid = new RegularGridCoverage(2, 2, deltaX, deltaY);
            grid.SetValues(new[] { 1, 2, 3, 4 });

            store.Functions.Add(grid);

            // create grid clone and check if function and cloned store are correct
            var clonedGrid = (RegularGridCoverage)grid.Clone();

            var clonedStore = (GdalFunctionStore)clonedGrid.Store;

            clonedStore.Functions.Count
                .Should().Be.EqualTo(4);

            clonedStore.Path
                .Should().Be.EqualTo(path);

            clonedGrid.GetValues<double>()
                .Should().Have.SameSequenceAs(new double[] { 1, 2, 3, 4 });
        }
Пример #47
0
        public void CloneOfExternalBilFile()
        {
            string path = rasterDataPath + "bodem.bil";
            //File.SetAttributes(path,FileAttributes.ReadOnly);
            var store = new GdalFunctionStore();
            store.Open(path);
            
            var grid = store.Grid;
            //action! 
            var clone = (RegularGridCoverage)grid.Clone();
            var cloneStore = clone.Store;
            
            Assert.IsTrue(cloneStore is GdalFunctionStore);
            Assert.AreEqual(path,((GdalFunctionStore)cloneStore).Path);

        }
Пример #48
0
        public void CopyToBilFileIncludeHDR()
        {
            string path = rasterDataPath + "SchematisatieInt.bil";
            string hdrPath = rasterDataPath + "SchematisatieInt.hdr";
            string targetPath = "SchematisatieInt.bil";
            string targetHDRPath = "SchematisatieInt.hdr";

            if (File.Exists(targetPath)) File.Delete(targetPath);
            if (File.Exists(targetHDRPath)) File.Delete(targetHDRPath);

            var functionStore = new GdalFunctionStore { Path = path };

            Assert.IsTrue(File.Exists(hdrPath));

            functionStore.CopyTo(targetPath);

            Assert.IsTrue(File.Exists(targetPath));
            Assert.IsTrue(File.Exists(targetHDRPath));

            if (File.Exists(targetPath)) File.Delete(targetPath);
            if (File.Exists(targetHDRPath)) File.Delete(targetHDRPath);
        }
Пример #49
0
        public void GetRegularGridCoverageFromGdalStore()
        {
            string fileName = rasterDataPath + "SchematisatieInt.bil";

            var functionStore = new GdalFunctionStore {Path = fileName};
            functionStore.Open();
            var grid =
                (IRegularGridCoverage) functionStore.Functions.FirstOrDefault(f => f is IRegularGridCoverage);

            Assert.AreEqual(20, grid.DeltaX);
            Assert.AreEqual(20, grid.DeltaY);

            Assert.AreEqual(3, grid.SizeX);
            Assert.AreEqual(3, grid.SizeY);

            Assert.AreEqual(3, grid.X.Values.Count);
            Assert.AreEqual(3, grid.X.Values.Count);
        }
Пример #50
0
        public void StoreShouldHaveCorrectFunctionsAfterAdd()
        {
            var functionStore = new GdalFunctionStore();
            functionStore.CreateNew(TestHelper.GetCurrentMethodName() + ".bil");

            var grid = new RegularGridCoverage(2, 2, 1, 1, typeof(float));
            grid.SetValues(new[] { 1, 2, 3, 4 });

            functionStore.Functions.Add(grid);

            functionStore.Functions.Count
                .Should("Added function should be: grid, values, x, y").Be.EqualTo(4);
        }
Пример #51
0
        public void GetValuesWithVariableIndexRangeFilters()
        {
            string fileName = rasterDataPath + "SchematisatieInt.bil";

            var functionStore = new GdalFunctionStore {Path = fileName};
            functionStore.Open();
            var grid = (IRegularGridCoverage) functionStore.Functions.First(f => f is IRegularGridCoverage);

            IMultiDimensionalArray<int> values = grid.GetValues<int>(
                new VariableIndexRangeFilter(grid.X, 1, 2),
                new VariableIndexRangeFilter(grid.Y, 1, 2)
                );

            //7  8  9
            //4 *5 *6
            //1 *2 *3
            Assert.AreEqual(4, values.Count);
            Assert.AreEqual(5, values[0, 0]);
            Assert.AreEqual(6, values[0, 1]);
            Assert.AreEqual(2, values[1, 0]);
            Assert.AreEqual(3, values[1, 1]);
        }
Пример #52
0
        public void WriteCoverageInMap()
        {
            var functionStore = new GdalFunctionStore();
            functionStore.CreateNew("file.map");

            var grid = new RegularGridCoverage(2, 2, 1, 1, typeof(float));
            grid.SetValues(new[] { 1, 2, 3, 4 });
            
            functionStore.Functions.Add(grid);
        }
Пример #53
0
        public void ReadUInt()
        {
            string fileName = rasterDataPath + "SchematisatieUInt.bil";
            var functionStore = new GdalFunctionStore { Path = fileName };
            functionStore.Open();
            var grid = functionStore.Grid;

            grid.Components[0].ValueType
                .Should("Value type stored in the file").Be.EqualTo(typeof (uint));

            var values = functionStore.Grid.Components[0].Values;
            Assert.AreEqual(new[] { 7, 8, 9, 4, 5, 6, 1, 2, 3 }, values);
        }
Пример #54
0
        public void GetValuesWithAggregationFilter()
        {

            //  nRows 2566
            // nCols 1843
            // upper left corner of map
            // ULXMAP        124854.28
            // ULYMAP        523505.38
            // stepsize (m) for both dimensions
            // Xdim 20
            // Ydim 20

            string path = rasterDataPath + "Bodem.bil";

            var functionStore = new GdalFunctionStore { Path = path };
            functionStore.Open();
            //grid.GetValues()
            var grid = functionStore.Grid;

            //create filter for x and y to set xmin, xmax, ymin and ymax (VariableValueRangesFilter<>)
            var xFilter = new VariableAggregationFilter(grid.X,18,0,1782);
            var yFilter = new VariableAggregationFilter(grid.Y,25,0,2475);

            //get values between 130000-132000 and 526000-528000
            var values = grid.GetValues(xFilter, yFilter);

            //check count
            Assert.AreEqual(10000, values.Count);
        }   
Пример #55
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);

        }
Пример #56
0
        public void GetInterpolatedValue()
        {
            string path = rasterDataPath + "SchematisatieInt.bil";

            var functionStore = new GdalFunctionStore {Path = path};
            functionStore.Open();
            var grid = (IRegularGridCoverage) functionStore.Functions.First(f => f is IRegularGridCoverage);
            grid.X.InterpolationType = ApproximationType.Constant;
            grid.X.ExtrapolationType = ApproximationType.Constant;
            grid.Y.InterpolationType = ApproximationType.Constant;
            grid.Y.ExtrapolationType = ApproximationType.Constant;
            var values = new double[] {1, 2, 3, 4, 5, 6, 7, 8, 9};
            var index = 0;

            for (int j = 0; j < 3; j++)
            {
                for (int i = 0; i < 3; i++)
                {
                    var x = 10.0 + 20*i;
                    var y = 50.0 - 20*j;

                    var value = grid.Evaluate<int>(new VariableValueFilter<double>(grid.X, new[] {x}),
                                                          new VariableValueFilter<double>(grid.Y, new[] { y }));
                    Assert.AreEqual(values[index], value);
                    index++;
                }
            }
        }
Пример #57
0
 public GdalFeatureProvider()
 {
     store = new GdalFunctionStore();
 }
Пример #58
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}))));
        }
Пример #59
0
        public void ReadingAscFileShouldNotRequireHardReturnAtEndOfFile()
        {
            string fileName = RasterDataPath + "test.ASC";
            var newFileName = Path.GetFullPath(Path.GetFileName(fileName));
            File.Copy(Path.GetFullPath(fileName), newFileName, true);
            var fileInfo = new FileInfo(newFileName);
            if (fileInfo.IsReadOnly)
            {
                fileInfo.IsReadOnly = false;
            }

            var store = new GdalFunctionStore();
            store.Open(newFileName);


            var grid = (IRegularGridCoverage) store.Functions.First(f => f is IRegularGridCoverage);
            Assert.AreEqual(typeof (int), grid.Components[0].ValueType);
            IList<int> values = grid.GetValues<int>();
            Assert.AreEqual(-9999, grid.Components[0].NoDataValues[0]);
            //last value should be a no-data value
            Assert.AreEqual(-9999, values[grid.SizeX-1], "Last value should be nodata value");
        }
Пример #60
0
 public void ReadBilFileWithIntegerValues()
 {
     string path = rasterDataPath + "SchematisatieInt.bil";
     string localPath = "SchematisatieInt.bil";
     File.Copy(path, localPath, true);
     File.Copy(path.Replace(".bil", ".hdr"), localPath.Replace(".bil", ".hdr"), true);
     var functionStore = new GdalFunctionStore {Path = localPath};
     functionStore.Open();
     var grid = (IRegularGridCoverage) functionStore.Functions.First(f => f is IRegularGridCoverage);
     Assert.AreEqual(typeof (int), grid.Components[0].ValueType);
     Assert.IsTrue(new[] { 7, 8, 9, 4, 5, 6, 1, 2, 3 }.SequenceEqual(functionStore.GetVariableValues<int>(grid.Components[0])));
     Assert.AreEqual(3, grid.X.Values.Count);
     Assert.IsTrue(new double[] {0, 20, 40}.SequenceEqual(grid.X.Values));
     Assert.IsTrue(new double[] {0, 20, 40}.SequenceEqual(grid.Y.Values));
     Assert.AreEqual(0, grid.Origin.X);
     Assert.AreEqual(0, grid.Origin.Y);
     //update some component values
     grid.SetValues(new int[] { 0, 0, 0 }, new VariableValueFilter<double>(grid.X, new double[] { 0 }));
     Assert.IsTrue(new[] { 0, 8, 9, 0, 5, 6, 0, 2, 3 }.SequenceEqual(functionStore.GetVariableValues<int>(grid.Components[0])));
 }