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

Function FormatMGRS

libs/platform/utm_mgrs_utils.cpp:437–456  ·  view source on GitHub ↗

Convert lat,lon for WGS84 ellipsoid to MGRS string.

Source from the content-addressed store, hash-verified

435
436// Convert lat,lon for WGS84 ellipsoid to MGRS string.
437std::string FormatMGRS(double lat, double lon, int precision)
438{
439 if (precision > 5)
440 precision = 5;
441 else if (precision < 1)
442 precision = 1;
443
444 if (lat <= -80 || lat > 84)
445 return {}; // Latitude limit exceeded.
446 if (lon <= -180 || lon > 180)
447 return {}; // Longitude limit exceeded.
448
449 UTMPoint mgrsp = LatLonToUtm(lat, lon);
450
451 // Need to set the right letter for the latitude.
452 auto const zoneLetter = LatitudeToZoneLetter(lat);
453 ASSERT(zoneLetter, (lat));
454 mgrsp.zoneLetter = zoneLetter;
455 return UTMtoMgrsStr(mgrsp, precision);
456}
457
458// Convert lat,lon for WGS84 ellipsoid to UTM string.
459std::string FormatUTM(double lat, double lon)

Calls 4

LatLonToUtmFunction · 0.85
LatitudeToZoneLetterFunction · 0.85
ASSERTFunction · 0.85
UTMtoMgrsStrFunction · 0.85

Tested by 1

UNIT_TESTFunction · 0.68