Class MilitaryGridReferenceSystem.IteratorOneZone
- All Implemented Interfaces:
Spliterator<String>
- Enclosing class:
- MilitaryGridReferenceSystem
IteratorOneZone
instance
for each Universal Polar Stereographic (UPS) or Universal Transverse Mercator (UTM) projection covered by
the area of interest. A given IteratorOneZone
instance use the same projection for all cells.
This class extends MilitaryGridReferenceSystem.Coder
in order to freeze the configuration (separator, precision, etc)
to the values they have at iterator creation time, and because if we parallelize the iteration, each iterator
will need its own MilitaryGridReferenceSystem.Coder.buffer
, MilitaryGridReferenceSystem.Coder.normalized
and MilitaryGridReferenceSystem.Coder.geographic
cache.
-
Nested Class Summary
Nested classes/interfaces inherited from interface java.util.Spliterator
Spliterator.OfDouble, Spliterator.OfInt, Spliterator.OfLong, Spliterator.OfPrimitive<T extends Object,
T_CONS extends Object, T_SPLITR extends Spliterator.OfPrimitive<T, T_CONS, T_SPLITR>> -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Rectangle2D
The region for which to return MGRS codes.private final Envelope2D
Temporary rectangle for computation purpose.private final boolean
Whether this iterator should iterates downward over rows.private final MilitaryGridReferenceSystem.Encoder
The encoder to use for creating MGRS codes.private final org.opengis.referencing.operation.MathTransform2D
The transform from the CRS ofencoder
to the CRS ofareaOfInterest
.private int
Position of the next MGRS reference to encode.private int
Position of the next MGRS reference to encode.private char
Latitude band of the last MGRS reference encoded by the iterator.private final boolean
Whether this iterator is allowed to skip some cells when testing for inclusion in the area of interest.private String
A MGRS reference which was pending return bytryAdvance(Consumer)
before to continue iteration.private final int
The amount of metres to add togridX
and to add or subtract togridY
during iteration.private final int
The easting value of the projection natural origin.private final int
ThegridX
value where to stop iteration, exclusive.private int
ThegridY
values where to stop iteration, exclusive.private int
The first northing value to use in iteration.Fields inherited from class org.apache.sis.referencing.gazetteer.MilitaryGridReferenceSystem.Coder
buffer, geographic, normalized
Fields inherited from interface java.util.Spliterator
CONCURRENT, DISTINCT, IMMUTABLE, NONNULL, ORDERED, SIZED, SORTED, SUBSIZED
-
Constructor Summary
ConstructorsModifierConstructorDescription(package private)
IteratorOneZone
(MilitaryGridReferenceSystem.Coder coder, Rectangle2D areaOfInterest, org.opengis.geometry.Envelope geographicArea, org.opengis.referencing.crs.SingleCRS sourceCRS, org.opengis.referencing.crs.ProjectedCRS targetCRS, int step) Returns a new iterator for creating MGRS codes in a single UTM or UPS zone.private
Creates an iterator for the lower half of a Universal Polar Stereographic (UPS) projection, and modifies the given iterator for restricting it to the upper half of UPS projection. -
Method Summary
Modifier and TypeMethodDescriptionprivate boolean
Implementation oftryAdvance(Consumer)
andforEachRemaining(Consumer)
.int
Specifies that the list of elements is immutable, that all elements will be distinct and that this iterator never returnnull
element.long
Returns an estimation of the number of cells in the area covered by this iterator.void
forEachRemaining
(Consumer<? super String> action) Performs the given action for each remaining MGRS codes.toString()
Returns a string representation of this iterator for debugging purpose.boolean
tryAdvance
(Consumer<? super String> action) Computes the next cell reference, if any.trySplit()
If this iterator intersects both the upper and lower half on UPS domain, returns an iterator for the lower half and modifies this iterator for the upper half.Methods inherited from class org.apache.sis.referencing.gazetteer.MilitaryGridReferenceSystem.Coder
decode, digits, encode, encode, encode, encode, encoder, getClipToValidArea, getEllipsoid, getPrecision, getPrecision, getReferenceSystem, getSeparator, projection, setClipToValidArea, setPrecision, setPrecision, setSeparator
Methods inherited from class org.apache.sis.referencing.gazetteer.ReferencingByIdentifiers.Coder
recoverableException
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Spliterator
getComparator, getExactSizeIfKnown, hasCharacteristics
-
Field Details
-
areaOfInterest
The region for which to return MGRS codes. This envelope can be in any CRS. This shape shall not be modified since the same instance will be shared by manyIteratorOneZone
s. -
gridToAOI
private final org.opengis.referencing.operation.MathTransform2D gridToAOIThe transform from the CRS ofencoder
to the CRS ofareaOfInterest
. -
encoder
The encoder to use for creating MGRS codes. -
xCenter
private final int xCenterThe easting value of the projection natural origin. This information is used for determining whethergridX
is on the left side or on right side of the center of UPS or UTM zone. We use this information for choosing the cell corner which is closest to map projection origin. -
xEnd
private final int xEnd -
yStart
private int yStartThe first northing value to use in iteration. ThegridY
value will need to be reset to this value for each new column. -
yEnd
private int yEndThegridY
values where to stop iteration, exclusive. Invariants:gridY < yEnd
shall be true in the North hemisphere, andgridY > yEnd
shall be true in the South hemisphere.
gridY
relationship dependency to the hemisphere is because we try to iterate from equator to the pole. -
gridX
private int gridXPosition of the next MGRS reference to encode. Position is composed of the latitude band number, the row and column indices of current 100 km square, and finally the grid coordinates inside the current 100 km square. All those components are inferred from the (easting, northing) values. -
gridY
private int gridYPosition of the next MGRS reference to encode. Position is composed of the latitude band number, the row and column indices of current 100 km square, and finally the grid coordinates inside the current 100 km square. All those components are inferred from the (easting, northing) values. -
step
private final int stepThe amount of metres to add togridX
and to add or subtract togridY
during iteration. The sign to use when updating thegridY
value depends on whether we are in the North or South hemisphere. -
downward
private final boolean downward -
optimize
private final boolean optimizeWhether this iterator is allowed to skip some cells when testing for inclusion in the area of interest. SinceIteratorOneZone
iterates in UTM zone from equator to pole, the range of longitude values will only decrease (the minimal longitude increase and the maximal longitude decrease). Consequently if we found a longitude out of range, we don't need to test that longitude again in next row.This optimization is allowed only under the following conditions:
areaOfInterest
is a rectangle in geographic coordinates.areaOfInterest
does not intersect Norway and Svalbard special cases.- We iterate in a UTM zone, or in a UPS zone contained fully in the upper half or fully in lower half.
-
latitudeBand
private char latitudeBandLatitude band of the last MGRS reference encoded by the iterator. This information is used for detecting when we moved to a new latitude band. -
pending
A MGRS reference which was pending return bytryAdvance(Consumer)
before to continue iteration. This field may be non-null immediately after a change of latitude band, and should be null otherwise. -
cell
Temporary rectangle for computation purpose. Needs to be an implementation from theorg.apache.sis.geometry
in order to support AOI crossing the anti-meridian.
-
-
Constructor Details
-
IteratorOneZone
IteratorOneZone(MilitaryGridReferenceSystem.Coder coder, Rectangle2D areaOfInterest, org.opengis.geometry.Envelope geographicArea, org.opengis.referencing.crs.SingleCRS sourceCRS, org.opengis.referencing.crs.ProjectedCRS targetCRS, int step) throws org.opengis.util.FactoryException, org.opengis.referencing.operation.TransformException Returns a new iterator for creating MGRS codes in a single UTM or UPS zone. The borders of theareaOfInterest
rectangle are considered exclusive.For envelopes that cross the anti-meridian, it does not matter if
geographicArea
uses the negative width convention or is expanded to the [-180 … 180]° of longitude range, because it will be clipped to the projection domain of validity anyway. However, theareaOfInterest
should use the negative width convention.- Parameters:
areaOfInterest
- the envelope for which to return MGRS codes. This envelope can be in any CRS.geographicArea
- the area of interest transformed into a normalized geographic CRS.sourceCRS
- the horizontal part of theareaOfInterest
CRS.targetCRS
- the UTM or UPS projected CRS of the zone for which to create MGRS references.step
- the amount of metres to add or subtract to grid coordinates during iteration.- Throws:
org.opengis.util.FactoryException
org.opengis.referencing.operation.TransformException
-
IteratorOneZone
Creates an iterator for the lower half of a Universal Polar Stereographic (UPS) projection, and modifies the given iterator for restricting it to the upper half of UPS projection. This method is fortrySplit()
usage only.
-
-
Method Details
-
trySplit
If this iterator intersects both the upper and lower half on UPS domain, returns an iterator for the lower half and modifies this iterator for the upper half. This method must be invoked beforeIteratorOneZone
can be used.- Specified by:
trySplit
in interfaceSpliterator<String>
-
estimateSize
public long estimateSize()Returns an estimation of the number of cells in the area covered by this iterator. The returned value may be greater than the real amount since we do not take in account the fact that the number of cells in a row become lower as we approach poles.Note: returned value should be the number of remaining elements, but current implementation does not compute how many elements we have already traversed.
- Specified by:
estimateSize
in interfaceSpliterator<String>
-
tryAdvance
Computes the next cell reference, if any. This method computes the bounding box in UPS or UTM coordinates, verifies if that box intersects the area of interest, and (if it intersects) delegates toMilitaryGridReferenceSystem.Encoder
for creating the MGRS reference.- Specified by:
tryAdvance
in interfaceSpliterator<String>
-
forEachRemaining
Performs the given action for each remaining MGRS codes.- Specified by:
forEachRemaining
in interfaceSpliterator<String>
-
advance
Implementation oftryAdvance(Consumer)
andforEachRemaining(Consumer)
. Theall
argument specifies whether this method is invoked for a single element or for all remaining ones. -
characteristics
public int characteristics()Specifies that the list of elements is immutable, that all elements will be distinct and that this iterator never returnnull
element.- Specified by:
characteristics
in interfaceSpliterator<String>
-
toString
Returns a string representation of this iterator for debugging purpose.
-