Class MgrsFormat

java.lang.Object
com.luciad.grids.mgrs.MgrsFormat
All Implemented Interfaces:
AutoCloseable

public final class MgrsFormat extends Object implements AutoCloseable
Class to format points as MGRS or UTM/UPS coordinates.

This class offers methods to format coordinates into either UTM MGRS, UPS MGRS, UTM or UPS notation. The UTM MGRS and UTM notations are used for coordinates within the UTM latitude bounds. For points in the polar regions, outside the UTM latitude bounds, the UPS MGRS and UPS notations are used.

Construction of this class is done through the Builder design pattern mechanism.

Example usage:

    MgrsFormat mgrsFormat = MgrsFormat.newBuilder()
                                      .precision(MgrsFormatPrecision.Precision1M)
                                      .formatType(MgrsFormatType.Mgrs)
                                      .zoneSeparator(" ")
                                      .coordinateSeparator(" ")
                                      .build();
    CoordinateReference wgs84 = CoordinateReferenceProvider.create("EPSG:4326");
    Point point = GeometryFactory.createPoint(wgs84, 5, 45, 0);
    String stringResult = mgrsFormat.format(point);

    Point parsed = mgrsFormat.parse(stringResult);
Since:
2023.1
  • Constructor Details

    • MgrsFormat

      public MgrsFormat(@NotNull MgrsFormat other)
  • Method Details

    • finalize

      protected void finalize()
      Overrides:
      finalize in class Object
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • newBuilder

      @NotNull public static MgrsFormat.Builder newBuilder()
      Creates a new builder with the default values.
      Returns:
      the new builder.
    • asBuilder

      @NotNull public MgrsFormat.Builder asBuilder()
      Creates a new builder initialized with all the properties of this style.
      Returns:
      the new builder.
    • format

      @NotNull public String format(@NotNull Point lonLatPoint) throws IllegalArgumentException
      Formats the given point or the given (lon,lat) pair as an MGRS or UTM/UPS coordinate string.
      Parameters:
      lonLatPoint - the point to be formatted. The reference of the point must be WGS84.
      Returns:
      the formatted string.
      Throws:
      IllegalArgumentException - when the the point cannot be formatted.
    • parse

      @NotNull public Point parse(@NotNull String coordinateString) throws ParseException
      Parses the given MGRS or UTM/UPS coordinate string into a point with WGS84 lon lat coordinates.
      Parameters:
      coordinateString - a MGRS coordinate string
      Returns:
      the coordinate reference.
      Throws:
      ParseException - when the coordinate string cannot be parsed.
    • getPrecision

      @NotNull public MgrsFormatPrecision getPrecision()
      Returns the MgrsFormatPrecision used to format an MGRS or UTM/UPS string.
      Returns:
      the precision.
    • getFormatType

      @NotNull public MgrsFormatType getFormatType()
      Returns the MgrsFormatType used to format an MGRS or UTM/UPS string.
      Returns:
      the format type.
    • getZoneSeparator

      @NotNull public String getZoneSeparator()
      Returns the string to separate the zone/grid letters and the coordinates.
      Returns:
      the zone separator.
    • getCoordinateSeparator

      @NotNull public String getCoordinateSeparator()
      Returns the string to separate the zone/grid letters and the coordinates.
      Returns:
      the coordinate separator.