Esempio n. 1
0
        /// <summary>
        /// Gets the FeatureLayer that is used for the selection tests.
        /// </summary>
        /// <param name="cat">Reference to the second category.</param>
        /// <returns>The FeatureLayer.</returns>
        private static IFeatureLayer GetFeatureLayer(out PolygonCategory cat)
        {
            // load layer with us states
            ShapefileLayerProvider provider = new();
            var fl = (IFeatureLayer)provider.OpenLayer(Common.AbsolutePath(Path.Combine(@"TestFiles", "50mil_us_states.shp")), false, null, null);

            Assert.IsNotNull(fl);

            // add two categories for testing category.SelectionEnabled
            PolygonScheme scheme = new();

            scheme.ClearCategories();
            scheme.AddCategory(new PolygonCategory(Color.LightBlue, Color.DarkBlue, 1)
            {
                FilterExpression = "[FIPS] >= 10",
                LegendText       = ">= 10"
            });
            cat = new PolygonCategory(Color.Pink, Color.DarkRed, 1)
            {
                FilterExpression = "[FIPS] < 10",
                LegendText       = "< 10"
            };
            scheme.AddCategory(cat);
            fl.Symbology = scheme;
            Assert.IsTrue(cat.SelectionEnabled, "Categories must be initialized with SelectionEnabled = true.");
            return(fl);
        }
Esempio n. 2
0
        public void CanExportPointShapeWithNullShapes(bool indexMode)
        {
            string path   = Common.AbsolutePath(@"Data\Shapefiles\Yield\Yield 2012.shp");
            var    target = new PointShapefile(path);

            Assert.IsTrue(target.Features.Count > 0);
            target.IndexMode = indexMode;

            var exportPath = FileTools.GetTempFileName(".shp");

            target.SaveAs(exportPath, true);

            try
            {
                var actual = new PointShapefile(exportPath);
                Assert.IsNotNull(actual);
                Assert.AreEqual(target.ShapeIndices.Count, actual.ShapeIndices.Count);
                Assert.AreEqual(target.ShapeIndices.Count(d => d.ShapeType == ShapeType.NullShape), actual.ShapeIndices.Count(d => d.ShapeType == ShapeType.NullShape));
                Assert.AreEqual(target.Features.Count, actual.Features.Count);
                Assert.AreEqual(target.Features.Count(d => d.Geometry.IsEmpty), actual.Features.Count(d => d.Geometry.IsEmpty));
            }
            finally
            {
                FileTools.DeleteShapeFile(exportPath);
            }
        }
Esempio n. 3
0
        public void ReadNullValues()
        {
            string path = Common.AbsolutePath(@"Data\Shapefiles\NullValues.dbf");

            var expectedRows = new object[6][];

            expectedRows[0] = new object[] { DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value };
            expectedRows[1] = new object[] { 1, 1.0, new DateTime(2016, 1, 1), true, "foo" };
            expectedRows[2] = new object[] { 2, 2.0, new DateTime(2016, 1, 1), false, "bar" };
            expectedRows[3] = new object[] { 1, DBNull.Value, new DateTime(2016, 1, 1), true, "test" };
            expectedRows[4] = new object[] { DBNull.Value, 1.0, DBNull.Value, false, DBNull.Value };
            expectedRows[5] = new object[] { 1234567890, 123456.0987, new DateTime(2016, 12, 31), DBNull.Value, "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takima" };

            var at = new AttributeTable(path);
            var dt = at.SupplyPageOfData(0, expectedRows.Length);

            Assert.IsNotNull(dt);

            for (var iRow = 0; iRow < expectedRows.Length; ++iRow)
            {
                Assert.IsNotNull(dt.Rows[iRow]);
                var content = dt.Rows[iRow].ItemArray;
                for (var iField = 0; iField < expectedRows[iRow].Length; ++iField)
                {
                    Assert.AreEqual(expectedRows[iRow][iField], content[iField]);
                }
            }
        }
Esempio n. 4
0
        public void GetCustomSettingFromFileTest()
        {
            Map        map    = new Map();
            AppManager target = new AppManager
            {
                Map = map
            };

            string uniqueName = "customsettingname";
            var    expected   = DateTime.Now;

            target.SerializationManager.SetCustomSetting(uniqueName, expected);

            var actual = target.SerializationManager.GetCustomSetting(uniqueName, DateTime.Now.AddDays(1));

            Assert.AreEqual(expected, actual);

            string path = Path.Combine(Common.AbsolutePath("TestFiles"), "SerializeTestWithCustomSettings.map.xml.dspx");

            target.SerializationManager.SaveProject(path);

            target.SerializationManager.OpenProject(path);
            actual = target.SerializationManager.GetCustomSetting(uniqueName, DateTime.Now.AddDays(1));
            Assert.AreEqual(expected.ToLongDateString(), actual.ToLongDateString());

            File.Delete(path);
        }
        public void CanReadShapefileWithManyByteBlocks()
        {
            string path   = Common.AbsolutePath(@"Data\Shapefiles\nos80k\nos80k.shp");
            var    target = new PolygonShapefile(path);

            Assert.IsNotNull(target);
            Assert.IsNotNull(target.ShapeIndices);
        }
Esempio n. 6
0
        public void GdalRasterTest()
        {
            var rp     = new GdalRasterProvider();
            var raster = rp.Open(Common.AbsolutePath(@"Data\Grids\sample_geotiff.tif"));
            var at     = new AffineTransform(raster.Bounds.AffineCoefficients);

            Assert.AreEqual(at.CellCenterToProj(0, 0), new Coordinate(-179.9499969, 89.9499969)); // correct location from sample_geotiff.tfw
        }
Esempio n. 7
0
        public void InRamImageDataCtorLoadsImageWithColor()
        {
            var imagePath = Common.AbsolutePath(Path.Combine(@"Data\Grids", "Hintergrundkarte.tif"));

            using var inram  = new InRamImageData(imagePath);
            using var bitmap = inram.GetBitmap();
            Assert.AreEqual(Color.FromArgb(255, 125, 105, 72), bitmap.GetPixel(300, 300)); // if the image was not drawn correctly GetPixel returns the ARGB values for white
        }
Esempio n. 8
0
        public void CanReadLineShapeWithNullShapes()
        {
            string path   = Common.AbsolutePath(@"Data\Shapefiles\Archi\ARCHI_13-01-01.shp");
            var    target = new LineShapefile(path);

            Assert.IsNotNull(target);
            Assert.AreEqual(11, target.ShapeIndices.Count(d => d.ShapeType == ShapeType.NullShape));
            Assert.AreEqual(11, target.Features.Count(d => d.Geometry.IsEmpty));
        }
Esempio n. 9
0
        public void CanLoadShapePointWithNullShapes()
        {
            string path   = Common.AbsolutePath(@"Data\Shapefiles\Yield\Yield 2012.shp");
            var    target = new PointShapefile(path);

            Assert.IsNotNull(target);
            Assert.AreEqual(target.ShapeIndices.Count(d => d.ShapeType == ShapeType.NullShape), 1792);
            Assert.AreEqual(target.Features.Count(d => d.Geometry.IsEmpty), 1792);
        }
Esempio n. 10
0
        public void CanReadPointZWithoutM()
        {
            string path   = Common.AbsolutePath(@"Data\Shapefiles\shp-no-m\SPATIAL_F_LUFTNINGSVENTIL.shp");
            var    target = new PointShapefile(path);

            Assert.AreEqual(CoordinateType.Z, target.CoordinateType);
            Assert.IsNotNull(target.Z);
            Assert.IsNotNull(target.M);
            Assert.IsTrue(target.M.All(d => d < -1e38));
        }
Esempio n. 11
0
        public void CanReadDataRowWithZeroDates()
        {
            string path = Common.AbsolutePath(@"Data\Shapefiles\DateShapefile\DateShapefile.dbf");
            var    at   = new AttributeTable(path);
            var    dt   = at.SupplyPageOfData(0, 1);

            Assert.IsNotNull(dt);
            Assert.IsNotNull(dt.Rows[0]);
            Assert.AreEqual(DBNull.Value, dt.Rows[0]["datefiled"]);
        }
Esempio n. 12
0
        static Proj4()
        {
            // init proj delegates
            var basePath = (IntPtr.Size == 8) ? "x64" : "x86";
            var path     = System.IO.Path.Combine(Common.AbsolutePath(basePath), "proj.dll");

            _pj_init_plus  = (pj_init_plus_delegate)FunctionLoader.LoadFunction <pj_init_plus_delegate>(path, "pj_init_plus");
            _pj_free       = (pj_free_delegate)FunctionLoader.LoadFunction <pj_free_delegate>(path, "pj_free");
            _pj_transform  = (pj_transform_delegate)FunctionLoader.LoadFunction <pj_transform_delegate>(path, "pj_transform");
            _pj_is_latlong = (pj_is_latlong_delegate)FunctionLoader.LoadFunction <pj_is_latlong_delegate>(path, "pj_is_latlong");
        }
        public void CopyAttributesToClipped()
        {
            var target = new ClipPolygonWithPolygon();

            // load input 1 Shapefile as IFeatureSet
            IFeatureSet europeShape = Shapefile.OpenFile(Common.AbsolutePath(@"Data\ClipPolygonWithPolygonTests\EUR_countries.shp"));

            // load input 2 Shapefile as IFeatureSet
            IFeatureSet belgiumShape = Shapefile.OpenFile(Common.AbsolutePath(@"Data\ClipPolygonWithPolygonTests\Belgium.shp"));

            // set output file as IFeatureSet shapefile
            IFeatureSet outputShape = new FeatureSet()
            {
                Filename = FileTools.GetTempFileName(".shp")
            };

            target.Execute(europeShape, belgiumShape, outputShape, new MockProgressHandler());

            // the output file needs to be closed and re-opened, because the DataTable in memory does not match the DataTable on disk
            outputShape.Close();
            var outputFile = FeatureSet.Open(outputShape.Filename);

            try
            {
                // output shapefile attribute columns should match the input 1 attribute columns
                Assert.That(outputFile.DataTable.Columns[0].Caption.Equals("ID"));
                Assert.That(outputFile.DataTable.Columns[1].Caption.Equals("Name"));

                string[,] dataValues =
                {
                    { "BE", "Belgium"    },
                    { "DE", "Germany"    },
                    { "LU", "Luxembourg" }
                };

                var mpCount = 0;
                foreach (var feature in outputFile.Features)
                {
                    Assert.That(feature.DataRow.ItemArray.Length == 2 && feature.DataRow.ItemArray[0].Equals(dataValues[mpCount, 0]) && feature.DataRow.ItemArray[1].Equals(dataValues[mpCount, 1]));
                    mpCount++;
                }

                Assert.That(mpCount == 3);
            }
            finally
            {
                FileTools.DeleteShapeFile(outputShape.Filename);
            }
        }
        public void ExcecuteDoesntLoseOutputFilename()
        {
            var target = new ClipPolygonWithLine();

            IFeatureSet fsInput1 = FeatureSet.Open(Common.AbsolutePath(@"Data\ClipPolygonWithLineTests\polygon.shp"));
            IFeatureSet fsInput2 = FeatureSet.Open(Common.AbsolutePath(@"Data\ClipPolygonWithLineTests\line.shp"));
            IFeatureSet fsOutput = new FeatureSet
            {
                Filename = FileTools.GetTempFileName(".shp")
            };

            Assert.DoesNotThrow(() => target.Execute(fsInput1, fsInput2, fsOutput, new MockProgressHandler()));
            Assert.AreNotEqual(string.IsNullOrWhiteSpace(fsOutput.Filename), true);

            FileTools.DeleteShapeFile(fsOutput.Filename);
        }
Esempio n. 15
0
        public void EachHoleExistsOnlyOnce()
        {
            string filePath = Common.AbsolutePath(@"Data\Shapefiles\Multipolygon\PolygonInHole.shp"); // Replace with path to file

            using var file = new PolygonShapefile(filePath);
            Assert.AreEqual(1, file.Features.Count, "Expected the shapefile to have only 1 feature.");

            IFeature feature = file.GetFeature(0);

            Assert.AreEqual(2, feature.Geometry.NumGeometries, "Expect the feature to consist out of 2 geometries.");

            for (int i = 0; i < feature.Geometry.NumGeometries; i++)
            {
                var polygon = (Polygon)feature.Geometry.GetGeometryN(i);
                Assert.AreEqual(1, polygon.NumInteriorRings, "Expect each polygon part to have 1 hole.");
            }
        }
Esempio n. 16
0
        public void ShapeReaderSkippingTest()
        {
            string path   = Common.AbsolutePath(@"Data\Shapefiles\shp-no-m\SPATIAL_F_LUFTNINGSVENTIL.shp");
            var    source = new PointShapefileShapeSource(path);

            var target = new ShapeReader(source)
            {
                PageSize = 10
            };
            int expectedStartIndex = 0;

            foreach (var page in target)
            {
                Assert.AreEqual(expectedStartIndex, page.Keys.Min(), "Shape reader skipped at least one entry.");
                expectedStartIndex = page.Keys.Max() + 1;
            }
        }
Esempio n. 17
0
        public void ClipRasterWithPolygonTest()
        {
            var folder = Common.AbsolutePath("Data");

            var shapeFilePath  = Path.Combine(folder, "elbe_watershed1.shp");
            var rasterFilePath = Path.Combine(folder, "kriging.bgd");
            var resultFilePath = Path.Combine(folder, "clipResult.bgd");

            var lClipPolygon = Shapefile.OpenFile(shapeFilePath);
            var lGridToClip  = Raster.OpenFile(rasterFilePath, false);

            var lGridAfterClip = new Raster {
                Filename = resultFilePath
            };

            ClipRaster.ClipRasterWithPolygon(lClipPolygon.Features[0], lGridToClip, lGridAfterClip.Filename);
            var ras2 = Raster.Open(lGridAfterClip.Filename);

            Assert.AreEqual(lGridToClip.NoDataValue, ras2.NoDataValue);
        }
Esempio n. 18
0
        public void SaveAsTest()
        {
            string gridDataFolder = Common.AbsolutePath(@"Data\Grids\");
            var    p                 = new GdalRasterProvider();
            var    sourceGrid        = p.Open(Path.Combine(gridDataFolder, @"elev_cm_ESRI\elev_cm_clip2\hdr.adf"));
            var    sourceGridMaximum = sourceGrid.Maximum;

            string savedGridName = Path.Combine(gridDataFolder, @"elev_cm.tif");

            sourceGrid.SaveAs(savedGridName);

            Assert.AreEqual(sourceGrid.Maximum, sourceGridMaximum, 0.0001);

            var savedSourceGrid = Raster.Open(savedGridName);

            Assert.AreEqual(sourceGridMaximum, savedSourceGrid.Maximum, 0.0001);

            sourceGrid.Close();
            savedSourceGrid.Close();
            File.Delete(savedGridName);
        }
Esempio n. 19
0
        public void SlopeIsWorking()
        {
            var raster = Raster.Open(Path.Combine(Common.AbsolutePath("Data"), "kriging.bgd"));
            var actual = Slope.GetSlope(raster, 1, true, null);

            try
            {
                Assert.IsNotNull(actual);
                Assert.AreEqual(raster.Extent, actual.Extent);
                Assert.AreEqual(raster.NumColumns, actual.NumColumns);
                Assert.AreEqual(raster.NumRows, actual.NumRows);
                Assert.AreEqual(raster.CellHeight, actual.CellHeight);
                Assert.AreEqual(raster.CellWidth, actual.CellWidth);

                // Test that some output values are non zeros and non NoData
                var existsSomeValidValues = false;
                for (int i = 0; i < raster.NumRows; i++)
                {
                    for (int j = 0; j < raster.NumColumns; j++)
                    {
                        if (raster.Value[i, j] != 0 &&
                            raster.Value[i, j] != raster.NoDataValue)
                        {
                            existsSomeValidValues = true;
                            goto finCycle;
                        }
                    }
                }

finCycle:
                Assert.IsTrue(existsSomeValidValues);
            }
            finally
            {
                File.Delete(actual.Filename);
            }
        }
Esempio n. 20
0
        public void CanOpenProjectFile(string mprojFile, string projectFileVer)
        {
            var path = Common.AbsolutePath(mprojFile);

            var map      = new Map();
            var target   = new LegacyProjectDeserializer(map);
            var curDir   = Environment.CurrentDirectory;
            var fileInfo = new FileInfo(path);

            try
            {
                dynamic parser = DynamicXMLNode.Load(path);
                Assert.AreEqual(projectFileVer, (string)parser["type"]);
                Assert.AreEqual(0, map.Layers.Count);
                Environment.CurrentDirectory = fileInfo.DirectoryName;
                target.OpenFile(fileInfo.FullName);
                Assert.Greater(map.Layers.Count, 0);
            }
            finally
            {
                // Restore current directory
                Environment.CurrentDirectory = curDir;
            }
        }
Esempio n. 21
0
 public void RunBeforeAnyTests()
 {
     GridShift.InitializeExternalGrids(Common.AbsolutePath("GeogTransformGrids"), false);
 }