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 Original file line Diff line number Diff line change
Expand Up @@ -1212,7 +1212,9 @@ protected void handleLayerGroup(LayerGroupInfo layerGroup, Set<LayerInfo> layers
element("CRS", authority); element("CRS", authority);


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


if (LayerGroupInfo.Mode.EO.equals(layerGroup.getMode())) { if (LayerGroupInfo.Mode.EO.equals(layerGroup.getMode())) {
LayerInfo rootLayer = layerGroup.getRootLayer(); LayerInfo rootLayer = layerGroup.getRootLayer();
Expand Down Expand Up @@ -1497,7 +1499,7 @@ private void handleBBox(Envelope bbox, String srs) {
element("BoundingBox", null, bboxAtts); 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()) { if (serviceInfo.isBBOXForEachCRS() && !serviceInfo.getSRS().isEmpty()) {
//output bounding box for each supported service srs //output bounding box for each supported service srs
for (String srs : serviceInfo.getSRS()) { for (String srs : serviceInfo.getSRS()) {
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1103,6 +1103,7 @@ protected void handleLayerGroup(LayerGroupInfo layerGroup, Set<LayerInfo> layers


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


if (LayerGroupInfo.Mode.EO.equals(layerGroup.getMode())) { if (LayerGroupInfo.Mode.EO.equals(layerGroup.getMode())) {
LayerInfo rootLayer = layerGroup.getRootLayer(); LayerInfo rootLayer = layerGroup.getRootLayer();
Expand Down Expand Up @@ -1425,7 +1426,7 @@ private void handleBBox(Envelope bbox, String SRS) {
element("BoundingBox", null, bboxAtts); 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 //TODO: this method is copied from wms 1.3 caps (along with a lot of things), we
// should refactor // should refactor
//WMSInfo info = wmsConfig.getServiceInfo(); //WMSInfo info = wmsConfig.getServiceInfo();
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ public void testGlobalCapabilities() throws Exception {


assertXpathExists("//Layer/Name[text() = 'cite:base']", dom); assertXpathExists("//Layer/Name[text() = 'cite:base']", dom);
assertBounds(cite, "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 @Test
Expand Down Expand Up @@ -218,6 +228,15 @@ public void testWorkspaceCapabilities() throws Exception {
assertXpathExists("//Layer/Name[text() = 'base']", dom); assertXpathExists("//Layer/Name[text() = 'base']", dom);
assertXpathNotExists("//Layer/Name[text() = 'sf:base']", dom); assertXpathNotExists("//Layer/Name[text() = 'sf:base']", dom);
assertBounds(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 @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())), assertXpathEvaluatesTo(String.valueOf(Math.round(lg.getBounds().getMaxY())),
"round(//Layer[Name/text() = '"+name+"']/BoundingBox/@maxy)", dom); "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 Original file line 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.assertXpathExists;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathNotExists; import static org.custommonkey.xmlunit.XMLAssert.assertXpathNotExists;


import java.util.Arrays;

import javax.xml.namespace.QName; import javax.xml.namespace.QName;


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


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

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

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

assertXpathExists("//wms:Layer/wms:Name[text() = 'cite:base']", dom); assertXpathExists("//wms:Layer/wms:Name[text() = 'cite:base']", dom);
assertBounds(cite, "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 @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:Lakes']", dom);
assertXpathExists("/wms:WMS_Capabilities/wms:Capability/wms:Layer/wms:Layer[wms:Name[text() = 'base']]/wms:Layer/wms:Name[text() = 'cite:Forests']", dom); assertXpathExists("/wms:WMS_Capabilities/wms:Capability/wms:Layer/wms:Layer[wms:Name[text() = 'base']]/wms:Layer/wms:Name[text() = 'cite:Forests']", dom);
} }


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


assertXpathExists("//wms:Layer/wms:Name[text() = 'base']", dom); assertXpathExists("//wms:Layer/wms:Name[text() = 'base']", dom);
assertXpathNotExists("//wms:Layer/wms:Name[text() = 'sf:base']", dom); assertXpathNotExists("//wms:Layer/wms:Name[text() = 'sf:base']", dom);
assertBounds(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 @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 maxx = lg.getBounds().getMaxX();
double maxy = lg.getBounds().getMaxY(); 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) { if (lg.getBounds().getCoordinateReferenceSystem() instanceof GeographicCRS) {
//flip // flip
double tmp = minx; double tmp = minx;
minx = miny; minx = miny;
miny = tmp; miny = tmp;
Expand All @@ -380,13 +406,32 @@ void assertBounds(LayerGroupInfo lg, String name, Document dom) throws Exception
maxx = maxy; maxx = maxy;
maxy = tmp; maxy = tmp;
} }
assertXpathEvaluatesTo(String.valueOf(Math.round(minx)),
"round(//wms:Layer[wms:Name/text() = '"+name+"']/wms:BoundingBox/@minx)", dom); assertXpathEvaluatesTo(String.valueOf(Math.round(minx)),
assertXpathEvaluatesTo(String.valueOf(Math.round(maxx)), "round(//wms:Layer[wms:Name/text() = '" + name + "']/wms:BoundingBox[@CRS = 'EPSG:4326']/@minx)", dom);
"round(//wms:Layer[wms:Name/text() = '"+name+"']/wms:BoundingBox/@maxx)", dom); assertXpathEvaluatesTo(String.valueOf(Math.round(maxx)),
assertXpathEvaluatesTo(String.valueOf(Math.round(miny)), "round(//wms:Layer[wms:Name/text() = '" + name + "']/wms:BoundingBox[@CRS = 'EPSG:4326']/@maxx)", dom);
"round(//wms:Layer[wms:Name/text() = '"+name+"']/wms:BoundingBox/@miny)", dom); assertXpathEvaluatesTo(String.valueOf(Math.round(miny)),
assertXpathEvaluatesTo(String.valueOf(Math.round(maxy)), "round(//wms:Layer[wms:Name/text() = '" + name + "']/wms:BoundingBox[@CRS = 'EPSG:4326']/@miny)", dom);
"round(//wms:Layer[wms:Name/text() = '"+name+"']/wms:BoundingBox/@maxy)", 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.