Esempio n. 1
0
        public void ReadLine_ShapeFileWithOnePointFeature_ReturnShape()
        {
            // Setup
            string shapeWithOnePoint = TestHelper.GetTestDataPath(TestDataPath.Core.Components.Gis.IO,
                                                                  "Single_Point_with_ID.shp");

            using (var reader = new PointShapeFileReader(shapeWithOnePoint))
            {
                // Call
                var pointData = reader.ReadFeature() as MapPointData;

                // Assert
                Assert.IsNotNull(pointData);
                Assert.AreEqual(1, pointData.Features.Count());

                MapGeometry[] mapGeometries = pointData.Features.First().MapGeometries.ToArray();
                Assert.AreEqual(1, mapGeometries.Length);

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

                Point2D[] firstPointCollection = pointCollections[0].ToArray();
                Assert.AreEqual(1, firstPointCollection.Length);
                Assert.AreEqual(1.705, firstPointCollection[0].X, 1e-1);
                Assert.AreEqual(0.922, firstPointCollection[0].Y, 1e-1);
            }
        }
Esempio n. 2
0
        public void ReadLine_WhenAtEndOfShapeFile_ReturnNull(string fileName)
        {
            // Setup
            string filePath = TestHelper.GetTestDataPath(TestDataPath.Core.Components.Gis.IO,
                                                         fileName);

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

                // Call
                var feature = reader.ReadFeature() as MapPointData;

                // Assert
                Assert.IsNull(feature);
            }
        }
Esempio n. 3
0
        public void ReadLine_WithoutName_MapDataHasDefaultName(string name)
        {
            // Setup
            string shapeWithOnePoint = TestHelper.GetTestDataPath(TestDataPath.Core.Components.Gis.IO,
                                                                  "Single_Point_with_ID.shp");

            using (var reader = new PointShapeFileReader(shapeWithOnePoint))
            {
                // Call
                var pointData = (MapPointData)reader.ReadFeature(name);

                // Assert
                Assert.AreEqual("Punten", pointData.Name);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Retrieve a <see cref="StructureLocation"/> based on the next point feature in the shapefile.
        /// </summary>
        /// <exception cref="LineParseException">Thrown when either:
        /// <list type="bullet">
        /// <item>The shapefile misses a value for a required attribute.</item>
        /// <item>The shapefile has an attribute whose type is incorrect.</item>
        /// </list></exception>
        /// <returns>A <see cref="StructureLocation"/> based on the next point feature in the shapefile.</returns>
        public StructureLocation GetNextStructureLocation()
        {
            var mapPointData = (MapPointData)pointsShapeFileReader.ReadFeature();

            IDictionary <string, object> attributes = mapPointData.Features.First().MetaData;

            string attributeIdValue   = GetIdAttributeValue(attributes);
            string attributeNameValue = GetNameAttributeValue(attributes, attributeIdValue);

            Point2D point = mapPointData.Features.First().MapGeometries.First().PointCollections.First().First();

            if (attributeIdValue == null)
            {
                throw new LineParseException(string.Format(Resources.StructuresReader_GetNextStructure_Invalid_KWKIDENT, idAttributeName));
            }

            return(new StructureLocation(attributeIdValue, attributeNameValue, point));
        }
Esempio n. 5
0
        /// <summary>
        /// Retrieve a <see cref="ProfileLocation"/> based on the next point feature in the shapefile.
        /// </summary>
        /// <exception cref="LineParseException">Thrown when either:
        /// <list type="bullet">
        /// <item>The shapefile misses a value for a required attribute.</item>
        /// <item>The shapefile has an attribute whose type is incorrect.</item>
        /// </list></exception>
        /// <returns>A <see cref="ProfileLocation"/> based on the next point feature in the shapefile.</returns>
        public ProfileLocation GetNextProfileLocation()
        {
            var mapPointData = (MapPointData)pointsShapeFileReader.ReadFeature();

            IDictionary <string, object> attributes = mapPointData.Features.First().MetaData;

            string attributeIdValue   = GetIdAttributeValue(attributes);
            string attributeNameValue = GetNameAttributeValue(attributes);
            double attributeX0Value   = GetOffsetAttributeValue(attributes);

            Point2D point = mapPointData.Features.First().MapGeometries.First().PointCollections.First().First();

            try
            {
                return(new ProfileLocation(attributeIdValue, attributeNameValue, attributeX0Value, point));
            }
            catch (ArgumentException exception)
            {
                throw new LineParseException(exception.Message);
            }
        }
Esempio n. 6
0
        public void ReadLine_ShapeFileWithMultiplePointFeatures_ReturnShapes()
        {
            // Setup
            string shapeWithMultiplePoints = TestHelper.GetTestDataPath(TestDataPath.Core.Components.Gis.IO,
                                                                        "Multiple_Point_with_ID.shp");

            using (var reader = new PointShapeFileReader(shapeWithMultiplePoints))
            {
                // Precondition
                Assert.AreEqual(6, reader.GetNumberOfFeatures());

                // Call
                var points1 = (MapPointData)reader.ReadFeature();
                var points2 = (MapPointData)reader.ReadFeature();
                var points3 = (MapPointData)reader.ReadFeature();
                var points4 = (MapPointData)reader.ReadFeature();
                var points5 = (MapPointData)reader.ReadFeature();
                var points6 = (MapPointData)reader.ReadFeature();

                // Assert

                #region Assertion for 'point1'

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

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

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

                Point2D[] point1FirstPointCpllection = point1PointCollections[0].ToArray();
                Assert.AreEqual(1, point1FirstPointCpllection.Length);
                Assert.AreEqual(-1.750, point1FirstPointCpllection[0].X, 1e-1);
                Assert.AreEqual(-0.488, point1FirstPointCpllection[0].Y, 1e-1);

                #endregion

                #region Assertion for 'point2'

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

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

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

                Point2D[] point2FirstPointCollection = point2PointCollections[0].ToArray();
                Assert.AreEqual(1, point2FirstPointCollection.Length);
                Assert.AreEqual(-0.790, point2FirstPointCollection[0].X, 1e-1);
                Assert.AreEqual(-0.308, point2FirstPointCollection[0].Y, 1e-1);

                #endregion

                #region Assertion for 'point3'

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

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

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

                Point2D[] point3FirstPointCollection = point3PointCollections[0].ToArray();
                Assert.AreEqual(1, point3FirstPointCollection.Length);
                Assert.AreEqual(0.740, point3FirstPointCollection[0].X, 1e-1);
                Assert.AreEqual(-0.577, point3FirstPointCollection[0].Y, 1e-1);

                #endregion

                #region Assertion for 'point4'

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

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

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

                Point2D[] point4FirstPointCollection = point4PointCollections[0].ToArray();
                Assert.AreEqual(1, point4FirstPointCollection.Length);
                Assert.AreEqual(0.787, point4FirstPointCollection[0].X, 1e-1);
                Assert.AreEqual(0.759, point4FirstPointCollection[0].Y, 1e-1);

                #endregion

                #region Assertion for 'point5'

                MapFeature[] features5 = points5.Features.ToArray();
                Assert.AreEqual(1, features5.Length);

                MapFeature    point5         = features5[0];
                MapGeometry[] point5Geometry = point5.MapGeometries.ToArray();
                Assert.AreEqual(1, point5Geometry.Length);

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

                Point2D[] point5FirstPointCollection = point5PointCollections[0].ToArray();
                Assert.AreEqual(1, point5FirstPointCollection.Length);
                Assert.AreEqual(-0.544, point5FirstPointCollection[0].X, 1e-1);
                Assert.AreEqual(0.283, point5FirstPointCollection[0].Y, 1e-1);

                #endregion

                #region Assertion for 'point6'

                MapFeature[] features6 = points6.Features.ToArray();
                Assert.AreEqual(1, features6.Length);

                MapFeature    point6         = features6[0];
                MapGeometry[] point6Geometry = point6.MapGeometries.ToArray();
                Assert.AreEqual(1, point6Geometry.Length);

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

                Point2D[] point6FirstPointCollection = point6PointCollections[0].ToArray();
                Assert.AreEqual(1, point6FirstPointCollection.Length);
                Assert.AreEqual(-2.066, point6FirstPointCollection[0].X, 1e-1);
                Assert.AreEqual(0.827, point6FirstPointCollection[0].Y, 1e-1);

                #endregion
            }
        }