// env = layer.getLatLonBoundingBox();
env = layer.getEnvelope(crs);
} else {
GeneralEnvelope layerDefinedEnv = layer.getEnvelope(DefaultGeographicCRS.WGS84);
CRSEnvelope bbox;
String epsg4326 = "EPSG:4326"; //$NON-NLS-1$
String epsg4269 = "EPSG:4269"; //$NON-NLS-1$
if (boundingBoxes.size() < 4) {
// This is a silly heuristic but the idea is that if there are only a few bboxes
// then one of them is likely the *natural* crs and that crs should be used.
bbox = boundingBoxes.values().iterator().next();
} else if (boundingBoxes.containsKey(epsg4326)) {
bbox = boundingBoxes.get(epsg4326);
} else if (boundingBoxes.containsKey(epsg4269)) {
bbox = boundingBoxes.get(epsg4269);
} else {
bbox = boundingBoxes.values().iterator().next();
}
try {
if (bbox.getEPSGCode().equals(epsg4269) || bbox.getEPSGCode().equals(epsg4326)) {
// It is lat long so lets use the layer definition
env = layerDefinedEnv;
crs = DefaultGeographicCRS.WGS84;
} else {
crs = CRS.decode(bbox.getEPSGCode());
env = new ReferencedEnvelope(bbox.getMinX(), bbox.getMaxX(),
bbox.getMinY(), bbox.getMaxY(), crs);
}
} catch (NoSuchAuthorityCodeException e) {
crs = DefaultGeographicCRS.WGS84;
env = layer.getEnvelope(crs);
} catch (FactoryException e) {