Skip to content

Commit

Permalink
[GEOS-8072] WMS 1.3.0 capabilities global bounding box computation do…
Browse files Browse the repository at this point in the history
…esn't use layer groups

[GEOS-5176] Namespace filtering on capabilties returns all layer groups (including the ones in other workspaces)
  • Loading branch information
Nuno Oliveira committed Apr 11, 2017
1 parent 997631b commit ac4c06c
Show file tree
Hide file tree
Showing 2 changed files with 302 additions and 30 deletions.
Expand Up @@ -658,13 +658,7 @@ private void handleLayers() {
} }


// filter the layers if a namespace filter has been set // filter the layers if a namespace filter has been set
if (request.getNamespace() != null) { filter = addNameSpaceFilterIfNeed(filter, "resource.namespace.prefix");
//build a query predicate for the namespace prefix
final String nsPrefix = request.getNamespace();
final String nsProp = "resource.namespace.prefix";
Filter equals = equal(nsProp, nsPrefix);
filter = and(filter, equals);
}


final Catalog catalog = wmsConfig.getCatalog(); final Catalog catalog = wmsConfig.getCatalog();


Expand All @@ -682,10 +676,17 @@ private void handleLayers() {
} }
handleRootCrsList(srs); handleRootCrsList(srs);


CloseableIterator<LayerInfo> layers; // create layer groups filter
layers = catalog.list(LayerInfo.class, filter); Filter lgFilter = Predicates.acceptAll();

// filter layer groups by namespace if needed
lgFilter = addNameSpaceFilterIfNeed(lgFilter, "workspace.name");

// handle root bounding box
CloseableIterator<LayerInfo> layers = catalog.list(LayerInfo.class, filter);
CloseableIterator<LayerGroupInfo> layerGroups = catalog.list(LayerGroupInfo.class, lgFilter);
try{ try{
handleRootBbox(layers); handleRootBbox(layers, layerGroups);
}finally{ }finally{
layers.close(); layers.close();
} }
Expand All @@ -699,9 +700,7 @@ private void handleLayers() {
Set<LayerInfo> layersAlreadyProcessed = new HashSet<LayerInfo>(); Set<LayerInfo> layersAlreadyProcessed = new HashSet<LayerInfo>();


// encode layer groups // encode layer groups
CloseableIterator<LayerGroupInfo> layerGroups;
{ {
final Filter lgFilter = Predicates.acceptAll();
SortBy layerGroupOrder = asc("name"); SortBy layerGroupOrder = asc("name");
layerGroups = catalog.list(LayerGroupInfo.class, lgFilter, null, null, layerGroups = catalog.list(LayerGroupInfo.class, lgFilter, null, null,
layerGroupOrder); layerGroupOrder);
Expand All @@ -727,6 +726,21 @@ private void handleLayers() {
end("Layer"); end("Layer");
} }


/**
* If the current request contains a namespace we build a filter using
* the provided property and request namespace and adds it to the provided
* filter. If the request doesn't contain a namespace the original filter
* is returned as is.
*/
private Filter addNameSpaceFilterIfNeed(Filter filter, String nameSpaceProperty) {
String nameSpacePrefix = request.getNamespace();
if (nameSpacePrefix == null) {
return filter;
}
Filter equals = equal(nameSpaceProperty, nameSpacePrefix);
return and(filter, equals);
}

/** /**
* Called by <code>handleLayers()</code>, writes down list of supported CRS's for the root * Called by <code>handleLayers()</code>, writes down list of supported CRS's for the root
* Layer. * Layer.
Expand Down Expand Up @@ -785,32 +799,49 @@ private String qualifySRS(String srs) {
} }


/** /**
* Called by <code>handleLayers()</code>, iterates over the available featuretypes and * Called by <code>handleLayers()</code>, iterates over the available layers and
* coverages to summarize their LatLonBBox'es and write the aggregated bounds for the root * layers groups to summarize their LatLonBBox'es and write the aggregated bounds
* layer. * for the root layer.
* *
* @param ftypes * @param layers available layers iterator
* the collection of FeatureTypeInfo and CoverageInfo objects to traverse * @param layersGroups available layer groups iterator
*/ */
private void handleRootBbox(Iterator<LayerInfo> layers) { private void handleRootBbox(Iterator<LayerInfo> layers, Iterator<LayerGroupInfo> layersGroups) {


final Envelope world = new Envelope(-180, 180, -90, 90); final Envelope world = new Envelope(-180, 180, -90, 90);

Envelope latlonBbox = new Envelope(); Envelope latlonBbox = new Envelope();
Envelope layerBbox = null;


LOGGER.finer("Collecting summarized latlonbbox and common SRS..."); LOGGER.finer("Collecting summarized latlonbbox and common SRS...");


while(layers.hasNext()) { // handle layers
LayerInfo layer = layers.next(); while (layers.hasNext()) {
ResourceInfo resource = layer.getResource(); if (expandEnvelopeToContain(world, latlonBbox,
layerBbox = resource.getLatLonBoundingBox(); layers.next().getResource().getLatLonBoundingBox())) {
if (layerBbox != null) { // our envelope already contains the world
latlonBbox.expandToInclude(layerBbox); break;
} }
}


//short cut for the case where we already reached the whole world bounds // handle layer groups
if(latlonBbox.contains(world)){ while (layersGroups.hasNext()) {
LayerGroupInfo layerGroup = layersGroups.next();
ReferencedEnvelope referencedEnvelope = layerGroup.getBounds();
if (referencedEnvelope == null) {
// no bounds available move on
continue;
}
if (!CRS.equalsIgnoreMetadata(referencedEnvelope, DefaultGeographicCRS.WGS84)) {
try {
// we need to reproject the envelope to lat / lon
referencedEnvelope = referencedEnvelope.transform(DefaultGeographicCRS.WGS84, true);
} catch (Exception exception) {
LOGGER.log(Level.WARNING, String.format(
"Failed to transform layer group '%s' bounds to WGS84.",
layerGroup.getName()), exception);
}
}
if (expandEnvelopeToContain(world, latlonBbox, referencedEnvelope)) {
// our envelope already contains the world
break; break;
} }
} }
Expand All @@ -825,6 +856,17 @@ private void handleRootBbox(Iterator<LayerInfo> layers) {
new ReferencedEnvelope(latlonBbox, DefaultGeographicCRS.WGS84), null, null); new ReferencedEnvelope(latlonBbox, DefaultGeographicCRS.WGS84), null, null);
} }


/**
* Helper method that expand a provided envelope to contain a resource envelope.
* If the extended envelope contains the world envelope TRUE is returned.
*/
private boolean expandEnvelopeToContain(Envelope world, Envelope envelope, Envelope resourceEnvelope) {
if (resourceEnvelope != null) {
envelope.expandToInclude(resourceEnvelope);
}
return envelope.contains(world);
}

private void handleLayerTree(final Iterator<LayerInfo> layers, Set<LayerInfo> layersAlreadyProcessed) { private void handleLayerTree(final Iterator<LayerInfo> layers, Set<LayerInfo> layersAlreadyProcessed) {
// Build a LayerTree only for the layers that have a wms path set. Process the ones that // Build a LayerTree only for the layers that have a wms path set. Process the ones that
// don't first // don't first
Expand Down

0 comments on commit ac4c06c

Please sign in to comment.