I'm using MapBox (Turf), trying to filter a specific Feature from a FeatureCollection. I successfully export the GeoJSON from QGIS and decode the GeoJSON into a FeatureCollection. I can't figure out the syntax to access the geometry (multiPolygon).
The FeatureCollection object looks like this:
[Turf.Feature(identifier: nil, properties: Optional(["place": Optional(Turf.JSONValue.string("Anytown, PA")), "name": Optional(Turf.JSONValue.string("Neighborhood")), "type": Optional(Turf.JSONValue.string("origin-zone")), "srno": Optional(Turf.JSONValue.number(31.0))]), geometry: Optional(Turf.Geometry.multiPolygon(Turf.MultiPolygon(coordinates: [[[__C.CLLocationCoordinate2D(latitude: 40.4435110405471, longitude: -79.93806054350729),...
This is as close as I've been able to get:
let features = serviceAreaPolygon.features.filter{$0.geometry.multiPolygon(MultiPolygon)}
which throws an error "Cannot convert value of type 'MultiPolygon.Type' to expected argument type 'MultiPolygon'"
Here is the structure:
public struct FeatureCollection: Equatable, ForeignMemberContainer {
/// The features that the collection contains.
public var features: [Feature] = []
public struct Feature: Equatable, ForeignMemberContainer {
public var identifier: FeatureIdentifier?
public var properties: JSONObject?
public var geometry: Geometry?
public init(geometry: Geometry) {
self.geometry = geometry
}
public enum Geometry: Equatable {
case multiPolygon(_ geometry: MultiPolygon)
}
extension Geometry: Codable {
private enum CodingKeys: String, CodingKey {
case kind = "type"
}
enum Kind: String, Codable, CaseIterable {
...
case MultiPolygon
}
extension MultiPolygon: GeometryConvertible {
public var geometry: Geometry { return .multiPolygon(self) }
}
This is probably very simple, but I've been fighting this for about 4 hours...
Thanks in advance.