Package com.luciad.grids.mgrs
Class MgrsFormat
java.lang.Object
com.luciad.grids.mgrs.MgrsFormat
- All Implemented Interfaces:
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
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionCreates a new builder initialized with all the properties of this style.void
close()
protected void
finalize()
Formats the given point or the given (lon,lat) pair as an MGRS or UTM/UPS coordinate string.Returns the string to separate the zone/grid letters and the coordinates.Returns theMgrsFormatType
used to format an MGRS or UTM/UPS string.Returns theMgrsFormatPrecision
used to format an MGRS or UTM/UPS string.Returns the string to separate the zone/grid letters and the coordinates.static MgrsFormat.Builder
Creates a new builder with the default values.Parses the given MGRS or UTM/UPS coordinate string into a point with WGS84 lon lat coordinates.
-
Constructor Details
-
MgrsFormat
-
-
Method Details
-
finalize
protected void finalize() -
close
public void close()- Specified by:
close
in interfaceAutoCloseable
-
newBuilder
Creates a new builder with the default values.- Returns:
- the new builder.
-
asBuilder
Creates a new builder initialized with all the properties of this style.- Returns:
- the new builder.
-
format
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
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
Returns theMgrsFormatPrecision
used to format an MGRS or UTM/UPS string.- Returns:
- the precision.
-
getFormatType
Returns theMgrsFormatType
used to format an MGRS or UTM/UPS string.- Returns:
- the format type.
-
getZoneSeparator
Returns the string to separate the zone/grid letters and the coordinates.- Returns:
- the zone separator.
-
getCoordinateSeparator
Returns the string to separate the zone/grid letters and the coordinates.- Returns:
- the coordinate separator.
-