From 0506a9e9f375b71ff32420ab4bbfd2b7ed9cc9d8 Mon Sep 17 00:00:00 2001 From: Engin Kurutepe Date: Mon, 28 May 2018 23:08:26 +0200 Subject: [PATCH] simplify how floor and ceiling altitudes are represented --- Iguazu.podspec | 2 +- Iguazu/AirSpace.swift | 20 ++++++++++++-------- Iguazu/Info.plist | 2 +- IguazuTests/AirSpaceTests.swift | 2 +- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Iguazu.podspec b/Iguazu.podspec index 827b9c3..e7ce1d2 100644 --- a/Iguazu.podspec +++ b/Iguazu.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = "Iguazu" - s.version = "1.2.1" + s.version = "1.2.2" s.summary = "An aviation file format parser written in Swift" s.description = <<-DESC Iguazu is a new project and still work in progress. The goal is to have a Swift framework with support for various popular aviation file formats to facilitate development of apps for pilots on the iOS platform. diff --git a/Iguazu/AirSpace.swift b/Iguazu/AirSpace.swift index 4c6c192..54a528a 100644 --- a/Iguazu/AirSpace.swift +++ b/Iguazu/AirSpace.swift @@ -315,16 +315,20 @@ public extension AirSpace { } extension AirSpaceAltitude { - var asNSDictionary: NSDictionary { + var geoJsonAltitude: Int { switch self { case .surface: - return [ "type": "surface" ] as NSDictionary - case .fl(let lvl): - return [ "type": "fl", "value": lvl ] as NSDictionary + return 0 + case .fl(let level): + let flMeasure = Measurement(value: 100.0*Double(level), unit: UnitLength.feet).converted(to: .meters) + let intMeters = Int(flMeasure.value.rounded()) + return intMeters case .agl(let alt): - return [ "type": "agl", "value": alt.value, "unit": alt.unit.symbol ] as NSDictionary + let intAGL = Int(alt.converted(to: .meters).value) + return intAGL case .msl(let alt): - return [ "type": "msl", "value": alt.value, "unit": alt.unit.symbol ] as NSDictionary + let intMSL = Int(alt.converted(to: .meters).value) + return intMSL } } } @@ -338,8 +342,8 @@ extension AirSpace: GeoJsonEncodable { "properties": [ "name": self.name as NSString, "type": self.class.rawValue as NSString, - "floor": self.floor.asNSDictionary, - "ceiling": self.ceiling.asNSDictionary, + "floor": self.floor.geoJsonAltitude, + "ceiling": self.ceiling.geoJsonAltitude, ] as NSDictionary, "geometry": [ "type": "Polygon" as NSString, diff --git a/Iguazu/Info.plist b/Iguazu/Info.plist index ae2dbbb..0eb186c 100644 --- a/Iguazu/Info.plist +++ b/Iguazu/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.2.1 + 1.2.2 CFBundleSignature ???? CFBundleVersion diff --git a/IguazuTests/AirSpaceTests.swift b/IguazuTests/AirSpaceTests.swift index 47ad196..21eca5d 100644 --- a/IguazuTests/AirSpaceTests.swift +++ b/IguazuTests/AirSpaceTests.swift @@ -27,7 +27,7 @@ class AirSpaceTests : XCTestCase { XCTAssertNotNil(airSpaces) let asp = airSpaces![0] let geoJson = asp.geoJsonString - XCTAssertEqual(geoJson, "{\"type\":\"Feature\",\"properties\":{\"ceiling\":{\"type\":\"fl\",\"value\":65},\"name\":\"TMZ-EDLW 129.875\",\"type\":\"TMZ\",\"floor\":{\"type\":\"msl\",\"value\":4500,\"unit\":\"ft\"}},\"geometry\":{\"type\":\"Polygon\",\"coordinates\":[[[7.3055555555555554,51.516666666666666],[7.3055555555555554,51.516666666666666],[7.3433333333333328,51.423888888888889],[7.4625000000000004,51.31305555555555],[7.4519444444444449,51.408333333333331],[7.3741666666666665,51.493055555555557],[7.3055555555555554,51.516666666666666]]]}}") + XCTAssertEqual(geoJson, "{\"type\":\"Feature\",\"properties\":{\"ceiling\":1981,\"name\":\"TMZ-EDLW 129.875\",\"type\":\"TMZ\",\"floor\":1371},\"geometry\":{\"type\":\"Polygon\",\"coordinates\":[[[7.3055555555555554,51.516666666666666],[7.3055555555555554,51.516666666666666],[7.3433333333333328,51.423888888888889],[7.4625000000000004,51.31305555555555],[7.4519444444444449,51.408333333333331],[7.3741666666666665,51.493055555555557],[7.3055555555555554,51.516666666666666]]]}}") } }