Convert between UTM/UPS and MGRS. More...
#include <GeographicLib/MGRS.hpp>
Static Public Member Functions | |
static void | Forward (int zone, bool northp, double x, double y, int prec, std::string &mgrs) |
static void | Forward (int zone, bool northp, double x, double y, double lat, int prec, std::string &mgrs) |
static void | Reverse (const std::string &mgrs, int &zone, bool &northp, double &x, double &y, int &prec, bool centerp=true) |
Friends | |
class | UTMUPS |
class | GeoCoords |
Convert between UTM/UPS and MGRS.
MGRS is defined in Chapter 3 of
This implementation has the following properties:
The NGA software package geotrans also provides conversions to and from MGRS. Version 2.4.2 (and earlier) suffers from some drawbacks:
void GeographicLib::MGRS::Forward | ( | int | zone, |
bool | northp, | ||
double | x, | ||
double | y, | ||
int | prec, | ||
std::string & | mgrs | ||
) | [static] |
Convert UTM or UPS coordinate to an MGRS coordinate. zone and northp give input zone (with zone = 0 indicating UPS) and hemisphere, x and y are the easting and northing (meters). prec indicates the desired precision with prec = 0 (the minimum) meaning 100 km, prec = 5 meaning 1 m, and prec == 11 (the maximum) meaning 1 um.
UTM eastings are allowed to be in the range [100 km, 900 km], northings are allowed to be in in [0 km, 9500 km] for the northern hemisphere and in [1000 km, 10000 km] for the southern hemisphere. (However UTM northings can be continued across the equator. So the actual limits on the northings are [-9000 km, 9500 km] for the "northern" hemisphere and [1000 km, 19500 km] for the "southern" hemisphere.)
UPS eastings/northings are allowed to be in the range [1300 km, 2700 km] in the northern hemisphere and in [800 km, 3200 km] in the southern hemisphere.
The ranges are 100 km more restrictive that for the conversion between geographic coordinates and UTM and UPS given by UTMUPS. These restrictions are dictated by the allowed letters in MGRS coordinates. The choice of 9500 km for the maximum northing for northern hemisphere and of 1000 km as the minimum northing for southern hemisphere provide at least 0.5 degree extension into standard UPS zones. The upper ends of the ranges for the UPS coordinates is dictated by requiring symmetry about the meridans 0E and 90E.
All allowed UTM and UPS coordinates may now be converted to legal MGRS coordinates with the proviso that eastings and northings on the upper boundaries are silently reduced by about 4nm to place them within the allowed range. (This includes reducing a southern hemisphere northing of 10000km by 4nm so that it is placed in latitude band M.) The UTM or UPS coordinates are truncated to requested precision to determine the MGRS coordinate. Thus in UTM zone 38N, the square area with easting in [444 km, 445 km) and northing in [3688 km, 3689 km) maps to MGRS coordinate 38SMB4488 (at prec = 2, 1km), Kulani Sq., Baghdad.
The UTM/UPS selection and the UTM zone is preserved in the conversion to MGRS coordinate. Thus for zone > 0, the MGRS coordinate begins with the zone number followed by one of [C–M] for the southern hemisphere and [N–X] for the northern hemisphere. For zone = 0, the MGRS coordinates begins with one of [AB] for the southern hemisphere and [XY] for the northern hemisphere.
The conversion to the MGRS is exact for prec in [0, 5] except that a neighboring latitude band letter may be given if the point is within 5nm of a band boundary. For prec in [6, 11], the conversion is accurate to roundoff.
Definition at line 125 of file MGRS.cpp.
References GeographicLib::UTMUPS::Reverse().
Referenced by GeographicLib::GeoCoords::MGRSRepresentation(), and GeographicLib::GeoCoords::AltMGRSRepresentation().
void GeographicLib::MGRS::Forward | ( | int | zone, |
bool | northp, | ||
double | x, | ||
double | y, | ||
double | lat, | ||
int | prec, | ||
std::string & | mgrs | ||
) | [static] |
Convert UTM or UPS coordinates to an MGRS coordinate in case that latitude is already known. The latitude is ignored for zone = 0 (UPS); otherwise the latitude is used to determine the latitude band and this is checked for consistency using the same tests as Reverse.
void GeographicLib::MGRS::Reverse | ( | const std::string & | mgrs, |
int & | zone, | ||
bool & | northp, | ||
double & | x, | ||
double & | y, | ||
int & | prec, | ||
bool | centerp = true |
||
) | [static] |
Convert a MGRS coordinate to UTM or UPS coordinates returning zone zone, hemisphere northp, easting x (meters), northing y (meters) . Also return the precision of the MGRS string (see Forward). If centerp = true (default), return center of the MGRS square, else return SW (lower left) corner.
All conversions from MGRS to UTM/UPS are permitted provided the MGRS coordinate is a possible result of a conversion in the other direction. (The leading 0 may be dropped from an input MGRS coordinate for UTM zones 1–9.) In addition, MGRS coordinates with a neighboring latitude band letter are permitted provided that some portion of the 100km block is within the given latitude band. Thus
The UTM/UPS selection and the UTM zone is preserved in the conversion from MGRS coordinate. The conversion is exact for prec in [0, 5]. With centerp = true the conversion from MGRS to geographic and back is stable. This is not assured if centerp = false.
Definition at line 136 of file MGRS.cpp.
Referenced by GeographicLib::GeoCoords::Reset().