Projections
Besides the Coordinates class, the Maps SDK for C++ provides a Projection class that represents the base class for different geocoordinate systems such as:
WGS84(World Geodetic System 1984)GK(Gauss-Kruger)UTM(Universal Transverse Mercator)LAM(Lambert)BNG(British National Grid)MGRS(Military Grid Reference System)W3W(What three words)
To know the type of the Projection you can use the type getter:
auto type = projection.type();
WGS84 Projection
The WGS84 projection is a widely used geodetic datum that serves as the foundation for GPS and other mapping systems. It provides a standard reference frame for the Earth's surface, allowing for accurate positioning and navigation. A WGS84 projection can be instantiated using a Coordinates object:
auto projectionObj = Projection_WGS84({51.50328, -0.11067});
Then, the coordinates can be accessed and set using the coordinates getter and setter:
auto coordinates = projectionObj.getCoordinates(); // Get coordinates
projectionObj.set({ 40.77228, -73.97136 }); // Set coordinates
The coordinates getter returns empty if the coordinates are not set.
GK Projection
The Gauss-Kruger projection is a cylindrical map projection that is 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, allowing for accurate representation of geographic features. A Gauss-Kruger projection can be instantiated using the following constructor:
auto projectionObj = Projection_GK();
projectionObj.set(/*x:*/ 6325113.72, /*y:*/ 5082540.66, /*zone:*/ 1);
In order to obtain the x, y and zone values, the getEasting, getNorthing and getZone getters can be used, while setting them can be done using the set method:
auto projectionObj = Projection_GK();
projectionObj.set(/*x:*/ 6325113.72, /*y:*/ 5082540.66, /*zone:*/ 1);
auto type = projectionObj.type(); // EProjectionType::EPR_Gk
auto zone = projectionObj.getZone(); // 1
auto easting = projectionObj.getEasting(); // 6325113.72
auto northing = projectionObj.getNorthing(); // 5082540.66
projectionObj.set(1, 1, 2);
auto newZone = projectionObj.getZone(); // 2
auto newEasting = projectionObj.getEasting(); // 1
auto newNorthing = projectionObj.getNorthing(); // 1
The Gauss-Kruger projection is currently supported only for countries that use Bessel ellipsoid. Trying to convert to and from Gauss-Kruger projection for other countries will result in a error::KNotSupported 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 that allows for precise location identification within the country. A BNG projection can be instantiated using the following constructor:
auto projectionObj = Projection_BNG();
In order to obtain the easting and northing values, the getEasting and getNorthing getters can be used, while setting them can be done using the set method:
auto projectionObj = Projection_BNG();
projectionObj.set(1, 1);
auto type = projectionObj.type(); // EProjectionType::EPR_Bng
auto newEasting = projectionObj.getEasting(); // 1
auto newNorthing = projectionObj.getNorthing(); // 1
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 to provide a grid reference system that is easy to use in the field. A MGRS projection can be instantiated using the following constructor:
auto projectionObj = Projection_MGRS();
In order to obtain the easting, northing, zone and letters values, the getEasting, getNorthing, getZone and getSq100kIdentifier getters can be used, while setting them can be done using the set method:
auto projectionObj = Projection_MGRS();
projectionObj.set(
1, 1, "B", "WC");
auto type = projectionObj.type(); // EProjectionType::EPR_Mgrs
auto newEasting = projectionObj.getEasting(); // 1
auto newNorthing = projectionObj.getNorthing(); // 1
auto newZone = projectionObj.getZone(); // B
auto newLetters = projectionObj.getSq100kIdentifier(); // WC
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. This system provides a simple and memorable way to reference specific locations. A W3W projection can be instantiated using the following constructor:
auto projectionObj = Projection_W3W();
In order to obtain and set the token and words values, the token and words getters and setters can be used.
LAM Projection
The LAM (Lambert) projection is a conic map projection that is commonly used for large-scale mapping in regions with an east-west orientation. It provides a way to represent geographic features accurately while minimizing distortion. A LAM projection can be instantiated using the following constructor:
auto projectionObj = Projection_LAM(/*x:*/ 6325113.72, /*y:*/ 5082540.66);
In order to obtain the x and y values, the x and y getters can be used, while setting them can be done using the set method.
auto projectionObj = Projection_LAM(/*x:*/ 6325113.72, /*y:*/ 5082540.66);
projectionObj.set(1, 1);
auto type = projectionObj.type(); // EProjectionType::EPR_Lam
auto newX = projectionObj.getX(); // 1
auto newY = projectionObj.getY(); // 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. It provides a way to represent geographic features accurately while minimizing distortion. A UTM projection can be instantiated using the following constructor:
auto projectionObj = Projection_UTM(/*x:*/ 6325113.72, /*y:*/ 5082540.66, /*zone:*/ 1, /*hemisphere:*/ EHemisphere::HEM_South);
In order to obtain the x, y, zone and hemisphere values, the x, y, zone and hemisphere getters can be used, while setting them can be done using the set method:
auto projectionObj = Projection_UTM(/*x:*/ 6325113.72, /*y:*/ 5082540.66, /*zone:*/ 1, /*hemisphere:*/ EHemisphere::HEM_South);
projectionObj.set(1, 1, 2, EHemisphere::HEM_North);
auto type = projectionObj.type(); // EProjectionType::EPR_Utm
auto newZone = projectionObj.getZone(); // 2
auto newX = projectionObj.getX(); // 1
auto newY = projectionObj.getY(); // 1
auto newHemisphere = projectionObj.getHemisphere(); // EHemisphere::HEM_North
Projection Service
The ProjectionService class provides a method to convert between different projection types. It allows you to transform coordinates from one projection to another, making it easier to work with various geospatial data formats. The class is abstract and features a static convert method:
auto from = Projection_WGS84();
from.set({51.5074, -0.1278});
auto to = Projection_MGRS();
ProjectionService().convert(
from,
to,
yourProgressListenerImpl
);
// Wait for the operation to complete (replace with your own synchronization mechanism).
WAIT_UNTIL( std::bind( &YourProgressListenerImpl::IsFinished, yourProgressListenerImpl ), 15000 );
auto easting = to.getEasting(); // 99316
auto northing = to.getNorthing(); // 10163
auto zone = to.getZone(); // 30U
auto sq100kIdentifier = to.getSq100kIdentifier(); // XC
ProjectionService::convert works with Projection_W3W only if the Projection_W3W object has a valid token that can be obtained from what3words.com. If the token is not set, the conversion will fail and the error::KNotSupported error will be returned via notifyComplete.