Class MilitaryGridReferenceSystem.Decoder
java.lang.Object
org.apache.sis.referencing.gazetteer.AbstractLocation
org.apache.sis.referencing.gazetteer.SimpleLocation
org.apache.sis.referencing.gazetteer.SimpleLocation.Projected
org.apache.sis.referencing.gazetteer.MilitaryGridReferenceSystem.Decoder
- All Implemented Interfaces:
org.opengis.geometry.coordinate.Position
,org.opengis.geometry.DirectPosition
,org.opengis.geometry.Envelope
,org.opengis.metadata.extent.GeographicBoundingBox
,org.opengis.metadata.extent.GeographicExtent
- Enclosing class:
MilitaryGridReferenceSystem
The result of decoding a MGRS reference.
The position represents the centroid of the decoded MGRS reference.
- Since:
- 0.8
- Version:
- 0.8
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.sis.referencing.gazetteer.SimpleLocation
SimpleLocation.Projected
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final org.opengis.referencing.crs.ProjectedCRS
The Coordinate Reference System of the decoded MGRS reference.(package private) static final int
Number of bits reserved for storing the minimal northing value of latitude bands in theROW_RESOLVER
table.(package private) static final int
Mask over the 4 lowest bits.private static final int[]
Mapping from latitude bands to the minimal northing values, together with the set of valid rows.Fields inherited from class org.apache.sis.referencing.gazetteer.SimpleLocation.Projected
eastBoundLongitude, northBoundLatitude, southBoundLatitude, westBoundLongitude
Fields inherited from class org.apache.sis.referencing.gazetteer.SimpleLocation
maxX, maxY, minX, minY
-
Constructor Summary
ConstructorsConstructorDescriptionDecoder
(MilitaryGridReferenceSystem.Coder owner, CharSequence reference) Decodes the given MGRS reference. -
Method Summary
Modifier and TypeMethodDescriptionprivate static int
endOfDigits
(CharSequence reference, int i, int end) Returns the index after the last digit in a sequence of ASCII characters.org.opengis.referencing.crs.CoordinateReferenceSystem
Returns the Coordinate Reference System of the decoded MGRS reference.private static boolean
isLetter
(int c) Returnstrue
if the given character is a valid upper case ASCII letter, excluding I and O.private static int
nextComponent
(MilitaryGridReferenceSystem.Coder owner, CharSequence reference, int base, int start, int end) Skips spaces, then the separator if present (optional).private static double
parseCoordinate
(CharSequence reference, int start, int end, double scale) Parses part of the given character sequence as a grid coordinate.private static int
parseInt
(CharSequence reference, int start, int end, short errorKey) Parses part of the given character sequence as an integer.(package private) static double
upperBound
(double φ) Returns the upper bound of the latitude band specified by the given lower bound.Methods inherited from class org.apache.sis.referencing.gazetteer.SimpleLocation.Projected
clipGeographicBoundingBox, clipProjectedEnvelope, computeGeographicBoundingBox, getEastBoundLongitude, getNorthBoundLatitude, getSouthBoundLatitude, getWestBoundLongitude
Methods inherited from class org.apache.sis.referencing.gazetteer.SimpleLocation
convert, getCoordinate, getDimension, getDirectPosition, getEnvelope, getGeographicExtent, getInclusion, getLowerCorner, getMaximum, getMedian, getMinimum, getOrdinate, getPosition, getSpan, getUpperCorner, setOrdinate
Methods inherited from class org.apache.sis.referencing.gazetteer.AbstractLocation
getAdministrator, getAlternativeGeographicIdentifiers, getChildren, getGeographicIdentifier, getLocationType, getParents, getTemporalExtent, setTypeToChild, toString, type
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.opengis.geometry.DirectPosition
equals, hashCode
Methods inherited from interface org.opengis.metadata.extent.GeographicExtent
getInclusion
-
Field Details
-
NORTHING_BITS_COUNT
static final int NORTHING_BITS_COUNTNumber of bits reserved for storing the minimal northing value of latitude bands in theROW_RESOLVER
table.- See Also:
-
NORTHING_BITS_MASK
static final int NORTHING_BITS_MASKMask over the 4 lowest bits.- See Also:
-
ROW_RESOLVER
private static final int[] ROW_RESOLVERMapping from latitude bands to the minimal northing values, together with the set of valid rows. There is 20 latitude bands identified by letters C to X inclusively, with letters I and O skipped. First, the band letter must be converted to an index i in the [0 … 19] range. Then, theROW_RESOLVER[i]
integer values provides the following information:- The lowest 4 bits gives the minimal northing value of all valid coordinates in the latitude band, as a multiple of the number of metres in a full cycle of 20 rows. That northing value can be computed in metre as below:
-
Given a row number row in the [0 … 19] range, the following expression tells
if that row can be inside the latitude band:
Note that the same row may be valid in two consecutive latitude bands.
The trailing
_0000
parts make room for 4 bits.
MilitaryGridReferenceSystemTest.verifyDecoderTables()
. The same method with minor edition can be used for generating this table. -
crs
private final org.opengis.referencing.crs.ProjectedCRS crsThe Coordinate Reference System of the decoded MGRS reference. This is an Universal Transverse Mercator (UTM) or Universal Polar Stereographic (UPS) projection.- See Also:
-
-
Constructor Details
-
Decoder
Decoder(MilitaryGridReferenceSystem.Coder owner, CharSequence reference) throws org.opengis.referencing.operation.TransformException Decodes the given MGRS reference.- Parameters:
owner
- theCoder
which is creating thisDecoder
.- Throws:
org.opengis.referencing.operation.TransformException
-
-
Method Details
-
nextComponent
private static int nextComponent(MilitaryGridReferenceSystem.Coder owner, CharSequence reference, int base, int start, int end) throws GazetteerException Skips spaces, then the separator if present (optional).- Parameters:
reference
- the reference to parse.base
- index where the parsing began. Used for formatting error message only.start
- current parsing position.end
- where the parsing is expected to end.- Returns:
- position where to continue parsing (with spaces skipped).
- Throws:
GazetteerException
- if this method unexpectedly reached the end of string.
-
isLetter
private static boolean isLetter(int c) Returnstrue
if the given character is a valid upper case ASCII letter, excluding I and O. -
endOfDigits
Returns the index after the last digit in a sequence of ASCII characters. Leading whitespaces must have been skipped before to invoke this method. -
parseInt
private static int parseInt(CharSequence reference, int start, int end, short errorKey) throws GazetteerException Parses part of the given character sequence as an integer.- Parameters:
reference
- the MGRS reference to parse.start
- index of the first character to parse as an integer.end
- index after the last character to parse as an integer.errorKey
-Resources.Keys
value to use in case of error. The error message string shall accept exactly one argument.- Returns:
- the parsed integer.
- Throws:
GazetteerException
- if the string cannot be parsed as an integer.
-
parseCoordinate
private static double parseCoordinate(CharSequence reference, int start, int end, double scale) throws GazetteerException Parses part of the given character sequence as a grid coordinate. The resolution is determined by the amount of digits.- Parameters:
reference
- the MGRS reference to parse.start
- index of the first character to parse as a grid coordinate.end
- index after the last character to parse as a grid coordinate.scale
- value ofMathFunctions.pow10(METRE_PRECISION_DIGITS - (end - start))
.- Returns:
- the parsed grid coordinate (also referred to as rectangular coordinates).
- Throws:
GazetteerException
- if the string cannot be parsed as a grid coordinate.
-
upperBound
static double upperBound(double φ) Returns the upper bound of the latitude band specified by the given lower bound. -
getCoordinateReferenceSystem
public org.opengis.referencing.crs.CoordinateReferenceSystem getCoordinateReferenceSystem()Returns the Coordinate Reference System of the decoded MGRS reference. This is an Universal Transverse Mercator (UTM) or Universal Polar Stereographic (UPS) projection.- Specified by:
getCoordinateReferenceSystem
in interfaceorg.opengis.geometry.DirectPosition
- Specified by:
getCoordinateReferenceSystem
in interfaceorg.opengis.geometry.Envelope
- Overrides:
getCoordinateReferenceSystem
in classSimpleLocation
-