示例#1
0
        public void ReadLine_WhenAtEndOfShapeFile_ReturnNull(string shapeFileName)
        {
            // Setup
            string linesShapefileFilePath = TestHelper.GetTestDataPath(TestDataPath.Core.Components.Gis.IO,
                                                                       shapeFileName);

            using (var reader = new PolylineShapeFileReader(linesShapefileFilePath))
            {
                for (var i = 0; i < reader.GetNumberOfFeatures(); i++)
                {
                    reader.ReadFeature();
                }

                // Call
                var line = reader.ReadFeature() as MapLineData;

                // Assert
                Assert.IsNull(line);
            }
        }
示例#2
0
        /// <summary>
        /// Gets the reference line map data.
        /// </summary>
        /// <param name="lineShapeReader">The line shape reader.</param>
        /// <param name="shapeFilePath">The shapefile path.</param>
        /// <returns>The map data representing the reference line.</returns>
        /// <exception cref="CriticalFileReadException">
        /// When either:
        /// <list type="bullet">
        /// <item>There isn't exactly 1 polyline in the shapefile.</item>
        /// <item>The shapefile doesn't contains lines.</item>
        /// </list>
        /// </exception>
        private static MapLineData GetReferenceLineMapData(PolylineShapeFileReader lineShapeReader, string shapeFilePath)
        {
            if (lineShapeReader.GetNumberOfFeatures() != 1)
            {
                string message = new FileReaderErrorMessageBuilder(shapeFilePath)
                                 .Build(RiskeerCommonIOResources.ReferenceLineReader_File_must_contain_1_polyline);
                throw new CriticalFileReadException(message);
            }

            return((MapLineData)lineShapeReader.ReadFeature(RiskeerCommonDataResources.ReferenceLine_DisplayName));
        }
示例#3
0
        public void ReadLine_WithoutName_MapDataHasDefaultName(string name)
        {
            // Setup
            string shapeWithOneLine = TestHelper.GetTestDataPath(TestDataPath.Core.Components.Gis.IO,
                                                                 "traject_10-1.shp");

            using (var reader = new PolylineShapeFileReader(shapeWithOneLine))
            {
                // Call
                var line = (MapLineData)reader.ReadFeature(name);

                // Assert
                Assert.AreEqual("Lijn", line.Name);
            }
        }
示例#4
0
        public void ReadLine_ShapeFileWithOneLineFeature_ReturnShape()
        {
            // Setup
            string shapeWithOneLine = TestHelper.GetTestDataPath(TestDataPath.Core.Components.Gis.IO,
                                                                 "traject_10-1.shp");

            using (var reader = new PolylineShapeFileReader(shapeWithOneLine))
            {
                // Call
                var line = (MapLineData)reader.ReadFeature();

                // Assert
                Assert.IsNotNull(line);

                MapFeature[] features = line.Features.ToArray();
                Assert.AreEqual(1, features.Length);

                MapGeometry[] geometries = features[0].MapGeometries.ToArray();
                Assert.AreEqual(1, geometries.Length);

                IEnumerable <Point2D>[] pointCollections = geometries[0].PointCollections.ToArray();
                Assert.AreEqual(1, pointCollections.Length);

                Point2D[] firstPointCollection = pointCollections[0].ToArray();
                Assert.AreEqual(1669, firstPointCollection.Length);
                Assert.AreEqual(202714.219, firstPointCollection[457].X, 1e-6);
                Assert.AreEqual(507775.781, firstPointCollection[457].Y, 1e-6);

                Assert.AreEqual(6, features[0].MetaData.Count);
                Assert.AreEqual("A", features[0].MetaData["CATEGORIE"]);
                Assert.AreEqual("10", features[0].MetaData["DIJKRING"]);
                Assert.AreEqual(19190.35000000, features[0].MetaData["LENGTE_TRJ"]);
                Assert.AreEqual("1:1000", features[0].MetaData["Ondergrens"]);
                Assert.AreEqual("1:3000", features[0].MetaData["Signalerin"]);
                Assert.AreEqual("10-1", features[0].MetaData["TRAJECT_ID"]);
            }
        }
示例#5
0
        public void ReadLine_ShapeFileWithMultipleLineFeatures_ReturnShapes()
        {
            // Setup
            string shapeWithMultipleLines = TestHelper.GetTestDataPath(TestDataPath.Core.Components.Gis.IO,
                                                                       "Multiple_PolyLine_with_ID.shp");

            using (var reader = new PolylineShapeFileReader(shapeWithMultipleLines))
            {
                // Precondition
                Assert.AreEqual(4, reader.GetNumberOfFeatures());

                // Call
                var line1 = (MapLineData)reader.ReadFeature();
                var line2 = (MapLineData)reader.ReadFeature();
                var line3 = (MapLineData)reader.ReadFeature();
                var line4 = (MapLineData)reader.ReadFeature();

                // Assert

                #region Assertions for 'line1'

                MapFeature[] features1 = line1.Features.ToArray();
                Assert.AreEqual(1, features1.Length);

                MapGeometry[] geometries1 = features1[0].MapGeometries.ToArray();
                Assert.AreEqual(1, geometries1.Length);

                IEnumerable <Point2D>[] line1PointCollections = geometries1[0].PointCollections.ToArray();
                Assert.AreEqual(1, line1PointCollections.Length);

                Point2D[] line1FirstPointCollection = line1PointCollections[0].ToArray();
                Assert.AreEqual(15, line1FirstPointCollection.Length);
                Assert.AreEqual(-1.514151, line1FirstPointCollection[2].X, 1e-6);
                Assert.AreEqual(-0.879717, line1FirstPointCollection[2].Y, 1e-6);

                Assert.AreEqual(1, features1[0].MetaData.Count);
                Assert.AreEqual(4, features1[0].MetaData["id"]);

                #endregion

                #region Assertions for 'line2'

                MapFeature[] features2 = line2.Features.ToArray();
                Assert.AreEqual(1, features2.Length);

                MapGeometry[] geometries2 = features2[0].MapGeometries.ToArray();
                Assert.AreEqual(1, geometries2.Length);

                IEnumerable <Point2D>[] line2PointCollections = geometries2[0].PointCollections.ToArray();
                Assert.AreEqual(1, line2PointCollections.Length);

                Point2D[] line2FirstPointCollection = line2PointCollections[0].ToArray();
                Assert.AreEqual(6, line2FirstPointCollection.Length);
                Assert.AreEqual(-2.028302, line2FirstPointCollection[3].X, 1e-6);
                Assert.AreEqual(-0.382075, line2FirstPointCollection[3].Y, 1e-6);

                Assert.AreEqual(1, features2[0].MetaData.Count);
                Assert.AreEqual(3, features2[0].MetaData["id"]);

                #endregion

                #region Assertions for 'line3'

                MapFeature[] features3 = line3.Features.ToArray();
                Assert.AreEqual(1, features3.Length);

                MapGeometry[] geometries3 = features3[0].MapGeometries.ToArray();
                Assert.AreEqual(1, geometries3.Length);

                IEnumerable <Point2D>[] line3PointCollections = geometries3[0].PointCollections.ToArray();
                Assert.AreEqual(1, line3PointCollections.Length);

                Point2D[] line3FirstPointCollection = line3PointCollections[0].ToArray();
                Assert.AreEqual(13, line3FirstPointCollection.Length);
                Assert.AreEqual(0.891509, line3FirstPointCollection[12].X, 1e-6);
                Assert.AreEqual(-0.122641, line3FirstPointCollection[12].Y, 1e-6);

                Assert.AreEqual(1, features3[0].MetaData.Count);
                Assert.AreEqual(2, features3[0].MetaData["id"]);

                #endregion

                #region Assertions for 'line4'

                MapFeature[] features4 = line4.Features.ToArray();
                Assert.AreEqual(1, features4.Length);

                MapGeometry[] geometries4 = features4[0].MapGeometries.ToArray();
                Assert.AreEqual(1, geometries4.Length);

                IEnumerable <Point2D>[] line4PointCollections = geometries4[0].PointCollections.ToArray();
                Assert.AreEqual(1, line4PointCollections.Length);

                Point2D[] line4FirstPointCollection = line4PointCollections[0].ToArray();
                Assert.AreEqual(6, line4FirstPointCollection.Length);
                Assert.AreEqual(-2.070754, line4FirstPointCollection[0].X, 1e-6);
                Assert.AreEqual(0.73584906, line4FirstPointCollection[0].Y, 1e-6);

                Assert.AreEqual(1, features4[0].MetaData.Count);
                Assert.AreEqual(1, features4[0].MetaData["id"]);

                #endregion
            }
        }
 /// <summary>
 /// Reads a new <see cref="MapLineData"/> from the file.
 /// </summary>
 /// <returns></returns>
 private MapLineData ReadMapLineData()
 {
     return(polylineShapeFileReader.ReadFeature() as MapLineData);
 }
示例#7
0
 private static MapLineData ReadMapLineData(PolylineShapeFileReader polylineShapeFileReader)
 {
     return((MapLineData)polylineShapeFileReader.ReadFeature());
 }