// see section 7.6.2 of the WCS 1.1.1 spec)
List<Double> lower = bbox.getLowerCorner();
List<Double> upper = bbox.getUpperCorner();
for (int i = 0; i < lower.size(); i++) {
if (lower.get(i) > upper.get(i)) {
final CoordinateSystemAxis axis = bboxCRs.getCoordinateSystem().getAxis(i);
// see if the coordinates can be fixed
if (bboxCRs instanceof GeographicCRS && axis.getDirection() == AxisDirection.EAST) {
if (gridEnvelopeBboxCRS != null) {
// try to guess which one needs to be fixed
final double envMax = gridEnvelopeBboxCRS.getMaximum(i);
if (envMax >= lower.get(i))
upper.set(i, upper.get(i) + (axis.getMaximumValue() - axis.getMinimumValue()));
else
lower.set(i, lower.get(i) - (axis.getMaximumValue() - axis.getMinimumValue()));
} else {
// just fix the upper and hope...
upper.set(i, upper.get(i) + (axis.getMaximumValue() - axis.getMinimumValue()));
}
}
// if even after the fix we're in the wrong situation, complain
if (lower.get(i) > upper.get(i)) {