Skip to content

Commit

Permalink
GEOS-8548: Output bbox on each CRS on LayerGroups too
Browse files Browse the repository at this point in the history
  • Loading branch information
dromagnoli committed Jan 25, 2018
1 parent 66b38ec commit 023c9c6
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,9 @@ protected void handleLayerGroup(LayerGroupInfo layerGroup, Set<LayerInfo> layers
element("CRS", authority);

handleGeographicBoundingBox(latLonBounds);
handleBBox(latLonBounds, "CRS:84");
handleBBox(layerGroupBounds, authority);
handleAdditionalBBox(layerGroupBounds, authority, layerGroup);

if (LayerGroupInfo.Mode.EO.equals(layerGroup.getMode())) {
LayerInfo rootLayer = layerGroup.getRootLayer();
Expand Down Expand Up @@ -1497,7 +1499,7 @@ private void handleBBox(Envelope bbox, String srs) {
element("BoundingBox", null, bboxAtts);
}

private void handleAdditionalBBox(ReferencedEnvelope bbox, String crs, LayerInfo layer) {
private void handleAdditionalBBox(ReferencedEnvelope bbox, String crs, PublishedInfo layer) {
if (serviceInfo.isBBOXForEachCRS() && !serviceInfo.getSRS().isEmpty()) {
//output bounding box for each supported service srs
for (String srs : serviceInfo.getSRS()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,7 @@ protected void handleLayerGroup(LayerGroupInfo layerGroup, Set<LayerInfo> layers

handleLatLonBBox(latLonBounds);
handleBBox(layerGroupBounds, authority);
handleAdditionalBBox(layerGroupBounds, authority, layerGroup);

if (LayerGroupInfo.Mode.EO.equals(layerGroup.getMode())) {
LayerInfo rootLayer = layerGroup.getRootLayer();
Expand Down Expand Up @@ -1425,7 +1426,7 @@ private void handleBBox(Envelope bbox, String SRS) {
element("BoundingBox", null, bboxAtts);
}

private void handleAdditionalBBox(ReferencedEnvelope bbox, String srs, LayerInfo layer) {
private void handleAdditionalBBox(ReferencedEnvelope bbox, String srs, PublishedInfo layer) {
//TODO: this method is copied from wms 1.3 caps (along with a lot of things), we
// should refactor
//WMSInfo info = wmsConfig.getServiceInfo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ public void testGlobalCapabilities() throws Exception {

assertXpathExists("//Layer/Name[text() = 'cite:base']", dom);
assertBounds(cite, "cite:base", dom);

String layer = "base";
assertXpathNotExists("//Layer[Name='" + layer + "']/BoundingBox[@SRS = 'EPSG:3005']", dom);

addSRSAndSetFlag();

dom = getAsDOM("wms?request=getcapabilities&version=1.1.1", true);

assertXpathExists("//Layer[Name='" + layer + "']/BoundingBox[@SRS = 'EPSG:4326']", dom);
assertXpathExists("//Layer[Name='" + layer + "']/BoundingBox[@SRS = 'EPSG:3005']", dom);
}

@Test
Expand Down Expand Up @@ -218,6 +228,15 @@ public void testWorkspaceCapabilities() throws Exception {
assertXpathExists("//Layer/Name[text() = 'base']", dom);
assertXpathNotExists("//Layer/Name[text() = 'sf:base']", dom);
assertBounds(sf, "base", dom);

String layer = "base";
assertXpathNotExists("//Layer[Name='" + layer + "']/BoundingBox[@SRS = 'EPSG:3005']", dom);

addSRSAndSetFlag();
dom = getAsDOM("wms?request=getcapabilities&version=1.1.1", true);

assertXpathExists("//Layer[Name='" + layer + "']/BoundingBox[@SRS = 'EPSG:4326']", dom);
assertXpathExists("//Layer[Name='" + layer + "']/BoundingBox[@SRS = 'EPSG:3005']", dom);
}

@Test
Expand Down Expand Up @@ -375,4 +394,21 @@ void assertBounds(LayerGroupInfo lg, String name, Document dom) throws Exception
assertXpathEvaluatesTo(String.valueOf(Math.round(lg.getBounds().getMaxY())),
"round(//Layer[Name/text() = '"+name+"']/BoundingBox/@maxy)", dom);
}

void addSRSAndSetFlag() {
WMSInfo wms = getWMS().getServiceInfo();
wms.getSRS().add("4326");
wms.getSRS().add("3005");
wms.setBBOXForEachCRS(true);
getGeoServer().save(wms);
}

@After
public void removeSRS() {
WMSInfo wms = getWMS().getServiceInfo();
wms.getSRS().remove("4326");
wms.getSRS().remove("3005");
wms.setBBOXForEachCRS(false);
getGeoServer().save(wms);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@
import static org.custommonkey.xmlunit.XMLAssert.assertXpathExists;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathNotExists;

import java.util.Arrays;

import javax.xml.namespace.QName;

import org.geoserver.catalog.Catalog;
import org.geoserver.catalog.CatalogBuilder;
import org.geoserver.catalog.LayerGroupInfo;
import org.geoserver.catalog.LayerInfo;
import org.geoserver.catalog.LayerGroupInfo.Mode;
import org.geoserver.catalog.LayerInfo;
import org.geoserver.catalog.PublishedInfo;
import org.geoserver.data.test.MockData;
import org.geoserver.wms.WMSInfo;
import org.geoserver.wms.WMSTestSupport;
import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -101,18 +100,28 @@ public void testAddLayerGroup() throws Exception {
catch(Exception e) {}
}

@Test
@Test
public void testGlobalCapabilities() throws Exception {
Document dom = getAsDOM("wms?request=getcapabilities&version=1.3.0");

assertXpathExists("//wms:Layer/wms:Name[text() = 'base']", dom);
assertBounds(global, "base", dom);

assertXpathExists("//wms:Layer/wms:Name[text() = 'sf:base']", dom);
assertBounds(sf, "sf:base", dom);

assertXpathExists("//wms:Layer/wms:Name[text() = 'cite:base']", dom);
assertBounds(cite, "cite:base", dom);

String layer = "base";
assertXpathNotExists("//wms:Layer[wms:Name='" + layer + "']/wms:BoundingBox[@CRS = 'EPSG:3005']", dom);

addSRSAndSetFlag();

dom = getAsDOM("wms?request=getcapabilities&version=1.3.0", true);

assertXpathExists("//wms:Layer[wms:Name='" + layer + "']/wms:BoundingBox[@CRS = 'EPSG:4326']", dom);
assertXpathExists("//wms:Layer[wms:Name='" + layer + "']/wms:BoundingBox[@CRS = 'EPSG:3005']", dom);
}

@Test
Expand Down Expand Up @@ -208,15 +217,23 @@ public void testEoLayerGroupInCapabilities() throws Exception {
assertXpathExists("/wms:WMS_Capabilities/wms:Capability/wms:Layer/wms:Layer[wms:Name[text() = 'base']]/wms:Layer/wms:Name[text() = 'cite:Lakes']", dom);
assertXpathExists("/wms:WMS_Capabilities/wms:Capability/wms:Layer/wms:Layer[wms:Name[text() = 'base']]/wms:Layer/wms:Name[text() = 'cite:Forests']", dom);
}

@Test
public
void testWorkspaceCapabilities() throws Exception {

@Test
public void testWorkspaceCapabilities() throws Exception {
Document dom = getAsDOM("sf/wms?request=getcapabilities&version=1.3.0");

assertXpathExists("//wms:Layer/wms:Name[text() = 'base']", dom);
assertXpathNotExists("//wms:Layer/wms:Name[text() = 'sf:base']", dom);
assertBounds(sf, "base", dom);

String layer = "base";
assertXpathNotExists("//wms:Layer[wms:Name='" + layer + "']/wms:BoundingBox[@CRS = 'EPSG:3005']", dom);

addSRSAndSetFlag();
dom = getAsDOM("wms?request=getcapabilities&version=1.3.0", true);

assertXpathExists("//wms:Layer[wms:Name='" + layer + "']/wms:BoundingBox[@CRS = 'EPSG:4326']", dom);
assertXpathExists("//wms:Layer[wms:Name='" + layer + "']/wms:BoundingBox[@CRS = 'EPSG:3005']", dom);
}

@Test
Expand Down Expand Up @@ -370,8 +387,17 @@ void assertBounds(LayerGroupInfo lg, String name, Document dom) throws Exception
double maxx = lg.getBounds().getMaxX();
double maxy = lg.getBounds().getMaxY();

assertXpathEvaluatesTo(String.valueOf(Math.round(minx)),
"round(//wms:Layer[wms:Name/text() = '" + name + "']/wms:BoundingBox[@CRS = 'CRS:84']/@minx)", dom);
assertXpathEvaluatesTo(String.valueOf(Math.round(maxx)),
"round(//wms:Layer[wms:Name/text() = '" + name + "']/wms:BoundingBox[@CRS = 'CRS:84']/@maxx)", dom);
assertXpathEvaluatesTo(String.valueOf(Math.round(miny)),
"round(//wms:Layer[wms:Name/text() = '" + name + "']/wms:BoundingBox[@CRS = 'CRS:84']/@miny)", dom);
assertXpathEvaluatesTo(String.valueOf(Math.round(maxy)),
"round(//wms:Layer[wms:Name/text() = '" + name + "']/wms:BoundingBox[@CRS = 'CRS:84']/@maxy)", dom);

if (lg.getBounds().getCoordinateReferenceSystem() instanceof GeographicCRS) {
//flip
// flip
double tmp = minx;
minx = miny;
miny = tmp;
Expand All @@ -380,13 +406,32 @@ void assertBounds(LayerGroupInfo lg, String name, Document dom) throws Exception
maxx = maxy;
maxy = tmp;
}
assertXpathEvaluatesTo(String.valueOf(Math.round(minx)),
"round(//wms:Layer[wms:Name/text() = '"+name+"']/wms:BoundingBox/@minx)", dom);
assertXpathEvaluatesTo(String.valueOf(Math.round(maxx)),
"round(//wms:Layer[wms:Name/text() = '"+name+"']/wms:BoundingBox/@maxx)", dom);
assertXpathEvaluatesTo(String.valueOf(Math.round(miny)),
"round(//wms:Layer[wms:Name/text() = '"+name+"']/wms:BoundingBox/@miny)", dom);
assertXpathEvaluatesTo(String.valueOf(Math.round(maxy)),
"round(//wms:Layer[wms:Name/text() = '"+name+"']/wms:BoundingBox/@maxy)", dom);

assertXpathEvaluatesTo(String.valueOf(Math.round(minx)),
"round(//wms:Layer[wms:Name/text() = '" + name + "']/wms:BoundingBox[@CRS = 'EPSG:4326']/@minx)", dom);
assertXpathEvaluatesTo(String.valueOf(Math.round(maxx)),
"round(//wms:Layer[wms:Name/text() = '" + name + "']/wms:BoundingBox[@CRS = 'EPSG:4326']/@maxx)", dom);
assertXpathEvaluatesTo(String.valueOf(Math.round(miny)),
"round(//wms:Layer[wms:Name/text() = '" + name + "']/wms:BoundingBox[@CRS = 'EPSG:4326']/@miny)", dom);
assertXpathEvaluatesTo(String.valueOf(Math.round(maxy)),
"round(//wms:Layer[wms:Name/text() = '" + name + "']/wms:BoundingBox[@CRS = 'EPSG:4326']/@maxy)", dom);

}

void addSRSAndSetFlag() {
WMSInfo wms = getWMS().getServiceInfo();
wms.getSRS().add("4326");
wms.getSRS().add("3005");
wms.setBBOXForEachCRS(true);
getGeoServer().save(wms);
}

@After
public void removeSRS() {
WMSInfo wms = getWMS().getServiceInfo();
wms.getSRS().remove("4326");
wms.getSRS().remove("3005");
wms.setBBOXForEachCRS(false);
getGeoServer().save(wms);
}
}

0 comments on commit 023c9c6

Please sign in to comment.