public class MilitaryGridReferenceSystem.Coder extends Object
Coder
instance can read references at arbitrary precision, but formats at the
specified precision.
The same Coder
instance can be reused for reading or writing many MGRS references.
See the MilitaryGridReferenceSystem
enclosing class for usage example.
Defined in the sis-referencing-by-identifiers
module
Modifier | Constructor and Description |
---|---|
protected |
Coder()
Creates a new coder initialized to the default precision and separator.
|
Modifier and Type | Method and Description |
---|---|
AbstractLocation |
decode(CharSequence reference)
Decodes the given MGRS reference into a position and an envelope.
|
String |
encode(DirectPosition position)
Encodes the given position into a MGRS reference.
|
Iterator<String> |
encode(Envelope areaOfInterest)
Returns an iterator over all MGRS references that intersect the given envelope.
|
boolean |
getClipToValidArea()
Returns whether the decoded locations should be clipped to the valid area.
|
double |
getPrecision()
Returns the precision of the references formatted by this coder.
|
String |
getSeparator()
Returns the separator to insert between each component of the MGRS identifier.
|
void |
setClipToValidArea(boolean clip)
Sets whether the decoded locations should be clipped to the valid area.
|
void |
setPrecision(double precision)
Sets the desired precision of the references formatted by this coder.
|
void |
setSeparator(String separator)
Sets the separator to insert between each component of the MGRS identifier.
|
protected Coder()
public double getPrecision()
Precision (m) | Reference example |
---|---|
1 | 4 Q FJ 12345 67890 |
10 | 4 Q FJ 1234 6789 |
100 | 4 Q FJ 123 678 |
1000 | 4 Q FJ 12 67 |
10 000 | 4 Q FJ 1 6 |
100 000 | 4 Q FJ |
(approximative) 1 000 000 | 4 Q |
public void setPrecision(double precision)
getPrecision()
method.precision
- the desired precision in metres.public String getSeparator()
public void setSeparator(String separator)
Note that a MGRS reference is normally written as an entity without spaces, parentheses, dashes,
or decimal points. Invoking this method with a non-empty separator produces non-conform MGRS, but
is sometime convenient for readability or for use in file systems (with the '/'
separator).
separator
- the separator to insert between each component of the MGRS identifier.public boolean getClipToValidArea()
true
.true
if decoded locations are clipped to the valid area.public void setClipToValidArea(boolean clip)
decode(CharSequence)
method clips the square to the zone where it belongs.
Invoking this method with the false
value disables this behavior.clip
- whether the decoded locations should be clipped to the valid area.public String encode(DirectPosition position) throws TransformException
position
- the coordinate to encode.TransformException
- if an error occurred while transforming the given coordinate to a MGRS reference.public Iterator<String> encode(Envelope areaOfInterest) throws TransformException
areaOfInterest
. Consequently the iterator may return slightly more cells than expected.
A future version may filter the cells more accurately. If an application needs the same set of cells
than what current the implementation returns, it can invoke setClipToValidArea(false)
for preserving current behavior in future Apache SIS versions.areaOfInterest
- envelope of desired MGRS references.TransformException
- if an error occurred while transforming the area of interest.public AbstractLocation decode(CharSequence reference) throws TransformException
org.opengis.referencing.gazetteer.Location
interface.
This change is pending GeoAPI revision.reference
- MGRS string to decode.TransformException
- if an error occurred while parsing the given string.Copyright © 2010–2017 The Apache Software Foundation. All rights reserved.