Esempio n. 1
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"));
                }
        }
Esempio n. 2
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);
        }