Merge ece17b5ae2
into 0be243792a
This commit is contained in:
commit
f966978978
|
@ -359,12 +359,13 @@
|
|||
454361721E7BE75800656472 = {
|
||||
CreatedOnToolsVersion = 8.2.1;
|
||||
DevelopmentTeam = W79FWJ7E3Y;
|
||||
LastSwiftMigration = 0820;
|
||||
LastSwiftMigration = 0830;
|
||||
ProvisioningStyle = Automatic;
|
||||
};
|
||||
4543617B1E7BE75800656472 = {
|
||||
CreatedOnToolsVersion = 8.2.1;
|
||||
DevelopmentTeam = 7L5H8T8QE3;
|
||||
LastSwiftMigration = 0830;
|
||||
ProvisioningStyle = Automatic;
|
||||
};
|
||||
454361911E7BE77F00656472 = {
|
||||
|
|
|
@ -29,12 +29,12 @@ import Foundation
|
|||
|
||||
let utmScaleFactor = 0.9996
|
||||
|
||||
func toDegrees(radians: Double) -> Double {
|
||||
return radians * 180 / M_PI
|
||||
func toDegrees(_ radians: Double) -> Double {
|
||||
return radians * 180 / Double.pi
|
||||
}
|
||||
|
||||
func toRadians(degrees: Double) -> Double {
|
||||
return degrees / 180 * M_PI
|
||||
func toRadians(_ degrees: Double) -> Double {
|
||||
return degrees / 180 * Double.pi
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,8 +63,8 @@ struct TMCoordinate {
|
|||
- Parameter datum: The datum to use
|
||||
*/
|
||||
init(coordinate: CLLocationCoordinate2D, centralMeridian: Double, datum: UTMDatum) {
|
||||
let phi = toRadians(degrees: coordinate.latitude) // Latitude in radians
|
||||
let lambda = toRadians(degrees: coordinate.longitude) // Longitude in radians
|
||||
let phi = toRadians(coordinate.latitude) // Latitude in radians
|
||||
let lambda = toRadians(coordinate.longitude) // Longitude in radians
|
||||
|
||||
let equitorialRadus = datum.equitorialRadius
|
||||
let polarRadius = datum.polarRadius
|
||||
|
@ -230,7 +230,7 @@ struct TMCoordinate {
|
|||
/* Calculate longitude */
|
||||
let longitudeRadians = centralMeridian + x1frac * x + x3frac * x3poly * pow(x, 3.0) + x5frac * x5poly * pow(x, 5.0) + x7frac * x7poly * pow(x, 7.0)
|
||||
|
||||
return CLLocationCoordinate2D(latitude: toDegrees(radians: latitudeRadians), longitude: toDegrees(radians: longitudeRadians))
|
||||
return CLLocationCoordinate2D(latitude: toDegrees(latitudeRadians), longitude: toDegrees(longitudeRadians))
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -240,7 +240,7 @@ struct TMCoordinate {
|
|||
- Parameter datum: The datum to use
|
||||
|
||||
*/
|
||||
private func footpointLatitude(northing: Double, datum: UTMDatum) -> Double {
|
||||
fileprivate func footpointLatitude(northing: Double, datum: UTMDatum) -> Double {
|
||||
let equitorialRadus = datum.equitorialRadius
|
||||
let polarRadius = datum.polarRadius
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ extension UTMGridZone {
|
|||
|
||||
/** Calculate the central meridian of the receiver */
|
||||
var centralMeridian: Double {
|
||||
return toRadians(degrees: -183.0 + (Double(self) * 6.0));
|
||||
return toRadians(-183.0 + (Double(self) * 6.0));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,28 +30,40 @@ class UTMConversionTests: XCTestCase {
|
|||
XCTAssertEqualWithAccuracy(johannesburgUTM.easting, 603914, accuracy: 0.00001)
|
||||
XCTAssertEqual(johannesburgUTM.zone, 35)
|
||||
XCTAssertEqual(johannesburgUTM.hemisphere, .southern)
|
||||
|
||||
let buninyongUTM = buninyong.utmCoordinate()
|
||||
XCTAssertEqualWithAccuracy(buninyongUTM.northing, 5828674.33994, accuracy: 0.00001)
|
||||
XCTAssertEqualWithAccuracy(buninyongUTM.easting, 758173.79835, accuracy: 0.00001)
|
||||
XCTAssertEqual(buninyongUTM.zone, 54)
|
||||
XCTAssertEqual(buninyongUTM.hemisphere, .southern)
|
||||
}
|
||||
|
||||
|
||||
func testCLLocation_utmCoordinate() {
|
||||
let osloUTM = osloLocation.utmCoordinate()
|
||||
XCTAssertEqualWithAccuracy(osloUTM.northing, 6643010.0, accuracy: 0.00001);
|
||||
XCTAssertEqualWithAccuracy(osloUTM.easting, 598430.0, accuracy: 0.00001);
|
||||
XCTAssertEqual(osloUTM.zone, 32)
|
||||
XCTAssertEqual(osloUTM.hemisphere, .northern)
|
||||
|
||||
|
||||
let trondheimUTM = trondheimLocation.utmCoordinate()
|
||||
XCTAssertEqualWithAccuracy(trondheimUTM.northing, 7034313, accuracy: 0.00001)
|
||||
XCTAssertEqualWithAccuracy(trondheimUTM.easting, 569612, accuracy: 0.00001)
|
||||
XCTAssertEqual(trondheimUTM.zone, 32)
|
||||
XCTAssertEqual(trondheimUTM.hemisphere, .northern)
|
||||
|
||||
|
||||
let johannesburgUTM = johannesburgLocation.utmCoordinate()
|
||||
XCTAssertEqualWithAccuracy(johannesburgUTM.northing, 7100115, accuracy: 0.00001)
|
||||
XCTAssertEqualWithAccuracy(johannesburgUTM.easting, 603914, accuracy: 0.00001)
|
||||
XCTAssertEqual(johannesburgUTM.zone, 35)
|
||||
XCTAssertEqual(johannesburgUTM.hemisphere, .southern)
|
||||
|
||||
let buninyongUTM = buninyongLocation.utmCoordinate()
|
||||
XCTAssertEqualWithAccuracy(buninyongUTM.northing, 5828674.33994, accuracy: 0.00001)
|
||||
XCTAssertEqualWithAccuracy(buninyongUTM.easting, 758173.79835, accuracy: 0.00001)
|
||||
XCTAssertEqual(buninyongUTM.zone, 54)
|
||||
XCTAssertEqual(buninyongUTM.hemisphere, .southern)
|
||||
}
|
||||
|
||||
|
||||
func testUTMCoordinate_coordinate() {
|
||||
let oslo = osloUTM.coordinate()
|
||||
XCTAssertEqual(oslo.latitude, 59.912814611065265)
|
||||
|
@ -60,11 +72,14 @@ class UTMConversionTests: XCTestCase {
|
|||
let trondheim = trondheimUTM.coordinate()
|
||||
XCTAssertEqual(trondheim.latitude, 63.430493678423012)
|
||||
XCTAssertEqual(trondheim.longitude, 10.394966844991798)
|
||||
|
||||
let utmJohannesburg = UTMCoordinate(northing: 7100115, easting: 603914, zone: 35, hemisphere: .southern)
|
||||
let johannesburg = utmJohannesburg.coordinate()
|
||||
|
||||
let johannesburg = johannesburgUTM.coordinate()
|
||||
XCTAssertEqual(johannesburg.latitude, -26.214767103043133)
|
||||
XCTAssertEqual(johannesburg.longitude, 28.040197220939884)
|
||||
|
||||
let buninyong = buninyongUTM.coordinate()
|
||||
XCTAssertEqualWithAccuracy(buninyong.latitude, -37.65282114, accuracy: 0.00001)
|
||||
XCTAssertEqualWithAccuracy(buninyong.longitude, 143.92649554, accuracy: 0.00001)
|
||||
}
|
||||
|
||||
func testUTMCoordinate_location() {
|
||||
|
@ -79,19 +94,26 @@ class UTMConversionTests: XCTestCase {
|
|||
let johannesburg = johannesburgUTM.location()
|
||||
XCTAssertEqual(johannesburg.coordinate.latitude, -26.214767103043133)
|
||||
XCTAssertEqual(johannesburg.coordinate.longitude, 28.040197220939884)
|
||||
|
||||
let buninyong = buninyongUTM.location()
|
||||
XCTAssertEqualWithAccuracy(buninyong.coordinate.latitude, -37.65282114, accuracy: 0.00001)
|
||||
XCTAssertEqualWithAccuracy(buninyong.coordinate.longitude, 143.92649554, accuracy: 0.00001)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private let buninyong = CLLocationCoordinate2D(latitude: -37.65282114, longitude: 143.92649554)
|
||||
private let oslo = CLLocationCoordinate2D(latitude: 59.912814611065265, longitude: 10.760192985178369)
|
||||
private let trondheim = CLLocationCoordinate2D(latitude: 63.430493678423012, longitude: 10.394966844991798)
|
||||
private let johannesburg = CLLocationCoordinate2D(latitude: -26.214767103043133, longitude: 28.040197220939884)
|
||||
|
||||
private let buninyongUTM = UTMCoordinate(northing: 5828674.33994, easting: 758173.79835, zone: 54, hemisphere: .southern)
|
||||
private let osloUTM = UTMCoordinate(northing: 6643010, easting: 598430, zone: 32, hemisphere: .northern)
|
||||
private let trondheimUTM = UTMCoordinate(northing: 7034313, easting: 569612, zone: 32, hemisphere: .northern)
|
||||
private let johannesburgUTM = UTMCoordinate(northing: 7100115, easting: 603914, zone: 35, hemisphere: .southern)
|
||||
|
||||
private let osloLocation = CLLocation(latitude: 59.912814611065265, longitude: 10.760192985178369)
|
||||
private let trondheimLocation = CLLocation(latitude: 63.430493678423012, longitude: 10.394966844991798)
|
||||
private let johannesburgLocation = CLLocation(latitude: -26.214767103043133, longitude: 28.040197220939884)
|
||||
private let buninyongLocation = CLLocation(latitude: buninyong.latitude, longitude: buninyong.longitude)
|
||||
private let osloLocation = CLLocation(latitude: oslo.latitude, longitude: oslo.longitude)
|
||||
private let trondheimLocation = CLLocation(latitude: trondheim.latitude, longitude: trondheim.longitude)
|
||||
private let johannesburgLocation = CLLocation(latitude: johannesburg.latitude, longitude: johannesburg.longitude)
|
||||
|
|
Loading…
Reference in New Issue