use of org.opengis.referencing.operation.CoordinateOperationFactory in project sis by apache.
the class ServicesForMetadata method setGeographicExtent.
/**
* Implementation of the public {@code setBounds(…, DefaultGeographicBoundingBox, …)} methods for
* the horizontal extent. If the {@code crs} argument is null, then it is caller's responsibility
* to ensure that the given envelope is two-dimensional.
*
* @param envelope the source envelope.
* @param target the target bounding box.
* @param crs the envelope CRS, or {@code null} if unknown.
* @param normalizedCRS the horizontal component of the given CRS, or null if the {@code crs} argument is null.
* @throws TransformException if the given envelope can not be transformed.
*/
private void setGeographicExtent(Envelope envelope, final DefaultGeographicBoundingBox target, final CoordinateReferenceSystem crs, final GeographicCRS normalizedCRS) throws TransformException {
if (normalizedCRS != null) {
// No need to check for dimension, since GeodeticCRS can not have less than 2.
final CoordinateSystem cs1 = crs.getCoordinateSystem();
final CoordinateSystem cs2 = normalizedCRS.getCoordinateSystem();
if (!Utilities.equalsIgnoreMetadata(cs2.getAxis(0), cs1.getAxis(0)) || !Utilities.equalsIgnoreMetadata(cs2.getAxis(1), cs1.getAxis(1))) {
final CoordinateOperation operation;
final CoordinateOperationFactory factory = CoordinateOperations.factory();
try {
operation = factory.createOperation(crs, normalizedCRS);
} catch (FactoryException e) {
throw new TransformException(Resources.format(Resources.Keys.CanNotTransformEnvelopeToGeodetic), e);
}
envelope = Envelopes.transform(operation, envelope);
}
}
/*
* At this point, the envelope should use (longitude, latitude) coordinates in degrees.
* However the prime meridian is not necessarily Greenwich.
*/
double westBoundLongitude = envelope.getMinimum(0);
double eastBoundLongitude = envelope.getMaximum(0);
double southBoundLatitude = envelope.getMinimum(1);
double northBoundLatitude = envelope.getMaximum(1);
if (normalizedCRS != null) {
final double rotation = CRS.getGreenwichLongitude(normalizedCRS);
westBoundLongitude += rotation;
eastBoundLongitude += rotation;
}
target.setBounds(westBoundLongitude, eastBoundLongitude, southBoundLatitude, northBoundLatitude);
target.setInclusion(Boolean.TRUE);
}
Aggregations