我正在使用 iOS Mapbox SDK从来自 3rd 方 APIMGLShapeCollectionFeature
的 goejson数据创建一个。FeatureCollection
guard let feature = try? MGLShape(data: jsonData, encoding: String.Encoding.utf8.rawValue) as? MGLShapeCollectionFeature else {
print("Could not cast to specified MGLShapeCollectionFeature")
return
}
问题是 API 有时会返回一个无效的 geojson,其中单个Feature
不包含有效坐标(见下文),并使用正确MGLShape
的 a 初始化失败。'NSInvalidArgumentException', reason: 'A multipoint must have at least one vertex.'
有没有办法在手动解析和修复geojson的过程中过滤掉并删除那些无效Features
的?FeatureCollection
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"icaoId": "KBOS",
"airSigmetType": "AIRMET",
"hazard": "IFR"
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
]
]
}
},
{
"type": "Feature",
"properties": {
"icaoId": "KSLC",
"airSigmetType": "AIRMET",
"hazard": "IFR"
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-106.63,
49.06
],
[
-104.12,
48.95
],
[
-104.17,
44.8
],
[
-106.91,
46.38
],
[
-106.63,
49.06
]
]
]
}
}
]
}