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]))); }
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 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); }
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 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 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]))); }
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); }