Transforms this box to the specified CRS and returns a new bounding box for the transformed shape. This method provides a convenient (while not always efficient) way to get {@linkplain #getMinimum minimum} and {@linkplain #getMaximum maximum}ordinate values toward some specific axis directions, typically {@linkplain AxisDirection#EAST East} and {@linkplain AxisDirection#NORTH North}.
Example: if {@code box} is a bounding box using a {@linkplain GeographicCRS geographic CRS} with WGS84 datum, then one can write:
GeographicCRS targetCRS = crsAuthorityFactory. {@linkplain CRSAuthorityFactory#createGeographicCRS createGeographicCRS}("EPSG:4326"); BoundingBox targetBox = box.toBounds(targetCRS); double minEasting = targetBox.getMinY(); double minNorthing = targetBox.getMinX();
Be aware that {@code "EPSG:4326"} has (
latitude,
longitude)axis order, thus the inversion of
X and
Y in the above code.
Sophesticated applications will typically provide more efficient way to perform similar transformations in their context. For example {@linkplain Canvas} storeprecomputed {@linkplain Canvas#getObjectiveToDisplayTransform objective to displaytransforms}.
@param targetCRS The target CRS for the bounding box to be returned.
@return A new bounding box wich includes the shape of this box transformedto the specified target CRS.
@throws TransformException if no transformation path has been found from{@linkplain #getCoordinateReferenceSystem this box CRS} to the specifiedtarget CRS, or if the transformation failed for an other reason.