public void CheckThemeOfCoverageWithoutValidValues() { var coverage = new RegularGridCoverage(2, 2, 10, 10); coverage.Components[0].Clear(); coverage.SetValues(new[] { -999.0, -999.0, double.PositiveInfinity, double.NaN }, new VariableValueFilter <double>(coverage.X, new double[] { 0, 1 }), new VariableValueFilter <double>(coverage.Y, new double[] { 0, 1 }) ); coverage.Components[0].NoDataValues.Add(-999.0); var layer = new RegularGridCoverageLayer { Coverage = coverage }; layer.Map = new Map(new Size(10, 10)); layer.Map.Zoom = layer.Map.Zoom / 100; layer.Render(); var gradientTheme = layer.Theme as GradientTheme; Assert.IsNotNull(gradientTheme); Assert.AreEqual(double.MinValue, gradientTheme.Min); Assert.AreEqual(double.MaxValue, gradientTheme.Max); }
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 }); }
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 GetGridValuesTest() { var vertices = new List<ICoordinate> { new Coordinate(0, 0), new Coordinate(100, 100) }; ILineString gridProfile = new LineString(vertices.ToArray()); IRegularGridCoverage regularGridCoverage = new RegularGridCoverage(2,3,100,50) { Name = "pressure", }; regularGridCoverage.Components.Clear(); regularGridCoverage.Components.Add(new Variable<float>("pressure")); regularGridCoverage.SetValues(new[] { 1.1, 2.0, 3.0, 4.0, 5.0, 6.0 }); Function gridValues = RegularGridCoverageHelper.GetGridValues(regularGridCoverage, gridProfile); Assert.AreEqual(101, gridValues.Components[0].Values.Count); Assert.AreEqual(1.1f, (float)gridValues[0.0], 1e-3f); // We can not use the linestring's length directly due to rounding errors Assert.AreEqual((double)gridValues.Arguments[0].Values[gridValues.Components[0].Values.Count - 1], gridProfile.Length, 1e-6); double length = (double)gridValues.Arguments[0].Values[gridValues.Components[0].Values.Count - 1]; Assert.AreEqual(6.0, gridValues[length]); }
public void CheckThemeOfCoverageWithoutValidValues() { var coverage = new RegularGridCoverage(2, 2, 10, 10); coverage.Components[0].Clear(); coverage.SetValues(new[] {-999.0, -999.0, double.PositiveInfinity , double.NaN}, new VariableValueFilter<double>(coverage.X, new double[] {0, 1}), new VariableValueFilter<double>(coverage.Y, new double[] {0, 1}) ); coverage.Components[0].NoDataValues.Add(-999.0); var layer = new RegularGridCoverageLayer { Coverage = coverage }; layer.Map = new Map(new Size(10, 10)); layer.Map.Zoom = layer.Map.Zoom / 100; layer.Render(); var gradientTheme = layer.Theme as GradientTheme; Assert.IsNotNull(gradientTheme); Assert.AreEqual(double.MinValue, gradientTheme.Min ); Assert.AreEqual(double.MaxValue, gradientTheme.Max); }
public void GetGridValuesTest() { var vertices = new List <ICoordinate> { new Coordinate(0, 0), new Coordinate(100, 100) }; ILineString gridProfile = new LineString(vertices.ToArray()); IRegularGridCoverage regularGridCoverage = new RegularGridCoverage(2, 3, 100, 50) { Name = "pressure", }; regularGridCoverage.Components.Clear(); regularGridCoverage.Components.Add(new Variable <float>("pressure")); regularGridCoverage.SetValues(new[] { 1.1f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f }); Function gridValues = CoverageHelper.GetCoverageValues(regularGridCoverage, gridProfile, null); Assert.AreEqual(101, gridValues.Components[0].Values.Count); Assert.AreEqual(1.1f, (float)gridValues[0.0], 1e-3f); // We can not use the linestring's length directly due to rounding errors Assert.AreEqual((double)gridValues.Arguments[0].Values[gridValues.Components[0].Values.Count - 1], gridProfile.Length, 1e-6); double length = (double)gridValues.Arguments[0].Values[gridValues.Components[0].Values.Count - 1]; Assert.AreEqual(6.0, gridValues[length]); }
public void ShowRegularGridWithQuantityThemeOnMap() { IRegularGridCoverage grid2D = new RegularGridCoverage(200, 200, 10, 10) { Name = "pressure" }; double[] values = new double[grid2D.SizeX * grid2D.SizeY]; double min = 0; double max = 0; for (int i = 0; i < values.Length; i++) { values[i] = i; if (values[i] > max) { max = values[i]; } if (values[i] < min) { min = values[i]; } } grid2D.SetValues(values); var map = new Map(); var rasterLayer = new RegularGridCoverageLayer { Grid = grid2D }; var defaultStyle = new VectorStyle { GeometryType = typeof(IPolygon), Line = Pens.SeaGreen }; double interval = (max - min) / 10; var intervalList = new List <Interval>(); double start = min; double stop = min + interval; for (int i = 0; i < 10; i++) { intervalList.Add(new Interval(start, stop)); start = stop; stop += interval; } QuantityTheme quantityTheme = ThemeFactory.CreateQuantityTheme(grid2D.Components[0].Name, defaultStyle, ColorBlend.BlueToGreen, 10, intervalList ); rasterLayer.Theme = quantityTheme; map.Layers.Add(rasterLayer); MapTestHelper.ShowModal(map); }
public void CloneTimeDependent() { var t1 = DateTime.Now; var t2 = t1.AddDays(1); IRegularGridCoverage coverage = new RegularGridCoverage(2, 2, 10, 20) { IsTimeDependent = true }; coverage.SetValues(new double[] { 1, 2, 3, 4 }, new VariableValueFilter <DateTime>(coverage.Time, t1)); coverage.SetValues(new double[] { 10, 20, 30, 40 }, new VariableValueFilter <DateTime>(coverage.Time, t2)); var clonedCoverage = (IRegularGridCoverage)coverage.Clone(); Assert.AreEqual(clonedCoverage.Time.Values.Count, coverage.Time.Values.Count); }
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; }
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); }
private static IRegularGridCoverage CreatePressureTimeDependentRegularGridCoverage(out DateTime time1, out DateTime time2) { IRegularGridCoverage grid2D = new RegularGridCoverage(2, 3, 100, 50) { // default constructor will set x[0] to 0.0 and y[0] to 0.0 Name = "pressure" }; var time = new Variable <DateTime>("time"); grid2D.Time = time; time1 = DateTime.Now; var values1 = new[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }; grid2D.SetValues(values1, new VariableValueFilter <DateTime>(time, time1)); Assert.AreEqual(6, grid2D.GetValues <double>().Count); time2 = time1.AddDays(1); var values2 = new[] { 10.0, 20.0, 30.0, 40.0, 50.0, 60.0 }; grid2D.SetValues(values2, new VariableValueFilter <DateTime>(time, time2)); // resulting dynamic coverage is // t = now t = now + 1day // x = 0 x = 100 x = 0 x = 100 // // y = 0 | 1.0 2.0 | 10.0 20.0 // y = 50 | 3.0 4.0 | 30.0 40.0 // y = 100 | 5.0 6.0 | 50.0 60.0 // // return(grid2D); }
public void EvaluateCoordinateForCornerCases() { var grid = new RegularGridCoverage(2, 2, 5.0, 5.0); grid.SetValues(new[] { 12.34 }); Assert.AreEqual(12.34, grid.Evaluate(new Coordinate(0.0, 0.0))); Assert.AreEqual(12.34, grid.Evaluate(new Coordinate(10.0, 0.0))); Assert.AreEqual(12.34, grid.Evaluate(new Coordinate(0.0, 10.0))); Assert.AreEqual(12.34, grid.Evaluate(new Coordinate(10.0, 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); }
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); }
private static IRegularGridCoverage CreateTestCoverage(double offsetX, double offsetY) { IRegularGridCoverage grid2D = new RegularGridCoverage(2, 3, 100, 50, offsetX, offsetY) { Name = "test" }; grid2D.SetValues(new[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }); return grid2D; }
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 AggregateInTime() { var grid2D = new RegularGridCoverage(2, 3, 100, 50) { Name = "pressure" }; var time = new Variable <DateTime>("time"); grid2D.Time = time; DateTime time1 = DateTime.Now; var values1 = new[] { 1.0, 1.0, 1.0, 1.0, 50.0, 60.0 }; grid2D.SetValues(values1, new VariableValueFilter <DateTime>(time, time1)); Assert.AreEqual(6, grid2D.GetValues <double>().Count); DateTime time2 = time1.AddDays(1); var values2 = new[] { 1.0, 1.0, 4.0, 4.0, 50.0, 60.0 }; grid2D.SetValues(values2, new VariableValueFilter <DateTime>(time, time2)); Func <int, double, int> aggregator = ((seed, h) => (h > 3) ? (seed + 1) : seed); var result = grid2D.Aggregate(time, 0, aggregator); var aggregatedValues = (IEnumerable <int>)result.Components[0].GetValues(); Assert.IsTrue(new[] { 0, 0, 1, 1, 2, 2 }.SequenceEqual(aggregatedValues)); }
public void FilterCoverage() { IRegularGridCoverage gridWithTime = new RegularGridCoverage(2, 3, 100, 50) { Name = "pressure" }; var time = new Variable <DateTime>("time"); gridWithTime.Time = time; DateTime time1 = DateTime.Now; var values1 = new[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }; gridWithTime.SetValues(values1, new VariableValueFilter <DateTime>(time, time1)); DateTime time2 = time1.AddDays(1); var values2 = new[] { 10.0, 20.0, 30.0, 40.0, 50.0, 60.0 }; gridWithTime.SetValues(values2, new VariableValueFilter <DateTime>(time, time2)); var filteredGrid = gridWithTime.FilterAsRegularGridCoverage(new VariableValueFilter <DateTime>(time, time2)); Assert.AreEqual(6, filteredGrid.Components[0].Values.Count); Assert.AreEqual(gridWithTime.Store, filteredGrid.Store); var sizeX = gridWithTime.SizeX; var filteredSizeX = filteredGrid.SizeX; Assert.AreEqual(sizeX, filteredSizeX); Assert.AreEqual(gridWithTime.SizeY, filteredGrid.SizeY); Assert.AreEqual(gridWithTime.DeltaX, filteredGrid.DeltaX); Assert.AreEqual(gridWithTime.DeltaY, filteredGrid.DeltaY); Assert.AreEqual(gridWithTime.Arguments.Count, filteredGrid.Arguments.Count); Assert.AreEqual(gridWithTime.Components.Count, filteredGrid.Components.Count); Assert.AreEqual(gridWithTime.Geometry, filteredGrid.Geometry); }
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 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); }
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); }
private static IRegularGridCoverage CreateTestCoverage(double offsetX, double offsetY) { IRegularGridCoverage grid2D = new RegularGridCoverage(2, 3, 100, 50, offsetX, offsetY) { Name = "test" }; grid2D.SetValues(new[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }); return(grid2D); }
private IRegularGridCoverage CreatePressureCoverage(double offsetX, double offsetY) { var sizeX = 2; var sizeY = 3; var deltaX = 100; var deltaY = 50; IRegularGridCoverage grid2D = new RegularGridCoverage(sizeX, sizeY, deltaX, deltaY, offsetX, offsetY) { Name = "pressure" }; //fill 2d matrix with values. grid2D.SetValues(new[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }); return grid2D; }
public void SelectOnlySpecificValuesUsingAggregationFilterFromBottom() // TODO: migrate to fit tests { IRegularGridCoverage grid2D = new RegularGridCoverage(4, 4, 1, 1); var values = new[, ] { { 1.1, 2.1, 3.1, 4.1 }, { 1.2, 2.2, 3.2, 4.2 }, { 1.3, 2.3, 3.3, 4.3 }, // <- { 1.4, 2.4, 3.4, 4.4 }, // <- }; grid2D.SetValues(values); var subSelection = grid2D.GetValues <double>(new VariableAggregationFilter(grid2D.Y, 1, 2, 3)); Assert.IsTrue(subSelection.SequenceEqual(new[] { 1.3, 2.3, 3.3, 4.3, 1.4, 2.4, 3.4, 4.4 })); }
public void SelectOnlySpecificValuesUsingAggregationFilter() // TODO: migrate to fit tests { IRegularGridCoverage grid2D = new RegularGridCoverage(4, 4, 1, 1); var values = new[, ] { { 1.0, 2.0, 3.0, 4.0 }, { 1.0, 2.0, 3.0, 4.0 }, { 1.0, 2.0, 3.0, 4.0 }, { 1.0, 2.0, 3.0, 4.0 }, // ^ ^ }; grid2D.SetValues(values); var subSelection = grid2D.GetValues <double>(new VariableAggregationFilter(grid2D.X, 2, 0, 3)); Assert.IsTrue(subSelection.SequenceEqual(new[] { 1.0, 3.0, 1.0, 3.0, 1.0, 3.0, 1.0, 3.0 })); }
public void GetGridValuesTest() { var vertices = new List <ICoordinate> { new Coordinate(0, 0), new Coordinate(100, 100) }; var gridProfile = new LineString(vertices.ToArray()); var regularGridCoverage = new RegularGridCoverage(2, 3, 100, 50) { Name = "pressure", }; regularGridCoverage.Components.Clear(); regularGridCoverage.Components.Add(new Variable <float>("pressure")); regularGridCoverage.SetValues(new[] { 1.1f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f }); var gridValues = CoverageProfile.GetCoverageValues(regularGridCoverage, gridProfile, null); Assert.AreEqual(101, gridValues.Components[0].Values.Count); Assert.AreEqual(1.1f, (float)gridValues[0.0], 1e-3f); // We can not use the linestring's length directly due to rounding errors Assert.AreEqual((double)gridValues.Arguments[0].Values[gridValues.Components[0].Values.Count - 1], gridProfile.Length, 1e-6); var length = (double)gridValues.Arguments[0].Values[gridValues.Components[0].Values.Count - 1]; Assert.AreEqual(6.0, gridValues[length]); gridValues = CoverageProfile.GetCoverageValues(regularGridCoverage, gridProfile, null, 10.0); Assert.AreEqual(15, gridValues.Components[0].Values.Count); Assert.AreEqual(1.1f, (float)gridValues[0.0], 1e-3f); length = (double)gridValues.Arguments[0].Values[gridValues.Components[0].Values.Count - 1]; // We can not use the linestring's length directly due to rounding errors Assert.AreEqual(((int)(gridProfile.Length / 10.0)) * 10.0, length, 1e-6); Assert.AreEqual(3.0, gridValues[length], "value at end is 3.0 due to rounding that caused the evaluated line to fall short to fall into cell with value of 6.0"); }
private IRegularGridCoverage CreatePressureCoverage(double offsetX, double offsetY) { var sizeX = 2; var sizeY = 3; var deltaX = 100; var deltaY = 50; IRegularGridCoverage grid2D = new RegularGridCoverage(sizeX, sizeY, deltaX, deltaY, offsetX, offsetY) { Name = "pressure" }; //fill 2d matrix with values. grid2D.SetValues(new[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }); return(grid2D); }
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); }
public void GetGridValuesTest() { var vertices = new List<ICoordinate> { new Coordinate(0, 0), new Coordinate(100, 100) }; var gridProfile = new LineString(vertices.ToArray()); var regularGridCoverage = new RegularGridCoverage(2, 3, 100, 50) { Name = "pressure", }; regularGridCoverage.Components.Clear(); regularGridCoverage.Components.Add(new Variable<float>("pressure")); regularGridCoverage.SetValues(new[] { 1.1f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f }); var gridValues = CoverageProfile.GetCoverageValues(regularGridCoverage, gridProfile, null); Assert.AreEqual(101, gridValues.Components[0].Values.Count); Assert.AreEqual(1.1f, (float)gridValues[0.0], 1e-3f); // We can not use the linestring's length directly due to rounding errors Assert.AreEqual((double)gridValues.Arguments[0].Values[gridValues.Components[0].Values.Count - 1], gridProfile.Length, 1e-6); var length = (double)gridValues.Arguments[0].Values[gridValues.Components[0].Values.Count - 1]; Assert.AreEqual(6.0, gridValues[length]); gridValues = CoverageProfile.GetCoverageValues(regularGridCoverage, gridProfile, null, 10.0); Assert.AreEqual(15, gridValues.Components[0].Values.Count); Assert.AreEqual(1.1f, (float)gridValues[0.0], 1e-3f); length = (double)gridValues.Arguments[0].Values[gridValues.Components[0].Values.Count - 1]; // We can not use the linestring's length directly due to rounding errors Assert.AreEqual(((int)(gridProfile.Length / 10.0))*10.0, length, 1e-6); Assert.AreEqual(3.0, gridValues[length], "value at end is 3.0 due to rounding that caused the evaluated line to fall short to fall into cell with value of 6.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 }); }
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 AggregateInTime() { var grid2D = new RegularGridCoverage(2, 3, 100, 50) { Name = "pressure" }; var time = new Variable<DateTime>("time"); grid2D.Time = time; DateTime time1 = DateTime.Now; var values1 = new[] { 1.0, 1.0, 1.0, 1.0, 50.0, 60.0 }; grid2D.SetValues(values1, new VariableValueFilter<DateTime>(time, time1)); Assert.AreEqual(6, grid2D.GetValues<double>().Count); DateTime time2 = time1.AddDays(1); var values2 = new[] { 1.0, 1.0, 4.0, 4.0, 50.0, 60.0 }; grid2D.SetValues(values2, new VariableValueFilter<DateTime>(time, time2)); Func<int, double, int> aggregator = ((seed, h) => (h > 3) ? (seed + 1) : seed); var result = grid2D.Aggregate(time, 0, aggregator); var aggregatedValues = (IEnumerable<int>) result.Components[0].GetValues(); Assert.IsTrue(new[] {0, 0, 1, 1, 2, 2}.SequenceEqual(aggregatedValues)); }
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 CloneTimeDependent() { var t1 = DateTime.Now; var t2 = t1.AddDays(1); IRegularGridCoverage coverage = new RegularGridCoverage(2, 2, 10, 20) {IsTimeDependent = true}; coverage.SetValues(new double[] {1, 2, 3, 4}, new VariableValueFilter<DateTime>(coverage.Time, t1)); coverage.SetValues(new double[] { 10, 20, 30, 40 }, new VariableValueFilter<DateTime>(coverage.Time, t2)); var clonedCoverage = (IRegularGridCoverage) coverage.Clone(); Assert.AreEqual(clonedCoverage.Time.Values.Count, coverage.Time.Values.Count); }
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); }
public void FilterCoverage() { IRegularGridCoverage gridWithTime = new RegularGridCoverage(2, 3, 100, 50) { Name = "pressure" }; var time = new Variable<DateTime>("time"); gridWithTime.Time = time; DateTime time1 = DateTime.Now; var values1 = new[] {1.0, 2.0, 3.0, 4.0, 5.0, 6.0}; gridWithTime.SetValues(values1, new VariableValueFilter<DateTime>(time, time1)); DateTime time2 = time1.AddDays(1); var values2 = new[] {10.0, 20.0, 30.0, 40.0, 50.0, 60.0}; gridWithTime.SetValues(values2, new VariableValueFilter<DateTime>(time, time2)); var filteredGrid = gridWithTime.FilterAsRegularGridCoverage(new VariableValueFilter<DateTime>(time, time2)); Assert.AreEqual(6, filteredGrid.Components[0].Values.Count); Assert.AreEqual(gridWithTime.Store, filteredGrid.Store); var sizeX = gridWithTime.SizeX; var filteredSizeX = filteredGrid.SizeX; Assert.AreEqual(sizeX, filteredSizeX); Assert.AreEqual(gridWithTime.SizeY, filteredGrid.SizeY); Assert.AreEqual(gridWithTime.DeltaX, filteredGrid.DeltaX); Assert.AreEqual(gridWithTime.DeltaY, filteredGrid.DeltaY); Assert.AreEqual(gridWithTime.Arguments.Count, filteredGrid.Arguments.Count); Assert.AreEqual(gridWithTime.Components.Count, filteredGrid.Components.Count); Assert.AreEqual(gridWithTime.Geometry, filteredGrid.Geometry); }
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 EvaluateCoordinateForCornerCases() { var grid = new RegularGridCoverage(2, 2, 5.0, 5.0); grid.SetValues(new[]{12.34}); Assert.AreEqual(12.34, grid.Evaluate(new Coordinate(0.0, 0.0))); Assert.AreEqual(12.34, grid.Evaluate(new Coordinate(10.0, 0.0))); Assert.AreEqual(12.34, grid.Evaluate(new Coordinate(0.0, 10.0))); Assert.AreEqual(12.34, grid.Evaluate(new Coordinate(10.0, 10.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 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); }
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}); }
public void SelectOnlySpecificValuesUsingAggregationFilter() // TODO: migrate to fit tests { IRegularGridCoverage grid2D = new RegularGridCoverage(4, 4, 1, 1); var values = new[,] { {1.0, 2.0, 3.0, 4.0}, {1.0, 2.0, 3.0, 4.0}, {1.0, 2.0, 3.0, 4.0}, {1.0, 2.0, 3.0, 4.0}, // ^ ^ }; grid2D.SetValues(values); var subSelection = grid2D.GetValues<double>(new VariableAggregationFilter(grid2D.X, 2, 0, 3)); Assert.IsTrue(subSelection.SequenceEqual(new[] {1.0, 3.0, 1.0, 3.0, 1.0, 3.0, 1.0, 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 SelectOnlySpecificValuesUsingAggregationFilterFromBottom() // TODO: migrate to fit tests { IRegularGridCoverage grid2D = new RegularGridCoverage(4, 4, 1, 1); var values = new[,] { {1.1, 2.1, 3.1, 4.1}, {1.2, 2.2, 3.2, 4.2}, {1.3, 2.3, 3.3, 4.3}, // <- {1.4, 2.4, 3.4, 4.4}, // <- }; grid2D.SetValues(values); var subSelection = grid2D.GetValues<double>(new VariableAggregationFilter(grid2D.Y, 1, 2, 3)); Assert.IsTrue(subSelection.SequenceEqual(new[] {1.3, 2.3, 3.3, 4.3, 1.4, 2.4, 3.4, 4.4})); }
public void ShowRegularGridWithQuantityThemeOnMap() { IRegularGridCoverage grid2D = new RegularGridCoverage(200, 200, 10, 10) { Name = "pressure" }; double[] values = new double[grid2D.SizeX*grid2D.SizeY]; double min = 0; double max = 0; for (int i = 0; i < values.Length; i++) { values[i] = i; if (values[i] > max) max = values[i]; if (values[i] < min) min = values[i]; } grid2D.SetValues(values); var map = new Map(); var rasterLayer = new RegularGridCoverageLayer {Grid = grid2D}; var defaultStyle = new VectorStyle {GeometryType = typeof (IPolygon), Line = Pens.SeaGreen}; double interval = (max - min)/10; var intervalList = new List<Interval>(); double start = min; double stop = min + interval; for (int i = 0; i < 10; i++) { intervalList.Add(new Interval(start, stop)); start = stop; stop += interval; } QuantityTheme quantityTheme = ThemeFactory.CreateQuantityTheme(grid2D.Components[0].Name, defaultStyle, ColorBlend.BlueToGreen, 10, intervalList ); rasterLayer.Theme = quantityTheme; map.Layers.Add(rasterLayer); MapTestHelper.ShowModal(map); }
private static IRegularGridCoverage CreatePressureTimeDependentRegularGridCoverage(out DateTime time1, out DateTime time2) { IRegularGridCoverage grid2D = new RegularGridCoverage(2, 3, 100, 50) { // default constructor will set x[0] to 0.0 and y[0] to 0.0 Name = "pressure" }; var time = new Variable<DateTime>("time"); grid2D.Time = time; time1 = DateTime.Now; var values1 = new[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }; grid2D.SetValues(values1, new VariableValueFilter<DateTime>(time, time1)); Assert.AreEqual(6, grid2D.GetValues<double>().Count); time2 = time1.AddDays(1); var values2 = new[] { 10.0, 20.0, 30.0, 40.0, 50.0, 60.0 }; grid2D.SetValues(values2, new VariableValueFilter<DateTime>(time, time2)); // resulting dynamic coverage is // t = now t = now + 1day // x = 0 x = 100 x = 0 x = 100 // // y = 0 | 1.0 2.0 | 10.0 20.0 // y = 50 | 3.0 4.0 | 30.0 40.0 // y = 100 | 5.0 6.0 | 50.0 60.0 // // return grid2D; }
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 }); }