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 Rectangle2DThe region for which to return MGRS codes.private final Envelope2DTemporary rectangle for computation purpose.private final booleanWhether this iterator should iterates downward over rows.private final MilitaryGridReferenceSystem.EncoderThe encoder to use for creating MGRS codes.private final org.opengis.referencing.operation.MathTransform2DThe transform from the CRS ofencoderto the CRS ofareaOfInterest.private intPosition of the next MGRS reference to encode.private intPosition of the next MGRS reference to encode.private charLatitude band of the last MGRS reference encoded by the iterator.private final booleanWhether this iterator is allowed to skip some cells when testing for inclusion in the area of interest.private StringA MGRS reference which was pending return bytryAdvance(Consumer)before to continue iteration.private final intThe amount of metres to add togridXand to add or subtract togridYduring iteration.private final intThe easting value of the projection natural origin.private final intThegridXvalue where to stop iteration, exclusive.private intThegridYvalues where to stop iteration, exclusive.private intThe first northing value to use in iteration.Fields inherited from class org.apache.sis.referencing.gazetteer.MilitaryGridReferenceSystem.Coder
buffer, geographic, normalizedFields 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.privateCreates 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 booleanImplementation oftryAdvance(Consumer)andforEachRemaining(Consumer).intSpecifies that the list of elements is immutable, that all elements will be distinct and that this iterator never returnnullelement.longReturns an estimation of the number of cells in the area covered by this iterator.voidforEachRemaining(Consumer<? super String> action) Performs the given action for each remaining MGRS codes.toString()Returns a string representation of this iterator for debugging purpose.booleantryAdvance(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, setSeparatorMethods inherited from class org.apache.sis.referencing.gazetteer.ReferencingByIdentifiers.Coder
recoverableExceptionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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 manyIteratorOneZones. -
gridToAOI
private final org.opengis.referencing.operation.MathTransform2D gridToAOIThe transform from the CRS ofencoderto 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 whethergridXis 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. ThegridYvalue will need to be reset to this value for each new column. -
yEnd
private int yEndThegridYvalues where to stop iteration, exclusive. Invariants:gridY < yEndshall be true in the North hemisphere, andgridY > yEndshall be true in the South hemisphere.
gridYrelationship 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 togridXand to add or subtract togridYduring iteration. The sign to use when updating thegridYvalue 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. SinceIteratorOneZoneiterates 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:
areaOfInterestis a rectangle in geographic coordinates.areaOfInterestdoes 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.geometryin 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 theareaOfInterestrectangle are considered exclusive.For envelopes that cross the anti-meridian, it does not matter if
geographicAreauses 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, theareaOfInterestshould 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 theareaOfInterestCRS.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.FactoryExceptionorg.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 beforeIteratorOneZonecan be used.- Specified by:
trySplitin 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:
estimateSizein 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.Encoderfor creating the MGRS reference.- Specified by:
tryAdvancein interfaceSpliterator<String>
-
forEachRemaining
Performs the given action for each remaining MGRS codes.- Specified by:
forEachRemainingin interfaceSpliterator<String>
-
advance
Implementation oftryAdvance(Consumer)andforEachRemaining(Consumer). Theallargument 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 returnnullelement.- Specified by:
characteristicsin interfaceSpliterator<String>
-
toString
Returns a string representation of this iterator for debugging purpose.
-