if (namespace == null) {
namespace = catalog.getDefaultNamespace();
}
wli.setNamespace(namespace);
Layer layer = wli.getWMSLayer(null);
// try to get the native SRS -> we use the bounding boxes, GeoServer will publish all of the
// supported SRS in the root, if we use getSRS() we'll get them all
for (String srs : layer.getBoundingBoxes().keySet()) {
try {
CoordinateReferenceSystem crs = CRS.decode(srs);
wli.setSRS(srs);
wli.setNativeCRS(crs);
} catch (Exception e) {
LOGGER.log(Level.INFO, "Skipping " + srs
+ " definition, it was not recognized by the referencing subsystem");
}
}
// fall back on WGS84 if necessary, and handle well known WMS CRS codes
String srs = wli.getSRS();
try {
if (srs == null || srs.equals("CRS:84")) {
wli.setSRS("EPSG:4326");
srs = "EPSG:4326";
wli.setNativeCRS(CRS.decode("EPSG:4326"));
} else if(srs.equals("CRS:83")) {
wli.setSRS("EPSG:4269");
srs = "EPSG:4269";
wli.setNativeCRS(CRS.decode("EPSG:4269"));
} else if(srs.equals("CRS:27")) {
wli.setSRS("EPSG:4267");
srs = "EPSG:4267";
wli.setNativeCRS(CRS.decode("EPSG:4267"));
}
} catch(Exception e) {
throw (IOException) new IOException("Failed to compute the layer declared SRS code").initCause(e);
}
wli.setProjectionPolicy(ProjectionPolicy.FORCE_DECLARED);
// try to grab the envelope
GeneralEnvelope envelope = layer.getEnvelope(wli.getNativeCRS());
if (envelope != null) {
ReferencedEnvelope re = new ReferencedEnvelope(envelope.getMinimum(0), envelope
.getMaximum(0), envelope.getMinimum(1), envelope.getMaximum(1), wli
.getNativeCRS());
wli.setNativeBoundingBox(re);
}
CRSEnvelope llbbox = layer.getLatLonBoundingBox();
if (llbbox != null) {
ReferencedEnvelope re = new ReferencedEnvelope(llbbox.getMinX(), llbbox.getMaxX(),
llbbox.getMinY(), llbbox.getMaxY(), DefaultGeographicCRS.WGS84);
wli.setLatLonBoundingBox(re);
} else if (wli.getNativeBoundingBox() != null) {
try {
wli.setLatLonBoundingBox(wli.getNativeBoundingBox().transform(
DefaultGeographicCRS.WGS84, true));
} catch (Exception e) {
LOGGER.log(Level.INFO, "Could not transform native bbox into a lat/lon one", e);
}
}
// reflect all the metadata that we can grab
wli.setAbstract(layer.get_abstract());
wli.setDescription(layer.get_abstract());
wli.setTitle(layer.getTitle());
if (layer.getKeywords() != null) {
for (String kw : layer.getKeywords()) {
if(kw != null){
wli.getKeywords().add(new Keyword(kw));
}
}
}