}
}
} catch (FactoryException e1) {
// could not find a match
}
ReferencedEnvelope extent = null;
Envelope envelope = CRS.getEnvelope(worldCRS);
if( envelope instanceof BoundingBox){
extent = ReferencedEnvelope.reference( (BoundingBox) envelope);
if( extent.getCoordinateReferenceSystem() != worldCRS ){
// CRS.getEnvelope(worldCRS) is inconsistent as it returned an envelope in a different CRS
return null; // give up!
}
}
if (extent == null || extent.isEmpty() || extent.isNull()) {
// fall back to WGS84 bounds and transform to world CRS
GeographicBoundingBox worldBounds = CRS.getGeographicBoundingBox(worldCRS);
if( worldBounds != null ){
ReferencedEnvelope testGeo = new ReferencedEnvelope(worldBounds.getWestBoundLongitude(), worldBounds.getEastBoundLongitude(), worldBounds.getNorthBoundLatitude(), worldBounds.getSouthBoundLatitude(), DefaultGeographicCRS.WGS84);
try {
extent = testGeo.transform(worldCRS, true );
} catch (TransformException e) {
extent = null; // off the map!
} catch (FactoryException e) {
extent = null; // off the map!
}