示例#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);
            }
        }
示例#2
0
        public void ParameteredConstructor_ExpectedValues(string shapeFileName)
        {
            // Setup
            string testFilePath = TestHelper.GetTestDataPath(TestDataPath.Core.Components.Gis.IO,
                                                             shapeFileName);

            // Call
            using (var reader = new PointShapeFileReader(testFilePath))
            {
                // Assert
                Assert.IsInstanceOf <ShapeFileReaderBase>(reader);
            }
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ProfileLocationReader"/> class.
        /// </summary>
        /// <param name="shapeFilePath">The shape file path.</param>
        /// <exception cref="ArgumentException">Thrown when <paramref name="shapeFilePath"/> is invalid.</exception>
        /// <exception cref="CriticalFileReadException">Thrown when: <list type="bullet">
        /// <item><paramref name="shapeFilePath"/> points to a file that does not exist.</item>
        /// <item><paramref name="shapeFilePath"/> does not only contain point features.</item>
        /// <item><paramref name="shapeFilePath"/> does not contain all of the required attributes.</item>
        /// </list></exception>
        public ProfileLocationReader(string shapeFilePath)
        {
            IOUtils.ValidateFilePath(shapeFilePath);
            if (!File.Exists(shapeFilePath))
            {
                string message = new FileReaderErrorMessageBuilder(shapeFilePath)
                                 .Build(CoreCommonUtilResources.Error_File_does_not_exist);
                throw new CriticalFileReadException(message);
            }

            pointsShapeFileReader = OpenPointsShapeFile(shapeFilePath);

            CheckRequiredAttributePresence();
        }
示例#4
0
        public void HasAttribute_VariousCases_ReturnTrueIfMatchesInProperCaseHasBeenFound(string attributeName, bool expectedResult)
        {
            // Setup
            string shapefileFilePath = TestHelper.GetTestDataPath(TestDataPath.Core.Components.Gis.IO,
                                                                  "Single_Point_with_ID.shp");

            using (var reader = new PointShapeFileReader(shapefileFilePath))
            {
                // Call
                bool result = reader.HasAttribute(attributeName);

                // Assert
                Assert.AreEqual(expectedResult, result);
            }
        }
示例#5
0
        public void HasAttribute_AttributeInShapefile_ReturnTrue()
        {
            // Setup
            string shapefileFilePath = TestHelper.GetTestDataPath(TestDataPath.Core.Components.Gis.IO,
                                                                  "Single_Point_with_ID.shp");

            using (var reader = new PointShapeFileReader(shapefileFilePath))
            {
                // Call
                bool result = reader.HasAttribute("id");

                // Assert
                Assert.IsTrue(result);
            }
        }
示例#6
0
        public void ReadShapeFile_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.ReadShapeFile(name);

                // Assert
                Assert.AreEqual("Punten", pointData.Name);
            }
        }
示例#7
0
        public void ReadLine_WithName_ApplyNameToMapData(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(name, pointData.Name);
            }
        }
示例#8
0
        public void GetNumberOfLines_ShapeFileWithMultiplePointFeatures_ReturnThatNumberOfFeatures()
        {
            // Setup
            string shapeWithMultiplePoints = TestHelper.GetTestDataPath(TestDataPath.Core.Components.Gis.IO,
                                                                        "Multiple_Point_with_ID.shp");

            using (var reader = new PointShapeFileReader(shapeWithMultiplePoints))
            {
                // Call
                int count = reader.GetNumberOfFeatures();

                // Assert
                Assert.AreEqual(6, count);
            }
        }
示例#9
0
        public void GetNumberOfLines_EmptyPointShapeFile_ReturnZero()
        {
            // Setup
            string shapeWithOneLine = TestHelper.GetTestDataPath(TestDataPath.Core.Components.Gis.IO,
                                                                 "Empty_Point_with_ID.shp");

            using (var reader = new PointShapeFileReader(shapeWithOneLine))
            {
                // Call
                int count = reader.GetNumberOfFeatures();

                // Assert
                Assert.AreEqual(0, count);
            }
        }
示例#10
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);
            }
        }
示例#11
0
        /// <summary>
        /// Creates an <see cref="IEnumerable{T}"/> of <see cref="ReadDuneLocation"/> based on the line features within the embedded shape file.
        /// </summary>
        /// <returns>An <see cref="IEnumerable{T}"/> of <see cref="ReadDuneLocation"/>.</returns>
        public IEnumerable <ReadDuneLocation> ReadDuneLocations()
        {
            using (var embeddedResourceFileWriter = new EmbeddedResourceFileWriter(typeof(DuneLocationsReader).Assembly,
                                                                                   true,
                                                                                   "RSPstelsel.shp",
                                                                                   "RSPstelsel.dbf",
                                                                                   "RSPstelsel.cpg",
                                                                                   "RSPstelsel.sbn",
                                                                                   "RSPstelsel.sbx",
                                                                                   "RSPstelsel.shx"))
            {
                string filePath = Path.Combine(embeddedResourceFileWriter.TargetFolderPath, "RSPstelsel.shp");

                var readDuneLocations = new List <ReadDuneLocation>();
                using (var pointShapeReader = new PointShapeFileReader(filePath))
                {
                    FeatureBasedMapData locationsData = pointShapeReader.ReadShapeFile();
                    readDuneLocations.AddRange(CreateDuneLocations(locationsData));
                }

                return(readDuneLocations);
            }
        }
        private ReadResult <FeatureBasedMapData> ReadFeatureBasedMapData()
        {
            try
            {
                string    shapeFileName = Path.GetFileNameWithoutExtension(FilePath);
                Shapefile featureSet    = Shapefile.OpenFile(FilePath);

                FeatureBasedMapData importedData;

                switch (featureSet.FeatureType)
                {
                case FeatureType.Point:
                case FeatureType.MultiPoint:
                    using (ShapeFileReaderBase reader = new PointShapeFileReader(FilePath))
                    {
                        importedData = reader.ReadShapeFile(shapeFileName);
                    }

                    break;

                case FeatureType.Line:
                    using (ShapeFileReaderBase reader = new PolylineShapeFileReader(FilePath))
                    {
                        importedData = reader.ReadShapeFile(shapeFileName);
                    }

                    break;

                case FeatureType.Polygon:
                    using (ShapeFileReaderBase reader = new PolygonShapeFileReader(FilePath))
                    {
                        importedData = reader.ReadShapeFile(shapeFileName);
                    }

                    break;

                default:
                    throw new CriticalFileReadException(Resources.FeatureBasedMapDataImporter_Import_ShapeFile_Contains_Unsupported_Data);
                }

                return(new ReadResult <FeatureBasedMapData>(false)
                {
                    Items = new[]
                    {
                        importedData
                    }
                });
            }
            catch (ArgumentException)
            {
                return(HandleCriticalFileReadError(Resources.FeatureBasedMapDataImporter_Import_File_does_not_contain_geometries));
            }
            catch (FileNotFoundException)
            {
                return(HandleCriticalFileReadError(Resources.FeatureBasedMapDataImporter_Import_File_does_not_exist_or_misses_needed_files));
            }
            catch (IOException)
            {
                return(HandleCriticalFileReadError(Resources.FeatureBasedMapDataImporter_Import_An_error_occurred_when_trying_to_read_the_file));
            }
            catch (CriticalFileReadException e)
            {
                return(HandleCriticalFileReadError(e.Message));
            }
            catch (Exception)
            {
                // Because NullReferenceException or NotImplementedException when reading in a corrupt shape file
                // from a third party library is expected, we catch all the exceptions here.
                return(HandleCriticalFileReadError(Resources.FeatureBasedMapDataImporter_Import_An_error_occurred_when_trying_to_read_the_file));
            }
        }
示例#13
0
        public void ReadShapeFile_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 points = (MapPointData)reader.ReadShapeFile();

                // Assert
                MapFeature[] features = points.Features.ToArray();
                Assert.AreEqual(6, features.Length);
                Assert.AreEqual("id", points.SelectedMetaDataAttribute);

                #region Assertion for 'point1'

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

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

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

                Assert.AreEqual(1, point1.MetaData.Count);
                Assert.AreEqual(6, point1.MetaData["id"]);

                #endregion

                #region Assertion for 'point2'

                MapFeature    point2         = features[1];
                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);

                Assert.AreEqual(1, point2.MetaData.Count);
                Assert.AreEqual(5, point2.MetaData["id"]);

                #endregion

                #region Assertion for 'point3'

                MapFeature    point3         = features[2];
                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);

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

                #endregion

                #region Assertion for 'point4'

                MapFeature    point4         = features[3];
                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);

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

                #endregion

                #region Assertion for 'point5'

                MapFeature    point5         = features[4];
                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);

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

                #endregion

                #region Assertion for 'point6'

                MapFeature    point6         = features[5];
                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);

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

                #endregion
            }
        }
示例#14
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
            }
        }