Beispiel #1
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 });
        }
Beispiel #2
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);
        }
        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 CopyConstructor()
        {
            IRegularGridCoverage coverage = new RegularGridCoverage(2, 3, 10, 20);

            coverage.Components[0].NoDataValues.Clear();
            coverage.Components[0].NoDataValues.Add(-1.0d);
            coverage.Components[0].DefaultValue = 100;
            coverage.Components[0].Unit         = new Unit("meter", "m");
            coverage.IsTimeDependent            = true;
            var copy = new RegularGridCoverage(coverage);

            Assert.AreEqual(2, copy.SizeX);
            Assert.AreEqual(3, copy.SizeY);
            Assert.AreEqual(10, copy.DeltaX);
            Assert.AreEqual(20, copy.DeltaY);
            Assert.AreEqual(1, copy.Components[0].NoDataValues.Count);
            Assert.AreEqual(100, copy.Components[0].DefaultValue);
            Assert.AreEqual("meter", copy.Components[0].Unit.Name);

            Assert.IsTrue(coverage.X.Values.SequenceEqual(copy.X.Values));
            Assert.IsTrue(coverage.Y.Values.SequenceEqual(copy.Y.Values));
            Assert.IsTrue(copy.X == copy.Arguments[2]);
            Assert.IsTrue(copy.Y == copy.Arguments[1]);
            Assert.IsTrue(copy.Time == copy.Arguments[0]);
        }
Beispiel #5
0
        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);
        }
Beispiel #6
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 });
        }
Beispiel #7
0
        public void Issue1372DataItemSetIsConsistenBeforeAnyBubblingOccurs()
        {
            var dataItemSet = CreateDataItemSet <IRegularGridCoverage>();

            var items    = dataItemSet.AsEventedList <IRegularGridCoverage>();
            var coverage = new RegularGridCoverage {
                Name = "oldCoverage"
            };

            items.Add(coverage);

            Assert.AreEqual(1, dataItemSet.Count);
            var newCoverage = new RegularGridCoverage {
                Name = "newCoverage"
            };

            int callCount = 0;

            ((INotifyPropertyChanged)dataItemSet).PropertyChanged += delegate
            {
                callCount++;
                //synchronization problem
                Assert.AreEqual(newCoverage, items[0]);
            };

            dataItemSet[0].Value = newCoverage;

            Assert.AreEqual(1, callCount);
        }
Beispiel #8
0
        public void GetTimesFromFilteredCoverage()
        {
            var coverage = new RegularGridCoverage(2, 2, 10, 10);

            coverage.IsTimeDependent = true;
            var firstTime  = new DateTime(2000, 1, 1);
            var secondTime = new DateTime(2000, 1, 2);

            coverage.Time.Values.Add(firstTime);
            coverage.Time.Values.Add(secondTime);


            //create a layer
            var layer = new RegularGridCoverageLayer {
                Coverage = coverage
            };

            Assert.AreEqual(2, layer.Times.Count());

            //action! set the time
            layer.SetCurrentTimeSelection(secondTime, null);

            //assert the start time got there
            Assert.AreEqual(secondTime, layer.TimeSelectionStart);
            //assert the rendercoverage got updated
            var timeFilter =
                (VariableValueFilter <DateTime>)
                layer.RenderedCoverage.Filters.OfType <IVariableValueFilter>().FirstOrDefault();

            Assert.AreEqual(new[] { secondTime }, timeFilter.Values);
        }
        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 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 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 ReAddComponent()
        {
            IRegularGridCoverage coverage = new RegularGridCoverage(2, 3, 10, 20);

            coverage.Components.RemoveAt(0);
            coverage.Components.Add(new Variable <double>());
            Assert.AreEqual(4, coverage.Store.Functions.Count);
        }
Beispiel #13
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 ClearResizesToZeroZero()
        {
            IRegularGridCoverage grid2D = new RegularGridCoverage(4, 4, 1, 1);

            grid2D.Clear();

            Assert.AreEqual(0, grid2D.SizeX);
            Assert.AreEqual(0, grid2D.SizeY);
        }
        public void CheckEnvelope()
        {
            IRegularGridCoverage coverage = new RegularGridCoverage(2, 3, 10, 20)
            {
                Name = "test"
            };

            Assert.AreEqual(20, coverage.Geometry.Envelope.EnvelopeInternal.MaxX, 1e-8);
            Assert.AreEqual(60, coverage.Geometry.Envelope.EnvelopeInternal.MaxY, 1e-8);
        }
        public void ResizeIsFast()
        {
            //TODO: make this really fast by optimizing resize...
            IRegularGridCoverage grid = new RegularGridCoverage();

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

            Assert.AreEqual(1000000, grid.Components[0].Values.Count);
            log.InfoFormat("This is still toooooo slow!");
        }
        public void EnvelopeChangesWhenCoverageIsCleared()
        {
            var coverage = new RegularGridCoverage(10, 10, 1, 1);
            var layer = new RegularGridCoverageLayer { Coverage = coverage };
            var envelope = new Envelope(0, 10, 0, 10);
            Assert.AreEqual(envelope, layer.Envelope);

            coverage.Clear();
            var EmptyEnvelope = new Envelope(0, 0, 0, 0);
            Assert.AreEqual(EmptyEnvelope, layer.Envelope);
        }
        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 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;
        }
Beispiel #20
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);
        }
        public void ResizeAndAddTime()
        {
            var coverage = new RegularGridCoverage()
            {
                IsTimeDependent = true
            };

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

            originalGrid.Resize(2, 4, 8, 16, new Coordinate(10, 100));
            Assert.AreEqual(2, originalGrid.SizeX);
            Assert.AreEqual(4, originalGrid.SizeY);
            Assert.AreEqual(8, originalGrid.DeltaX);
            Assert.AreEqual(16, originalGrid.DeltaY);
            Assert.AreEqual(10, originalGrid.X.Values[0]);
            Assert.AreEqual(100, originalGrid.Y.Values[0]);
        }
        public void ClearingCoverageCauseRenderRequired()
        {
            var coverage = new RegularGridCoverage(10, 10, 1, 1);
            var layer = new RegularGridCoverageLayer { Coverage = coverage };
            layer.Map = new Map(new Size(10,10));
            layer.Render();
            Assert.IsFalse(layer.RenderRequired);

            //action!
            coverage.Clear();

            Assert.IsTrue(layer.RenderRequired);
        }
        public void ResizeSetsDefaultValues()
        {
            IRegularGridCoverage grid = new RegularGridCoverage();

            grid.Components[0].DefaultValue = 5.0;

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

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

            Assert.IsTrue(variable.Values.All(v => v == 5.0));
        }
Beispiel #25
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);
        }
Beispiel #26
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 }))));
        }
Beispiel #27
0
        public void EnvelopeChangesWhenCoverageIsCleared()
        {
            var coverage = new RegularGridCoverage(10, 10, 1, 1);
            var layer    = new RegularGridCoverageLayer {
                Coverage = coverage
            };
            var envelope = new Envelope(0, 10, 0, 10);

            Assert.AreEqual(envelope, layer.Envelope);

            coverage.Clear();
            var EmptyEnvelope = new Envelope(0, 0, 0, 0);

            Assert.AreEqual(EmptyEnvelope, layer.Envelope);
        }
Beispiel #28
0
        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 RegularGridResize()
        {
            IRegularGridCoverage regularGridCoverage = new RegularGridCoverage();

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

            Assert.AreEqual(50, regularGridCoverage.Y.Values.Count);
            Assert.AreEqual(0, regularGridCoverage.Y.Values[0]);
            Assert.AreEqual(20, regularGridCoverage.Y.Values[1]);
            Assert.AreEqual(980, regularGridCoverage.Y.Values[49]);
        }
Beispiel #30
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);
        }
Beispiel #31
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);
        }
Beispiel #32
0
        public void ClearingCoverageCauseRenderRequired()
        {
            var coverage = new RegularGridCoverage(10, 10, 1, 1);
            var layer    = new RegularGridCoverageLayer {
                Coverage = coverage
            };

            layer.Map = new Map(new Size(10, 10));
            layer.Render();
            Assert.IsFalse(layer.RenderRequired);

            //action!
            coverage.Clear();

            Assert.IsTrue(layer.RenderRequired);
        }
        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 CreateRegularGridCoverageUsingGivenComponentValueType()
        {
            var sizeX  = 2; // number of values along x dimension
            var sizeY  = 2;
            var deltaX = 1;
            var deltaY = 1;

            var componentValueType = typeof(int);

            var grid = new RegularGridCoverage(sizeX, sizeY, deltaX, deltaY, componentValueType);

            grid.Components.Count
            .Should().Be.EqualTo(1);

            grid.Components[0].ValueType
            .Should().Be.EqualTo(componentValueType);
        }
Beispiel #35
0
        public void ResizeIsFast()
        {
            IRegularGridCoverage grid = new RegularGridCoverage();
            var startTime             = DateTime.Now;

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

            Console.WriteLine(dt);

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

            Assert.AreEqual(1000000, grid.Components[0].Values.Count);
            log.InfoFormat("Resized to 1000x1000 in {0}", dt);
            log.InfoFormat("This is still toooooo slow!");
        }
        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 CreateRegularGridCoverageUsingGivenComponentValueType()
        {
            var sizeX = 2; // number of values along x dimension
            var sizeY = 2;
            var deltaX = 1;
            var deltaY = 1;

            var componentValueType = typeof(int);

            var grid = new RegularGridCoverage(sizeX, sizeY, deltaX, deltaY, componentValueType);

            grid.Components.Count
                .Should().Be.EqualTo(1);

            grid.Components[0].ValueType
                .Should().Be.EqualTo(componentValueType);
        }
        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;
        }
Beispiel #39
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");
        }
        public void ChangesInLayersBubbleUpToMap()
        {
            var coverage = new RegularGridCoverage(10, 10, 1, 1);
            var layer = new RegularGridCoverageLayer { Coverage = coverage };
            int callCount = 0;
            var senders = new object[] {coverage};
            var propertyNames = new[] {"Name"};

            ((INotifyPropertyChanged)layer).PropertyChanged += (sender,args)=>
            {
                Assert.AreEqual(senders[callCount], sender);
                Assert.AreEqual(propertyNames[callCount], args.PropertyName);

                callCount++;
            };

            //change the name of the layer
            coverage.Name = "new name";

            //should result in property changed of map
            Assert.AreEqual(1, callCount);
        }
        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 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 ReAddComponent()
 {
     IRegularGridCoverage coverage = new RegularGridCoverage(2, 3, 10, 20);
     coverage.Components.RemoveAt(0);
     coverage.Components.Add(new Variable<double>());
     Assert.AreEqual(4, coverage.Store.Functions.Count);
 }
 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 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 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 ClearResizesToZeroZero()
        {
            IRegularGridCoverage grid2D = new RegularGridCoverage(4, 4, 1, 1);
            grid2D.Clear();

            Assert.AreEqual(0, grid2D.SizeX);
            Assert.AreEqual(0, grid2D.SizeY);
        }
        public void Clone()
        {
            IRegularGridCoverage coverage = new RegularGridCoverage(2, 3, 10, 20, 5, 60);
            coverage.Components[0].NoDataValues.Add(-1.0d);
            coverage.Components[0].DefaultValue = 100;
            coverage.Components[0].Name = "values";
            coverage.Components[0].Unit = new Unit("meter", "m");

            var clonedCoverage = (IRegularGridCoverage) coverage.Clone();

            Assert.AreEqual(2, clonedCoverage.SizeX);
            Assert.AreEqual(3, clonedCoverage.SizeY);
            Assert.AreEqual(10, clonedCoverage.DeltaX);
            Assert.AreEqual(20, clonedCoverage.DeltaY);
            Assert.AreEqual(coverage.Components[0].Name, clonedCoverage.Components[0].Name);
            Assert.AreEqual(1, clonedCoverage.Components[0].NoDataValues.Count);
            Assert.AreEqual(100, clonedCoverage.Components[0].DefaultValue);
            Assert.AreEqual("meter", clonedCoverage.Components[0].Unit.Name);
            Assert.AreEqual(5, clonedCoverage.Origin.X);
            Assert.AreEqual(60, clonedCoverage.Origin.Y);
        }
        public void RegularGridResize()
        {
            IRegularGridCoverage regularGridCoverage = new RegularGridCoverage();
            regularGridCoverage.Resize(100, 50, 10, 20);
            Assert.AreEqual(100, regularGridCoverage.X.Values.Count);
            Assert.AreEqual(0, regularGridCoverage.X.Values[0]);
            Assert.AreEqual(10, regularGridCoverage.X.Values[1]);
            Assert.AreEqual(990, regularGridCoverage.X.Values[99]);

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

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

            Assert.AreEqual(1000000, grid.Components[0].Values.Count);
            log.InfoFormat("This is still toooooo slow!");
        }
        public void 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 FilterIncludesAllComponents()
        {
            IRegularGridCoverage gridWithTime = new RegularGridCoverage(2, 3, 100, 50)
                                                    {
                                                        Name = "pressure"
                                                    };

            var time = new Variable<DateTime>("time");
            DateTime startTime = DateTime.Now;
            time.Values.Add(startTime);
            gridWithTime.Time = time;
            gridWithTime.Components.Add(new Variable<string>("second"));

            var filteredGrid = gridWithTime.Filter(new VariableValueFilter<DateTime>(time, startTime));
            Assert.AreEqual(2, filteredGrid.Components.Count);
        }
        public void CheckEnvelope()
        {
            IRegularGridCoverage coverage = new RegularGridCoverage(2, 3, 10, 20)
                                                {
                                                    Name = "test"
                                                };

            Assert.AreEqual(20, coverage.Geometry.Envelope.EnvelopeInternal.MaxX, 1e-8);
            Assert.AreEqual(60, coverage.Geometry.Envelope.EnvelopeInternal.MaxY, 1e-8);
        }
        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 ResizeSetsDefaultValues()
 {
     IRegularGridCoverage grid = new RegularGridCoverage();
     grid.Components[0].DefaultValue = 5.0;
     
     grid.Resize(10, 10, 1, 1);
     
     //check the values
     var variable = (IVariable<double>)grid.Components[0];
     Assert.IsTrue(variable.Values.All(v=>v== 5.0));
 }
        public void 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 EvaluateTimeDependent()
        {
            var grid = new RegularGridCoverage(2, 2, 1, 1) { IsTimeDependent = true };

            var values = new[,]
                             {
                                 {1.0, 2.0},
                                 {3.0, 4.0}
                             };

            grid[new DateTime(2000, 1, 1)] = values;
            grid[new DateTime(2000, 1, 3)] = values;

            // evaluate value, interpolated in time and space (default interpolation is piecewise constant)
            var value = grid.Evaluate(new Coordinate(0.5, 0.5), new DateTime(2000, 1, 2));

            value
                .Should("evaluate time-dependent regular grid coverage value").Be.EqualTo(1.0);

        }
        public void CopyConstructor()
        {
            IRegularGridCoverage coverage = new RegularGridCoverage(2, 3, 10, 20);
            coverage.Components[0].NoDataValues.Clear();
            coverage.Components[0].NoDataValues.Add(-1.0d);
            coverage.Components[0].DefaultValue = 100;
            coverage.Components[0].Unit = new Unit("meter", "m");
            coverage.IsTimeDependent = true;
            var copy = new RegularGridCoverage(coverage);

            Assert.AreEqual(2, copy.SizeX);
            Assert.AreEqual(3, copy.SizeY);
            Assert.AreEqual(10, copy.DeltaX);
            Assert.AreEqual(20, copy.DeltaY);
            Assert.AreEqual(1, copy.Components[0].NoDataValues.Count);
            Assert.AreEqual(100, copy.Components[0].DefaultValue);
            Assert.AreEqual("meter", copy.Components[0].Unit.Name);

            Assert.IsTrue(coverage.X.Values.SequenceEqual(copy.X.Values));
            Assert.IsTrue(coverage.Y.Values.SequenceEqual(copy.Y.Values));
            Assert.IsTrue(copy.X == copy.Arguments[2]);
            Assert.IsTrue(copy.Y == copy.Arguments[1]);
            Assert.IsTrue(copy.Time == copy.Arguments[0]);

        }
 public void Resize()
 {
     var originalGrid = new RegularGridCoverage(2, 2, 5, 5);
     originalGrid.Resize(2, 4, 8, 16, new Coordinate(10, 100));
     Assert.AreEqual(2, originalGrid.SizeX);
     Assert.AreEqual(4, originalGrid.SizeY);
     Assert.AreEqual(8, originalGrid.DeltaX);
     Assert.AreEqual(16, originalGrid.DeltaY);
     Assert.AreEqual(10, originalGrid.X.Values[0]);
     Assert.AreEqual(100, originalGrid.Y.Values[0]);
 }
        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;
        }