MCPcopy Create free account
hub / github.com/comaps/comaps / UTMtoMgrsStr

Function UTMtoMgrsStr

libs/platform/utm_mgrs_utils.cpp:214–227  ·  view source on GitHub ↗

Convert UTM point parameters to MGRS parameters. Additional 2 char code is deducted. Easting and northing parameters are reduced to 5 digits.

Source from the content-addressed store, hash-verified

212// Convert UTM point parameters to MGRS parameters. Additional 2 char code is deducted.
213// Easting and northing parameters are reduced to 5 digits.
214std::string UTMtoMgrsStr(UTMPoint const & point, int precision)
215{
216 if (point.zoneLetter == 'Z')
217 return "Latitude limit exceeded";
218 auto const eastingStr = strings::to_string_width(static_cast<long>(point.easting), precision + 1);
219 auto northingStr = strings::to_string_width(static_cast<long>(point.northing), precision + 1);
220
221 if (northingStr.size() > 6)
222 northingStr = northingStr.substr(northingStr.size() - 6);
223
224 return strings::to_string_width(point.zoneNumber, 2) + point.zoneLetter + ' ' +
225 Get100kId(point.easting, point.northing, point.zoneNumber) + ' ' + eastingStr.substr(1, precision) + ' ' +
226 northingStr.substr(1, precision);
227}
228} // namespace
229
230// Convert UTM parameters to lat,lon for WSG 84 ellipsoid.

Callers 1

FormatMGRSFunction · 0.85

Calls 3

to_string_widthFunction · 0.85
Get100kIdFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected