Class Envelope2D
- All Implemented Interfaces:
- Shape,- Serializable,- Cloneable,- Emptiable,- Envelope
This class inherits x and y fields. But despite their names, they don't need to be oriented toward East and North respectively. The (x,y) axis can have any direction and should be understood as coordinate 0 and coordinate 1 values instead. This is not specific to this implementation; in Java2D too, the visual axis orientation depend on the affine transform in the graphics context.
Crossing the anti-meridian of a Geographic CRS
The Web Coverage Service (WCS) specification authorizes (with special treatment) cases where upper < lower at least in the longitude case. They are envelopes crossing the anti-meridian, like the red box below (the green box is the usual case). ForEnvelope2D objects, they are rectangle with negative width or
 height field values. The default implementation of methods listed in the
 right column can handle such cases.
  
 - getMinimum(int)
- getMaximum(int)
- getSpan(int)
- getMedian(int)
- isEmpty()
- toRectangles()
- contains(double,double)
- contains(Rectangle2D)and its variant receiving- doublearguments
- intersects(Rectangle2D)and its variant receiving- doublearguments
- createIntersection(Rectangle2D)
- createUnion(Rectangle2D)
- add(Rectangle2D)
- add(double,double)
getMinX(), getMinY(), getMaxX(), getMaxY(),
 getCenterX(), getCenterY(), getWidth() and getHeight()
 methods delegate to the above-cited methods.- Since:
- 0.3
- See Also:
Defined in the sis-referencing module
- 
Nested Class SummaryNested classes/interfaces inherited from class Rectangle2DRectangle2D.Double, Rectangle2D.Float
- 
Field SummaryFields inherited from class Rectangle2D.Doubleheight, width, x, yFields inherited from class Rectangle2DOUT_BOTTOM, OUT_LEFT, OUT_RIGHT, OUT_TOP
- 
Constructor SummaryConstructorsConstructorDescriptionConstructs an initially empty envelope with no CRS.Envelope2D(DirectPosition lowerCorner, DirectPosition upperCorner) Constructs a two-dimensional envelope defined by the specified coordinates.Envelope2D(Envelope envelope) Constructs a two-dimensional envelope defined by anotherEnvelope.Constructs a new envelope with the same data than the specified geographic bounding box.Envelope2D(CoordinateReferenceSystem crs, double x, double y, double width, double height) Constructs two-dimensional envelope defined by the specified coordinates.Envelope2D(CoordinateReferenceSystem crs, Rectangle2D rect) Constructs two-dimensional envelope defined by anotherRectangle2D.
- 
Method SummaryModifier and TypeMethodDescriptionvoidadd(double px, double py) Adds a point to this rectangle.voidadd(Rectangle2D rect) Adds another rectangle to this rectangle.booleanboundsEquals(Envelope that, int xDim, int yDim, double eps) Returnstrueifthisenvelope bounds is equal tothatenvelope bounds in two specified dimensions.clone()Returns a clone of this envelope.booleancontains(double px, double py) Tests if a specified coordinate is inside the boundary of this envelope.booleancontains(double rx, double ry, double rw, double rh) Returnstrueif this envelope completely encloses the specified rectangle.booleancontains(Rectangle2D rect) Returnstrueif this envelope completely encloses the specified rectangle.Returns the intersection of this envelope with the specified rectangle.createUnion(Rectangle2D rect) Returns the union of this envelope with the specified rectangle.booleanCompares the specified object with this envelope for equality.doubleReturns the median coordinate value for dimension 0.doubleReturns the median coordinate value for dimension 1.Returns the coordinate reference system in which the coordinates are given.final intReturns the number of dimensions, which is always 2.doubleReturns the span for dimension 1.The limits in the direction of decreasing coordinate values for the two dimensions.doublegetMaximum(int dimension) Returns the maximal coordinate along the specified dimension.doubleReturns the maximal coordinate value for dimension 0.doubleReturns the maximal coordinate value for dimension 1.A coordinate position consisting of all the median coordinate values.doublegetMedian(int dimension) Returns the median coordinate along the specified dimension.doublegetMinimum(int dimension) Returns the minimal coordinate along the specified dimension.doubleReturns the minimal coordinate value for dimension 0.doubleReturns the minimal coordinate value for dimension 1.doublegetSpan(int dimension) Returns the envelope span along the specified dimension.The limits in the direction of increasing coordinate values for the two dimensions.doubleReturns the span for dimension 0.booleanintersects(double rx, double ry, double rw, double rh) Returnstrueif this envelope intersects the specified envelope.booleanintersects(Rectangle2D rect) Returnstrueif this envelope intersects the specified envelope.booleanisEmpty()Determines whether the envelope is empty.voidSets the coordinate reference system in which the coordinate are given.voidsetRect(Rectangle2D rect) Sets this envelope to the given rectangle.Returns this envelope as non-empty Java2D rectangle objects.Formats this envelope as a "BOX" element.Methods inherited from class Rectangle2D.DoublegetBounds2D, getX, getY, outcode, setRectMethods inherited from class Rectangle2Dadd, getPathIterator, getPathIterator, hashCode, intersect, intersectsLine, intersectsLine, outcode, setFrame, unionMethods inherited from class RectangularShapecontains, getBounds, getFrame, setFrame, setFrame, setFrameFromCenter, setFrameFromCenter, setFrameFromDiagonal, setFrameFromDiagonal
- 
Constructor Details- 
Envelope2Dpublic Envelope2D()Constructs an initially empty envelope with no CRS.
- 
Envelope2Dpublic Envelope2D(DirectPosition lowerCorner, DirectPosition upperCorner) throws MismatchedReferenceSystemException, MismatchedDimensionException Constructs a two-dimensional envelope defined by the specified coordinates. ThelowerCornerandupperCornerarguments are not necessarily the minimal and maximal values respectively. See the class javadoc about crossing the anti-meridian for more details.- Parameters:
- lowerCorner- the first position.
- upperCorner- the second position.
- Throws:
- MismatchedReferenceSystemException- if the two positions don't use the same CRS.
- MismatchedDimensionException- if the two positions are not two-dimensional.
 
- 
Envelope2DConstructs a two-dimensional envelope defined by anotherEnvelope.- Parameters:
- envelope- the envelope to copy (cannot be- null).
- Throws:
- MismatchedDimensionException- if the given envelope is not two-dimensional.
 
- 
Envelope2DConstructs a new envelope with the same data than the specified geographic bounding box. The coordinate reference system is set to the default geographic CRS. Axis order is (longitude, latitude).- Parameters:
- box- The bounding box to copy (cannot be- null).
 
- 
Envelope2Dpublic Envelope2D(CoordinateReferenceSystem crs, Rectangle2D rect) throws MismatchedDimensionException Constructs two-dimensional envelope defined by anotherRectangle2D. If the given rectangle has negative width or height, they will be interpreted as an envelope crossing the anti-meridian.- Parameters:
- crs- the coordinate reference system, or- null.
- rect- the rectangle to copy (cannot be- null).
- Throws:
- MismatchedDimensionException- if the given CRS is not two-dimensional.
 
- 
Envelope2Dpublic Envelope2D(CoordinateReferenceSystem crs, double x, double y, double width, double height) throws MismatchedDimensionException Constructs two-dimensional envelope defined by the specified coordinates. Despite their name, the (x,y) coordinates don't need to be oriented toward (East, North). Those parameter names simply match the x and y fields. The actual axis orientations are determined by the specified CRS. See the class javadoc for details.- Parameters:
- crs- the coordinate reference system, or- null.
- x- the x minimal value.
- y- the y minimal value.
- width- the envelope width. May be negative for envelope crossing the anti-meridian.
- height- the envelope height. May be negative for envelope crossing the anti-meridian.
- Throws:
- MismatchedDimensionException- if the given CRS is not two-dimensional.
 
 
- 
- 
Method Details- 
getCoordinateReferenceSystemReturns the coordinate reference system in which the coordinates are given.- Specified by:
- getCoordinateReferenceSystemin interface- Envelope
- Returns:
- the coordinate reference system, or null.
 
- 
setCoordinateReferenceSystemSets the coordinate reference system in which the coordinate are given. This method does not reproject the envelope. If the envelope coordinates need to be transformed to the new CRS, consider usingEnvelopes.transform(Envelope, CoordinateReferenceSystem)instead.- Parameters:
- crs- the new coordinate reference system, or- null.
 
- 
setRectSets this envelope to the given rectangle. If the given rectangle is also an instance ofEnvelope(typically as anotherEnvelope2D) and has a non-null Coordinate Reference System (CRS), then the CRS of this envelope will be set to the CRS of the given envelope.- Overrides:
- setRectin class- Rectangle2D.Double
- Parameters:
- rect- the rectangle to copy coordinates from.
- Since:
- 0.8
 
- 
getDimensionpublic final int getDimension()Returns the number of dimensions, which is always 2.- Specified by:
- getDimensionin interface- Envelope
- Returns:
- always 2 for bi-dimensional objects.
 
- 
getLowerCornerThe limits in the direction of decreasing coordinate values for the two dimensions. This is typically a coordinate position consisting of the minimal coordinates for the two dimensions for all points within theEnvelope.The object returned by this method is a copy. Change in the returned position will not affect this envelope, and conversely. Note: The Web Coverage Service (WCS) 1.1 specification uses an extended interpretation of the bounding box definition. In a WCS 1.1 data structure, the lower corner defines the edges region in the directions of decreasing coordinate values in the envelope CRS. This is usually the algebraic minimum coordinates, but not always. For example, an envelope crossing the anti-meridian could have a lower corner longitude greater than the upper corner longitude. Such extended interpretation applies mostly to axes havingWRAPAROUNDrange meaning.- Specified by:
- getLowerCornerin interface- Envelope
- Returns:
- a copy of the lower corner, typically (but not necessarily) containing minimal coordinate values.
- See Also:
 
- 
getUpperCornerThe limits in the direction of increasing coordinate values for the two dimensions. This is typically a coordinate position consisting of the maximal coordinates for the two dimensions for all points within theEnvelope.The object returned by this method is a copy. Change in the returned position will not affect this envelope, and conversely. Note: The Web Coverage Service (WCS) 1.1 specification uses an extended interpretation of the bounding box definition. In a WCS 1.1 data structure, the upper corner defines the edges region in the directions of increasing coordinate values in the envelope CRS. This is usually the algebraic maximum coordinates, but not always. For example, an envelope crossing the anti-meridian could have an upper corner longitude less than the lower corner longitude. Such extended interpretation applies mostly to axes havingWRAPAROUNDrange meaning.- Specified by:
- getUpperCornerin interface- Envelope
- Returns:
- a copy of the upper corner, typically (but not necessarily) containing maximal coordinate values.
- See Also:
 
- 
getMedianA coordinate position consisting of all the median coordinate values.The object returned by this method is a copy. Change in the returned position will not affect this envelope, and conversely. - Returns:
- a copy of the median coordinates.
- Since:
- 1.1
- See Also:
 
- 
getMinimumReturns the minimal coordinate along the specified dimension. This method handles anti-meridian as documented in theAbstractEnvelope.getMinimum(int)method.- Specified by:
- getMinimumin interface- Envelope
- Parameters:
- dimension- the dimension to query.
- Returns:
- the minimal coordinate value along the given dimension.
- Throws:
- IndexOutOfBoundsException- if the given index is out of bounds.
 
- 
getMaximumReturns the maximal coordinate along the specified dimension. This method handles anti-meridian as documented in theAbstractEnvelope.getMaximum(int)method.- Specified by:
- getMaximumin interface- Envelope
- Parameters:
- dimension- the dimension to query.
- Returns:
- the maximal coordinate value along the given dimension.
- Throws:
- IndexOutOfBoundsException- if the given index is out of bounds.
 
- 
getMedianReturns the median coordinate along the specified dimension. This method handles anti-meridian as documented in theAbstractEnvelope.getMedian(int)method.- Specified by:
- getMedianin interface- Envelope
- Parameters:
- dimension- the dimension to query.
- Returns:
- the mid coordinate value along the given dimension.
- Throws:
- IndexOutOfBoundsException- if the given index is out of bounds.
- See Also:
 
- 
getSpanReturns the envelope span along the specified dimension. This method handles anti-meridian as documented in theAbstractEnvelope.getSpan(int)method.- Specified by:
- getSpanin interface- Envelope
- Parameters:
- dimension- the dimension to query.
- Returns:
- the rectangle width or height, depending the given dimension.
- Throws:
- IndexOutOfBoundsException- if the given index is out of bounds.
 
- 
getMinXpublic double getMinX()Returns the minimal coordinate value for dimension 0. The default implementation invokesgetMinimum(0). The result is the standardRectangle2Dvalue (namely x) only if the envelope is not crossing the anti-meridian.- Overrides:
- getMinXin class- RectangularShape
- Returns:
- the minimal coordinate value for dimension 0.
 
- 
getMinYpublic double getMinY()Returns the minimal coordinate value for dimension 1. The default implementation invokesgetMinimum(1). The result is the standardRectangle2Dvalue (namely y) only if the envelope is not crossing the anti-meridian.- Overrides:
- getMinYin class- RectangularShape
- Returns:
- the minimal coordinate value for dimension 1.
 
- 
getMaxXpublic double getMaxX()Returns the maximal coordinate value for dimension 0. The default implementation invokesgetMinimum(0). The result is the standardRectangle2Dvalue (namely x + width) only if the envelope is not crossing the anti-meridian.- Overrides:
- getMaxXin class- RectangularShape
- Returns:
- the maximal coordinate value for dimension 0.
 
- 
getMaxYpublic double getMaxY()Returns the maximal coordinate value for dimension 1. The default implementation invokesgetMinimum(1). The result is the standardRectangle2Dvalue (namely y + height) only if the envelope is not crossing the anti-meridian.- Overrides:
- getMaxYin class- RectangularShape
- Returns:
- the maximal coordinate value for dimension 1.
 
- 
getCenterXpublic double getCenterX()Returns the median coordinate value for dimension 0. The default implementation invokesgetMedian(0). The result is the standardRectangle2Dvalue (namely x + width/2) only if the envelope is not crossing the anti-meridian.- Overrides:
- getCenterXin class- RectangularShape
- Returns:
- the median coordinate value for dimension 0.
 
- 
getCenterYpublic double getCenterY()Returns the median coordinate value for dimension 1. The default implementation invokesgetMedian(1). The result is the standardRectangle2Dvalue (namely y + height/2) only if the envelope is not crossing the anti-meridian.- Overrides:
- getCenterYin class- RectangularShape
- Returns:
- the median coordinate value for dimension 1.
 
- 
getWidthpublic double getWidth()Returns the span for dimension 0. The default implementation invokesgetSpan(0). The result is the standardRectangle2Dvalue (namely width) only if the envelope is not crossing the anti-meridian.- Overrides:
- getWidthin class- Rectangle2D.Double
- Returns:
- the span for dimension 0.
 
- 
getHeightpublic double getHeight()Returns the span for dimension 1. The default implementation invokesgetSpan(1). The result is the standardRectangle2Dvalue (namely height) only if the envelope is not crossing the anti-meridian.- Overrides:
- getHeightin class- Rectangle2D.Double
- Returns:
- the span for dimension 1.
 
- 
isEmptypublic boolean isEmpty()Determines whether the envelope is empty. A negative Rectangle2D.Double.width or (@linkplain #height} is considered as a non-empty area if the corresponding axis has the wraparound range meaning.Note that if the Rectangle2D.Double.width or Rectangle2D.Double.height value is NaN, then the envelope is considered empty. This is different than the defaultRectangle2D.Double.isEmpty()implementation, which doesn't check forNaNvalues.- Specified by:
- isEmptyin interface- Emptiable
- Overrides:
- isEmptyin class- Rectangle2D.Double
- Returns:
- trueif this envelope is empty.
 
- 
toRectanglesReturns this envelope as non-empty Java2D rectangle objects. This method returns an array of length 0, 1, 2 or 4 depending on whether the envelope crosses the anti-meridian or the limit of any other axis having wraparound range meaning. More specifically:- If this envelope is empty, then this method returns an empty array.
- If this envelope does not have any wraparound behavior, then this method returns a copy
       of this envelope as an instance of Rectangle2D.Doublein an array of length 1.
- If this envelope crosses the anti-meridian (a.k.a. date line) then this method represents this envelope as two separated rectangles.
- While uncommon, the envelope could theoretically crosses the limit of other axis having wraparound range meaning. If wraparound occur along the two axes, then this method represents this envelope as four separated rectangles.
 API note: The return type is theRectangle2D.Doubleimplementation class rather than theRectangle2Dabstract class because theEnvelope2Dclass hierarchy already exposes this implementation choice.- Returns:
- a representation of this envelope as an array of non-empty Java2D rectangles.
         The array never contains this.
- Since:
- 0.4
- See Also:
 
- 
containspublic boolean contains(double px, double py) Tests if a specified coordinate is inside the boundary of this envelope. If it least one of the given coordinate value isNaN, then this method returnsfalse.Crossing the anti-meridian of a Geographic CRSThis method supports anti-meridian in the same way thanAbstractEnvelope.contains(DirectPosition).- Specified by:
- containsin interface- Shape
- Overrides:
- containsin class- Rectangle2D
- Parameters:
- px- the first coordinate value of the point to text.
- py- the second coordinate value of the point to text.
- Returns:
- trueif the specified coordinate is inside the boundary of this envelope;- falseotherwise.
 
- 
containsReturnstrueif this envelope completely encloses the specified rectangle. If this envelope or the given rectangle have at least oneNaNvalue, then this method returnsfalse.Crossing the anti-meridian of a Geographic CRSThis method supports anti-meridian in the same way thanAbstractEnvelope.contains(Envelope).- Specified by:
- containsin interface- Shape
- Overrides:
- containsin class- RectangularShape
- Parameters:
- rect- the rectangle to test for inclusion.
- Returns:
- trueif this envelope completely encloses the specified rectangle.
 
- 
containspublic boolean contains(double rx, double ry, double rw, double rh) Returnstrueif this envelope completely encloses the specified rectangle. If this envelope or the given rectangle have at least oneNaNvalue, then this method returnsfalse.Crossing the anti-meridian of a Geographic CRSThis method supports anti-meridian in the same way thanAbstractEnvelope.contains(Envelope).- Specified by:
- containsin interface- Shape
- Overrides:
- containsin class- Rectangle2D
- Parameters:
- rx- the x coordinate of the lower corner of the rectangle to test for inclusion.
- ry- the y coordinate of the lower corner of the rectangle to test for inclusion.
- rw- the width of the rectangle to test for inclusion. May be negative if the rectangle spans the anti-meridian.
- rh- the height of the rectangle to test for inclusion. May be negative.
- Returns:
- trueif this envelope completely encloses the specified one.
 
- 
intersectsReturnstrueif this envelope intersects the specified envelope. If this envelope or the given rectangle have at least oneNaNvalue, then this method returnsfalse.Crossing the anti-meridian of a Geographic CRSThis method supports anti-meridian in the same way thanAbstractEnvelope.intersects(Envelope).- Specified by:
- intersectsin interface- Shape
- Overrides:
- intersectsin class- RectangularShape
- Parameters:
- rect- the rectangle to test for intersection.
- Returns:
- trueif this envelope intersects the specified rectangle.
 
- 
intersectspublic boolean intersects(double rx, double ry, double rw, double rh) Returnstrueif this envelope intersects the specified envelope. If this envelope or the given rectangle have at least oneNaNvalue, then this method returnsfalse.Crossing the anti-meridian of a Geographic CRSThis method supports anti-meridian in the same way thanAbstractEnvelope.intersects(Envelope).- Specified by:
- intersectsin interface- Shape
- Overrides:
- intersectsin class- Rectangle2D
- Parameters:
- rx- the x coordinate of the lower corner of the rectangle to test for intersection.
- ry- the y coordinate of the lower corner of the rectangle to test for intersection.
- rw- the width of the rectangle to test for inclusion. May be negative if the rectangle spans the anti-meridian.
- rh- the height of the rectangle to test for inclusion. May be negative.
- Returns:
- trueif this envelope intersects the specified rectangle.
 
- 
createIntersectionReturns the intersection of this envelope with the specified rectangle. If this envelope or the given rectangle have at least oneNaNvalues, then this method returns an empty envelope.Crossing the anti-meridian of a Geographic CRSThis method supports anti-meridian in the same way thanGeneralEnvelope.intersect(Envelope).- Overrides:
- createIntersectionin class- Rectangle2D.Double
- Parameters:
- rect- the rectangle to be intersected with this envelope.
- Returns:
- the intersection of the given rectangle with this envelope.
 
- 
createUnionReturns the union of this envelope with the specified rectangle. The default implementation clones this envelope, then delegates toadd(Rectangle2D).- Overrides:
- createUnionin class- Rectangle2D.Double
- Parameters:
- rect- the rectangle to add to this envelope.
- Returns:
- the union of the given rectangle with this envelope.
 
- 
addAdds another rectangle to this rectangle. The resulting rectangle is the union of the twoRectangleobjects.Crossing the anti-meridian of a Geographic CRSThis method supports anti-meridian in the same way thanGeneralEnvelope.add(Envelope), except if the result is a rectangle expanding to infinities. In that later case, the field values are set toNaNbecause infinite values are a problematic inRectangle2Dobjects.- Overrides:
- addin class- Rectangle2D
- Parameters:
- rect- the rectangle to add to this envelope.
 
- 
addpublic void add(double px, double py) Adds a point to this rectangle. The resulting rectangle is the smallest rectangle that contains both the original rectangle and the specified point.After adding a point, a call to contains(double, double)with the added point as an argument will returntrue, except if one of the point coordinates wasDouble.NaNin which case the corresponding coordinate has been ignored.Crossing the anti-meridian of a Geographic CRSThis method supports anti-meridian in the same way thanGeneralEnvelope.add(DirectPosition).- Overrides:
- addin class- Rectangle2D
- Parameters:
- px- the first coordinate of the point to add.
- py- the second coordinate of the point to add.
 
- 
equalsCompares the specified object with this envelope for equality. If the given object is not an instance ofEnvelope2D, then the two objects are compared as plain rectangles, i.e. the coordinate reference system of this envelope is ignored.Note onThis class does not override thehashCode()Rectangle2D.hashCode()method for consistency with theRectangle2D.equals(Object)method, which compare arbitraryRectangle2Dimplementations.- Overrides:
- equalsin class- Rectangle2D
- Parameters:
- object- the object to compare with this envelope.
- Returns:
- trueif the given object is equal to this envelope.
 
- 
boundsEqualsReturnstrueifthisenvelope bounds is equal tothatenvelope bounds in two specified dimensions. The coordinate reference system is not compared, since it doesn't need to have the same number of dimensions.- Parameters:
- that- the envelope to compare to.
- xDim- the dimension of- thatenvelope to compare to the x dimension of- thisenvelope.
- yDim- the dimension of- thatenvelope to compare to the y dimension of- thisenvelope.
- eps- a small tolerance number for floating point number comparisons. This value will be scaled according this envelope width and height.
- Returns:
- trueif the envelope bounds are the same (up to the specified tolerance level) in the specified dimensions, or- falseotherwise.
 
- 
cloneReturns a clone of this envelope.- Overrides:
- clonein class- RectangularShape
- Returns:
- a clone of this envelope.
 
- 
toStringFormats this envelope as a "BOX" element. The output is of the form "BOX(lower corner,upper corner)". Example:BOX(-90 -180, 90 180) - Overrides:
- toStringin class- Rectangle2D.Double
- See Also:
 
 
-