Projections
Learn how to create projection objects and convert between coordinate systems using ProjectionContext.
Supported projection types
WGS84- World Geodetic System 1984GK- Gauss-KrugerUTM- Universal Transverse MercatorLAM- LambertBNG- British National GridMGRS- Military Grid Reference SystemW3W- What three words
WGS84 projection
The WGS84 projection is a widely used geodetic datum that serves as the foundation for GPS and other mapping systems.
Create a WGS84 projection using coordinates:
let wgs = ProjectionWGS84Object(
coordinates: CoordinatesObject.coordinates(withLatitude: 51.5074, longitude: -0.1278)
)
Access and modify coordinates using the getter and setter:
if let coords = wgs.getCoordinates() {
print("latitude=\(coords.getLatitude()) longitude=\(coords.getLongitude())")
}
wgs.setCoordinates(
CoordinatesObject.coordinates(withLatitude: 10.0, longitude: 10.0)
)
GK projection
The Gauss-Kruger projection is a cylindrical map projection commonly used for large-scale mapping in regions with a north-south orientation. It divides the Earth into zones, each with its own coordinate system.
Create a Gauss-Kruger projection:
let gk = ProjectionGKObject(x: 6325113.72, y: 5082540.66, zone: 1)
Access and modify values using getter and setter methods:
let easting = gk.getEasting()
let northing = gk.getNorthing()
let zone = gk.getZone()
print("easting=\(easting) northing=\(northing) zone=\(zone)")
gk.setX(1, setY: 1, zone: 2)
The Gauss-Kruger projection is currently supported only for countries that use the Bessel ellipsoid. Converting to and from Gauss-Kruger projection for other countries will result in an SDKErrorCode error.
BNG projection
The BNG (British National Grid) projection is a coordinate system used in Great Britain for mapping and navigation. It provides a grid reference system for precise location identification.
Create a BNG projection using easting and northing:
let bng = ProjectionBNGObject(easting: 500000, northing: 4649776)
Or create from a grid reference string:
let bng2 = ProjectionBNGObject(gridReference: "TL56")
Access and modify values:
let easting = bng.getEasting()
let northing = bng.getNorthing()
let gridRef = bng.getGridReference()
print("easting=\(easting) northing=\(northing) grid=\(gridRef)")
bng.setEasting(1, northing: 1)
bng.setGridReference("SJ23")
MGRS projection
The MGRS (Military Grid Reference System) projection is a coordinate system used by the military for precise location identification. It combines the UTM and UPS coordinate systems.
Create a MGRS projection:
let mgrs = ProjectionMGRSObject(easting: 99316, northing: 10163, zone: "30U", letters: "XC")
Access and modify values:
let easting = mgrs.getEasting()
let northing = mgrs.getNorthing()
let zone = mgrs.getZone()
let sq100k = mgrs.getSq100kIdentifier()
print("easting=\(easting) northing=\(northing) zone=\(zone) sq100k=\(sq100k)")
mgrs.setEasting(1, northing: 1, zone: "B", letters: "AB")
W3W projection
The W3W (What three words) projection is a geocoding system that divides the world into a grid of 3m x 3m squares, each identified by a unique combination of three words.
Create a W3W projection with an API token:
let w3w = ProjectionW3WObject(token: "your-api-token")
Access and modify token and words:
let token = w3w.getToken()
let words = w3w.getWords()
w3w.setToken("new-token")
w3w.setWords("///hello.world.test")
LAM projection
The LAM (Lambert) projection is a conic map projection commonly used for large-scale mapping in regions with an east-west orientation.
Create a LAM projection:
let lam = ProjectionLAMObject(x: 6325113.72, y: 5082540.66)
Access and modify coordinates:
let x = lam.getX()
let y = lam.getY()
print("x=\(x) y=\(y)")
lam.setX(1, setY: 1)
UTM projection
The UTM (Universal Transverse Mercator) projection is a global map projection that divides the world into a series of zones, each with its own coordinate system.
Create a UTM projection:
let utm = ProjectionUTMObject(x: 6325113.72, y: 5082540.66, zone: 1, hemisphere: .north)
Access and modify values:
let x = utm.getX()
let y = utm.getY()
let zone = utm.getZone()
let hemisphere = utm.getHemisphere()
print("x=\(x) y=\(y) zone=\(zone) hemisphere=\(hemisphere)")
utm.setX(1, setY: 1, zone: 2, hemisphere: .south)
Convert between projections
ProjectionContext.convert(_:to:completionHandler:) converts from one projection object to another.
let context = ProjectionContext()
let from = ProjectionWGS84Object(
coordinates: CoordinatesObject.coordinates(withLatitude: 51.5074, longitude: -0.1278)
)
let to = ProjectionMGRSObject(easting: 0, northing: 0, zone: "", letters: "")
let code = context.convert(from, to: to) { result in
print("conversion result = \(result)")
print("zone=\(to.getZone()) easting=\(to.getEasting()) northing=\(to.getNorthing())")
}
print("operation started with code = \(code)")
ProjectionContext.convert works with ProjectionW3WObject only if the object has a valid token that can be obtained from what3words.com. If the token is not set or invalid, the conversion will fail and return SDKErrorCodeKNotSupported.