Пример #1
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 MapLineData("test")
            {
                Features = new[]
                {
                    feature
                }
            };

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

                // Assert
                TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentException>(call, "Een feature mag maar één geometrie bevatten.");
            }
        }
Пример #2
0
        public void CopyToFeature_InconsistentMetaDataBetweenMapLineDatas_ThrowArgumentException()
        {
            // Setup
            MapFeature[] features1    = CreateFeatures(0.0);
            var          mapLineData1 = new MapLineData("test data 1")
            {
                Features = features1
            };

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

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

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

            using (var writer = new PolylineShapeFileWriter())
            {
                writer.CopyToFeature(mapLineData1);

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

                // Assert
                const string message = "Column 'anotherKey' does not belong to table .";
                TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentException>(call, message);
            }
        }
Пример #3
0
        public void SaveAs_ValidMapLineData_WritesShapeFile()
        {
            // Setup
            string       directoryPath = TestHelper.GetScratchPadPath(nameof(SaveAs_ValidMapLineData_WritesShapeFile));
            string       filePath      = Path.Combine(directoryPath, "test.shp");
            const string baseName      = "test";

            MapFeature[] features = CreateFeatures(0.0);

            var mapLineData = new MapLineData("test data")
            {
                Features = features
            };

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

            using (new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), nameof(SaveAs_ValidMapLineData_WritesShapeFile)))
                using (var writer = new PolylineShapeFileWriter())
                {
                    writer.CopyToFeature(mapLineData);

                    // 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
 public void DefaultConstructor_ExpectedValues()
 {
     // Call
     using (var writer = new PolylineShapeFileWriter())
     {
         // Assert
         Assert.IsInstanceOf <ShapeFileWriterBase>(writer);
     }
 }
Пример #5
0
        /// <summary>
        /// Writes a <see cref="ReferenceLine"/> as a line feature in a shapefile.
        /// </summary>
        /// <param name="referenceLine">The reference line which is to be written to file.</param>
        /// <param name="id">The id of the assessment section to which this reference line is associated.</param>
        /// <param name="filePath">The path to the shapefile.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="referenceLine"/>, <paramref name="id"/>
        /// or <paramref name="filePath"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">Thrown when <list type="bullet">
        /// <item><paramref name="filePath"/> is invalid, or</item>
        /// <item><paramref name="id"/> is empty or consists of whitespace.</item>
        /// </list></exception>
        /// <exception cref="CriticalFileWriteException">Thrown when the shapefile cannot be written.</exception>
        public void WriteReferenceLine(ReferenceLine referenceLine, string id, string filePath)
        {
            if (filePath == null)
            {
                throw new ArgumentNullException(nameof(filePath));
            }

            var polyLineShapeFileWriter = new PolylineShapeFileWriter();

            MapLineData mapLineData = CreateMapLineData(referenceLine, id);

            polyLineShapeFileWriter.CopyToFeature(mapLineData);

            polyLineShapeFileWriter.SaveAs(filePath);
        }