* @param extent The extent to convert to a geographic bounding box, or {@code null}.
* @return A geographic bounding box extracted from the given extent, or {@code null}
* if the given extent was {@code null}.
*/
public static GeographicBoundingBox getGeographicBoundingBox(final Extent extent) {
GeographicBoundingBox candidate = null;
if (extent != null) {
DefaultGeographicBoundingBox modifiable = null;
for (final GeographicExtent element : extent.getGeographicElements()) {
final GeographicBoundingBox bounds;
if (element instanceof GeographicBoundingBox) {
bounds = (GeographicBoundingBox) element;
} else if (element instanceof BoundingPolygon) {
// TODO: iterates through all polygons and invoke Polygon.getEnvelope();
continue;
} else {
continue;
}
/*
* A single geographic bounding box has been extracted. Now add it to previous
* ones (if any). All exclusion boxes before the first inclusion box are ignored.
*/
if (candidate == null) {
/*
* Reminder: 'inclusion' is a mandatory attribute, so it should never be
* null for a valid metadata object. If the metadata object is invalid,
* it is better to get an exception than having a code doing silently
* some probably inappropriate work.
*/
if (getInclusion(bounds.getInclusion())) {
candidate = bounds;
}
} else {
if (modifiable == null) {
modifiable = new DefaultGeographicBoundingBox();