Class MilitaryGridReferenceSystem.Encoder
java.lang.Object
org.apache.sis.referencing.gazetteer.MilitaryGridReferenceSystem.Encoder
- Enclosing class:
MilitaryGridReferenceSystem
Conversions from direct positions to Military Grid Reference System (MGRS) references.
Each
Encoder
instance is configured for one DirectPosition
CRS.
If a position is given in another CRS, another Encoder
instance must be created.
Immutability and thread safety
This class is not thread-safe. A new instance must be created for each thread, or synchronization must be applied by the caller.- Since:
- 0.8
- Version:
- 1.3
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int
The actual zone where the position to encode is located.(package private) final int
UTM zone of position CRS (negative for South hemisphere), or 100 (negative of positive) if the CRS is a Universal Polar Stereographic projection, or 0 if the CRS is not a recognized projection.private final CommonCRS
The datum to which to transform the coordinates before formatting the MGRS reference.(package private) char
The latitude band of the last encoded reference.private static final int
SpecialcrsZone
value for the UPS (Universal Polar Stereographic) projection.private org.opengis.referencing.operation.MathTransform
A transform from a position in the CRS given at construction time to a position in the CRS identified byactualZone
.private final org.opengis.referencing.operation.MathTransform
Coordinate conversion or transformation from the normalized CRS to geographic CRS.private final org.opengis.referencing.operation.MathTransform
Coordinate conversion from the position CRS to a CRS of the same type but with normalized axes, ornull
if not needed. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
append
(StringBuilder buffer, int value, int digits) Appends the given value in the given buffer, padding with zero digits in order to get the specified total amount of digits.(package private) String
encode
(MilitaryGridReferenceSystem.Coder owner, org.opengis.geometry.DirectPosition position, boolean reproject, String separator, int digits, double precision) Encodes the given position into a MGRS reference.(package private) final double
getLatitude
(MilitaryGridReferenceSystem.Coder owner, org.opengis.geometry.DirectPosition position) Returns the latitude in degrees of given position.(package private) static char
latitudeBand
(double φ) Returns the band letter for the given latitude.private static char
letter
(int c) Returns the given character as achar
if it is a letter, or throws an exception otherwise.
-
Field Details
-
POLE
private static final int POLESpecialcrsZone
value for the UPS (Universal Polar Stereographic) projection. Positive value is used for North pole and negative value for South pole.- See Also:
-
datum
The datum to which to transform the coordinates before formatting the MGRS reference. Only the datums enumerated inCommonCRS
are currently supported. -
crsZone
final int crsZoneUTM zone of position CRS (negative for South hemisphere), or 100 (negative of positive) if the CRS is a Universal Polar Stereographic projection, or 0 if the CRS is not a recognized projection. Note that this is not necessarily the same zone than the one to use for formatting any given coordinate in that projected CRS, since theTransverseMercator.Zoner.zone(double, double)
method has special rules for some latitudes. -
toNormalized
private final org.opengis.referencing.operation.MathTransform toNormalizedCoordinate conversion from the position CRS to a CRS of the same type but with normalized axes, ornull
if not needed. After conversion, axis directions will be (East, North) and axis units will be metres.This transform should perform only simple operations like swapping axis order and unit conversions. It should not perform more complex operations that would require to go back to geographic coordinates.
-
toGeographic
private final org.opengis.referencing.operation.MathTransform toGeographicCoordinate conversion or transformation from the normalized CRS to geographic CRS. Axis directions are (North, East) as in EPSG geodetic dataset and axis units are degrees. This transform is nevernull
.This transform may contain datum change from the position datum to the target
datum
. -
toActualZone
private org.opengis.referencing.operation.MathTransform toActualZoneA transform from a position in the CRS given at construction time to a position in the CRS identified byactualZone
. This field is updated only when a given position is not located in the zone of the CRS given at construction time. -
actualZone
private int actualZoneThe actual zone where the position to encode is located. Legal values are the same thancrsZone
. If non-zero, then this is the zone of thetoActualZone
transform. This field is updated only when a given position is not located in the zone of the CRS given at construction time. -
latitudeBand
char latitudeBandThe latitude band of the last encoded reference. This information is provided forMilitaryGridReferenceSystem.IteratorOneZone
purpose.
-
-
Constructor Details
-
Encoder
Encoder(CommonCRS datum, org.opengis.referencing.crs.CoordinateReferenceSystem crs) throws org.opengis.util.FactoryException, org.opengis.referencing.operation.TransformException Creates a new converter from direct positions to MGRS references.- Parameters:
datum
- the datum to which to transform the coordinate before formatting the MGRS reference, ornull
for inferring the datum from the givencrs
.crs
- the coordinate reference system of the coordinates for which to create MGRS references.- Throws:
IllegalArgumentException
- if the given CRS do not use one of the supported datums.org.opengis.util.FactoryException
- if the creation of a coordinate operation failed.org.opengis.referencing.operation.TransformException
- if the creation of an inverse operation failed.
-
-
Method Details
-
latitudeBand
static char latitudeBand(double φ) Returns the band letter for the given latitude. It is caller responsibility to ensure that the given latitude is between -80.0 and 84.0 inclusive. The returned letter will be one of"CDEFGHJKLMNPQRSTUVWX"
(note that I and O letters are excluded). All bands are 8° height except the X band which is 12° height.- Parameters:
φ
- the latitude in degrees for which to get the band letter.- Returns:
- the band letter for the given latitude.
-
getLatitude
final double getLatitude(MilitaryGridReferenceSystem.Coder owner, org.opengis.geometry.DirectPosition position) throws org.opengis.referencing.operation.TransformException Returns the latitude in degrees of given position. This is used only for estimating the precision.- Throws:
org.opengis.referencing.operation.TransformException
-
encode
String encode(MilitaryGridReferenceSystem.Coder owner, org.opengis.geometry.DirectPosition position, boolean reproject, String separator, int digits, double precision) throws org.opengis.util.FactoryException, org.opengis.referencing.operation.TransformException Encodes the given position into a MGRS reference. It is caller responsibility to ensure that the position CRS is the same than the CRS specified at thisEncoder
creation time.- Parameters:
owner
- theCoder
which own thisEncoder
.position
- the direct position to format as a MGRS reference.reproject
- whether this method is allowed to reprojectposition
when needed.separator
- the separator to insert between each component of the MGRS identifier.digits
- number of digits to use for formatting the numerical part of a MGRS reference.precision
- angular precision in radians, or 0. If non-zero, it will overridedigits
.- Returns:
- the value of
buffer.toString()
, ornull
if a reprojection was necessary butreproject
isfalse
. - Throws:
org.opengis.util.FactoryException
org.opengis.referencing.operation.TransformException
-
letter
Returns the given character as achar
if it is a letter, or throws an exception otherwise. The exception should never happen, unless the the encoder is used for a planet larger than Earth for which we do not have enough letters.- Throws:
GazetteerException
-
append
Appends the given value in the given buffer, padding with zero digits in order to get the specified total amount of digits.- Throws:
GazetteerException
-