public final class MgrsFormat extends Object implements AutoCloseable
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);
Modifier and Type | Class and Description |
---|---|
static class |
MgrsFormat.Builder
Builder for creating
MgrsFormat . |
Constructor and Description |
---|
MgrsFormat(MgrsFormat other) |
Modifier and Type | Method and Description |
---|---|
MgrsFormat.Builder |
asBuilder()
Creates a new builder initialized with all the properties of this style.
|
void |
close() |
protected void |
finalize() |
String |
format(Point lonLatPoint)
Formats the given point or the given (lon,lat) pair as an MGRS or UTM/UPS coordinate string.
|
String |
getCoordinateSeparator()
Gets the string to separate the zone/grid letters and the coordinates.
|
MgrsFormatType |
getFormatType()
Gets the
MgrsFormatType used to format an MGRS or UTM/UPS string. |
MgrsFormatPrecision |
getPrecision()
Gets the
MgrsFormatPrecision used to format an MGRS or UTM/UPS string. |
String |
getZoneSeparator()
Gets the string to separate the zone/grid letters and the coordinates.
|
static MgrsFormat.Builder |
newBuilder()
Creates a new builder with the default values.
|
Point |
parse(String coordinateString)
Parses the given MGRS or UTM/UPS coordinate string into a point with WGS84 lon lat coordinates.
|
public MgrsFormat(@NotNull MgrsFormat other)
public void close()
close
in interface AutoCloseable
@NotNull public static MgrsFormat.Builder newBuilder()
@NotNull public MgrsFormat.Builder asBuilder()
@NotNull public String format(@NotNull Point lonLatPoint) throws IllegalArgumentException
lonLatPoint
- the point to be formatted. The reference of the point must be WGS84.IllegalArgumentException
- when the the point cannot be formatted.@NotNull public Point parse(@NotNull String coordinateString) throws ParseException
coordinateString
- a MGRS coordinate stringParseException
- when the coordinate string cannot be parsed.@NotNull public MgrsFormatPrecision getPrecision()
MgrsFormatPrecision
used to format an MGRS or UTM/UPS string.@NotNull public MgrsFormatType getFormatType()
MgrsFormatType
used to format an MGRS or UTM/UPS string.@NotNull public String getZoneSeparator()
@NotNull public String getCoordinateSeparator()