fromMgrs static method

ArcGISPoint fromMgrs(
  1. {required String coordinates,
  2. required SpatialReference? spatialReference,
  3. required MgrsConversionMode mgrsConversionMode}
)

Parses a coordinate in Military Grid Reference System (MGRS) notation, and returns a Point representing that location.

The spatial reference provided must have an ellipsoid and datum matching those used by the source of the MGRS string. If no spatial reference is provided, it is assumed the MGRS string is referenced to WGS 84. For an explanation of the different modes for interpreting an MGRS notation string, please see MgrsConversionMode. Note that the choice between zone 01 and 60 has no impact when reading from an MGRS notation string. The MGRS string can contain leading and trailing whitespace and can have whitespace between the grid zone designator, the 100km square identifier, and the numerical eastings and northings.

MGRS notation examples
30UVG898998
30UVG 89885 99877
Returns null on error, including when the given string is not valid MGRS notation.

Parameters:

  • coordinates — The MGRS notation string for the coordinate.
  • spatialReference — A spatial reference that defines the datum and ellipsoid referenced by the MGRS coordinate.
  • mgrsConversionMode — The mode used by the given MGRS coordinates.

Return Value: A point with the location from the MGRS string in the spatial reference provided.

Implementation

static ArcGISPoint fromMgrs(
    {required String coordinates,
    required SpatialReference? spatialReference,
    required MgrsConversionMode mgrsConversionMode}) {
  _initializeArcGISEnvironmentIfNeeded();
  final coreCoordinates = _CString(coordinates);
  final objectHandle = _withThrowingErrorHandler((errorHandler) {
    return runtimecore.RT_CoordinateFormatter_fromMGRS(
        coreCoordinates.bytes,
        spatialReference?._handle ?? ffi.nullptr,
        mgrsConversionMode.coreValue,
        errorHandler);
  });
  return ArcGISPoint._fromHandle(objectHandle)!;
}