diff --git a/apps/ios/GuideDogs/Code/Data/Models/Cache Models/GDASpatialDataResultEntity.swift b/apps/ios/GuideDogs/Code/Data/Models/Cache Models/GDASpatialDataResultEntity.swift index b21d7fd3..84f91dca 100644 --- a/apps/ios/GuideDogs/Code/Data/Models/Cache Models/GDASpatialDataResultEntity.swift +++ b/apps/ios/GuideDogs/Code/Data/Models/Cache Models/GDASpatialDataResultEntity.swift @@ -178,19 +178,18 @@ class GDASpatialDataResultEntity: Object { } // Set geolocation information - if let geometry = feature.geometry { - if case .point(let point) = geometry { - latitude = point.latitude - longitude = point.longitude - } else if let json_data = try? JSONEncoder().encode(geometry) { - coordinatesJson = String(data: json_data, encoding: .utf8) - } - - let centroid = geometry.centroid - centroidLatitude = centroid.latitude - centroidLongitude = centroid.longitude + if case .point(let point) = feature.geometry { + latitude = point.latitude + longitude = point.longitude + } else if let json_data = try? JSONEncoder().encode(feature.geometry) { + coordinatesJson = String(data: json_data, encoding: .utf8) + _geometry = feature.geometry; } + let centroid = feature.geometry.centroid + centroidLatitude = centroid.latitude + centroidLongitude = centroid.longitude + // Road specific metadata roundabout = feature.isRoundabout diff --git a/apps/ios/GuideDogs/Code/Data/Models/JSON Parsing/OSM/GeoJsonFeature.swift b/apps/ios/GuideDogs/Code/Data/Models/JSON Parsing/OSM/GeoJsonFeature.swift index eeb65e1c..340c414a 100644 --- a/apps/ios/GuideDogs/Code/Data/Models/JSON Parsing/OSM/GeoJsonFeature.swift +++ b/apps/ios/GuideDogs/Code/Data/Models/JSON Parsing/OSM/GeoJsonFeature.swift @@ -80,8 +80,9 @@ final class GeoJsonFeature: Decodable { var superCategory: SuperCategory = .undefined /// Geometry of this feature - /// While Features are required to have a `geometry` member, it may be `null` for unlocated features, represented here as `nil` - var geometry: GeoJsonGeometry? + /// + /// GeoJSON spec allows null geometries, but we don't (we throw a parse failure if missing) + var geometry: GeoJsonGeometry var isCrossing = false @@ -143,12 +144,12 @@ final class GeoJsonFeature: Decodable { isRoundabout = true } - // TODO: it is unclear if geometry not existing should cause the feature to be rejected - geometry = try? container.decode(GeoJsonGeometry.self, forKey: .geometry) + // GeoJSON spec permits null geometries, but we don't + geometry = try container.decode(GeoJsonGeometry.self, forKey: .geometry) // Fix geometries for crossings with LineString geometries if isCrossing, case .lineString = geometry, - let median = geometry?.getLineMedian() { + let median = geometry.getLineMedian() { geometry = GeoJsonGeometry(point: median) } @@ -272,14 +273,10 @@ final class GeoJsonFeature: Decodable { let startCopy = GeoJsonFeature(copyFrom: self) let endCopy = GeoJsonFeature(copyFrom: self) - guard let first = geometry?.first, let last = geometry?.last else { - return nil - } - - startCopy.geometry = .point(coordinates: first) + startCopy.geometry = .point(coordinates: geometry.first) startCopy.superCategory = SuperCategory.mobility - endCopy.geometry = .point(coordinates: last) + endCopy.geometry = .point(coordinates: geometry.last) endCopy.superCategory = SuperCategory.mobility return (startCopy, endCopy) diff --git a/apps/ios/UnitTests/Data/Models/JSON Parsing/OSM/GeoJsonFeatureTest.swift b/apps/ios/UnitTests/Data/Models/JSON Parsing/OSM/GeoJsonFeatureTest.swift index f517eacc..c6cfa397 100644 --- a/apps/ios/UnitTests/Data/Models/JSON Parsing/OSM/GeoJsonFeatureTest.swift +++ b/apps/ios/UnitTests/Data/Models/JSON Parsing/OSM/GeoJsonFeatureTest.swift @@ -51,7 +51,7 @@ final class GeoJsonFeatureTest: XCTestCase { XCTAssertEqual(rpi_feature.type, "amenity") XCTAssertEqual(rpi_feature.value, "university") XCTAssertEqual(rpi_feature.osmIds, ["ft-100000000008670722"]) - XCTAssertEqual(rpi_feature.geometry?.rawValue, "MultiPolygon") + XCTAssertEqual(rpi_feature.geometry.rawValue, "MultiPolygon") //XCTAssertEqual(rpi_feature.superCategory, .undefined) XCTAssertEqual(rpi_feature.properties, [ @@ -105,7 +105,7 @@ final class GeoJsonFeatureTest: XCTestCase { XCTAssertEqual(sage_feature.type, "highway") XCTAssertEqual(sage_feature.value, "tertiary") XCTAssertEqual(sage_feature.osmIds, ["ft-669453514"]) - XCTAssertEqual(sage_feature.geometry?.rawValue, "LineString") + XCTAssertEqual(sage_feature.geometry.rawValue, "LineString") XCTAssertEqual(sage_feature.properties, [ "highway": "tertiary",