示例#1
0
        public void CopyToFeature_InconsistentMetaDataBetweenMapPointDatas_ThrowArgumentException()
        {
            // Setup
            MapFeature[] features1     = CreateFeatures(0.0);
            var          mapPointData1 = new MapPointData("test data 1")
            {
                Features = features1
            };

            mapPointData1.Features.First().MetaData["firstKey"]  = 123;
            mapPointData1.Features.First().MetaData["secondKey"] = "aValue";

            MapFeature[] features2     = CreateFeatures(10.0);
            var          mapPointData2 = new MapPointData("test data 2")
            {
                Features = features2
            };

            mapPointData2.Features.First().MetaData["firstKey"]   = 123;
            mapPointData2.Features.First().MetaData["anotherKey"] = "anotherValue";

            using (var writer = new PointShapeFileWriter())
            {
                writer.CopyToFeature(mapPointData1);

                // Call
                TestDelegate call = () => writer.CopyToFeature(mapPointData2);

                // Assert
                const string message = "Column 'anotherKey' does not belong to table .";
                TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentException>(call, message);
            }
        }
示例#2
0
        public void CopyToFeature_FeatureContainsMultipleGeometries_ThrowsArgumentException()
        {
            // Setup
            var feature = new MapFeature(new[]
            {
                new MapGeometry(new[]
                {
                    Enumerable.Empty <Point2D>()
                }),
                new MapGeometry(new[]
                {
                    Enumerable.Empty <Point2D>()
                })
            });

            var mapData = new MapPointData("test")
            {
                Features = new[]
                {
                    feature
                }
            };

            using (var writer = new PointShapeFileWriter())
            {
                // Call
                TestDelegate call = () => writer.CopyToFeature(mapData);

                // Assert
                TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentException>(call, "Een feature mag maar één geometrie bevatten.");
            }
        }
示例#3
0
        public void SaveAs_ValidMapPointData_WritesShapeFile()
        {
            // Setup
            string       directoryPath = TestHelper.GetScratchPadPath(nameof(SaveAs_ValidMapPointData_WritesShapeFile));
            string       filePath      = Path.Combine(directoryPath, "test.shp");
            const string baseName      = "test";

            MapFeature[] features = CreateFeatures(0.0);

            var mapPointData = new MapPointData("test data")
            {
                Features = features
            };

            mapPointData.Features.First().MetaData["<some key>"] = 123;

            using (new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), nameof(SaveAs_ValidMapPointData_WritesShapeFile)))
                using (var writer = new PointShapeFileWriter())
                {
                    writer.CopyToFeature(mapPointData);

                    // Call
                    writer.SaveAs(filePath);

                    // Assert
                    string pathName = Path.Combine(directoryPath, baseName);
                    Assert.IsTrue(File.Exists(pathName + ".shp"));
                    Assert.IsTrue(File.Exists(pathName + ".shx"));
                    Assert.IsTrue(File.Exists(pathName + ".dbf"));
                }
        }
示例#4
0
        /// <summary>
        /// Writes the collection of <see cref="HydraulicBoundaryLocationCalculation"/> as point features in a shapefile.
        /// </summary>
        /// <param name="calculations">The hydraulic boundary locations calculations to be written to file.</param>
        /// <param name="filePath">The path to the shapefile.</param>
        /// <param name="calculationsType">The type of calculations.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="calculations"/> or
        /// <paramref name="filePath"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">Thrown when <paramref name="filePath"/> is invalid.</exception>
        /// <exception cref="InvalidEnumArgumentException">Thrown when the <see cref="calculationsType"/>
        /// is an invalid value.</exception>
        /// <exception cref="CriticalFileWriteException">Thrown when the shapefile cannot be written.</exception>
        public static void WriteHydraulicBoundaryLocationCalculations(IEnumerable <HydraulicBoundaryLocationCalculation> calculations,
                                                                      string filePath, HydraulicBoundaryLocationCalculationsType calculationsType)
        {
            if (calculations == null)
            {
                throw new ArgumentNullException(nameof(calculations));
            }

            if (filePath == null)
            {
                throw new ArgumentNullException(nameof(filePath));
            }

            if (!Enum.IsDefined(typeof(HydraulicBoundaryLocationCalculationsType), calculationsType))
            {
                throw new InvalidEnumArgumentException(nameof(calculationsType),
                                                       (int)calculationsType,
                                                       typeof(HydraulicBoundaryLocationCalculationsType));
            }

            var pointShapeFileWriter = new PointShapeFileWriter();

            foreach (MapPointData mapDataLocation in calculations.Select(c => CreateCalculationData(c, calculationsType)))
            {
                pointShapeFileWriter.CopyToFeature(mapDataLocation);
            }

            pointShapeFileWriter.SaveAs(filePath);
        }