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); } }
/// <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)); } }
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 } }