diff --git a/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTBoundingBox.java b/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTBoundingBox.java new file mode 100644 index 0000000..71d462d --- /dev/null +++ b/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTBoundingBox.java @@ -0,0 +1,48 @@ +package it.geosolutions.geoserver.rest.decoder; + +import org.jdom.Element; + +/** + * Parse a Boundingbox of the following structure + * + * 472800.0 + * 817362.0 + * 35053.40625 + * 301500.0 + * EPSG:21781 + * + * @author nmandery + */ +public class RESTBoundingBox { + + protected Element bboxElem; + + public RESTBoundingBox(Element bboxElem) { + this.bboxElem = bboxElem; + } + + public String getCRS() { + return this.bboxElem.getChildText("crs"); + } + + protected double getEdge(String edge) { + return Double.parseDouble(this.bboxElem.getChildText(edge)); + } + + public double getMinX() { + return this.getEdge("minx"); + } + + public double getMaxX() { + return this.getEdge("maxx"); + } + + public double getMinY() { + return this.getEdge("miny"); + } + + public double getMaxY() { + return this.getEdge("maxy"); + } + +} diff --git a/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTResource.java b/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTResource.java index 9840c17..303c091 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTResource.java +++ b/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTResource.java @@ -109,31 +109,44 @@ public class RESTResource { Namespace.getNamespace("atom", "http://www.w3.org/2005/Atom")); return atom.getAttributeValue("href"); } + + public RESTBoundingBox getNativeBoundingBox() { + RESTBoundingBox bbox = null; + Element bboxElement = rootElem.getChild("nativeBoundingBox"); + if (bboxElement != null) { + bbox = new RESTBoundingBox(bboxElement); + } + return bbox; + } + + public RESTBoundingBox getLatLonBoundingBox() { + RESTBoundingBox bbox = null; + Element bboxElement = rootElem.getChild("latLonBoundingBox"); + if (bboxElement != null) { + bbox = new RESTBoundingBox(bboxElement); + } + return bbox; + } public String getCRS() { - Element elBBox = rootElem.getChild("latLonBoundingBox"); - return elBBox.getChildText("crs"); - } - - protected double getLatLonEdge(String edge) { - Element elBBox = rootElem.getChild("latLonBoundingBox"); - return Double.parseDouble(elBBox.getChildText(edge)); + RESTBoundingBox bbox = this.getLatLonBoundingBox(); + return bbox.getCRS(); } public double getMinX() { - return getLatLonEdge("minx"); + return this.getLatLonBoundingBox().getMinX(); } public double getMaxX() { - return getLatLonEdge("maxx"); + return this.getLatLonBoundingBox().getMaxX(); } public double getMinY() { - return getLatLonEdge("miny"); + return this.getLatLonBoundingBox().getMinY(); } public double getMaxY() { - return getLatLonEdge("maxy"); + return this.getLatLonBoundingBox().getMaxY(); } /** diff --git a/src/test/java/it/geosolutions/geoserver/decoder/ResourceDecoderTest.java b/src/test/java/it/geosolutions/geoserver/decoder/ResourceDecoderTest.java index 84f4be2..c5178dc 100644 --- a/src/test/java/it/geosolutions/geoserver/decoder/ResourceDecoderTest.java +++ b/src/test/java/it/geosolutions/geoserver/decoder/ResourceDecoderTest.java @@ -1,5 +1,6 @@ package it.geosolutions.geoserver.decoder; +import it.geosolutions.geoserver.rest.decoder.RESTBoundingBox; import it.geosolutions.geoserver.rest.decoder.RESTCoverage; import it.geosolutions.geoserver.rest.encoder.dimensions.GSCoverageDimensionEncoder; import it.geosolutions.geoserver.rest.encoder.metadatalink.GSMetadataLinkInfoEncoder; @@ -94,6 +95,28 @@ public class ResourceDecoderTest { Assert.assertEquals(coverage.getMaxY(), 90, 0); } + @Test + public void testLatLonBoundingBox() { + RESTBoundingBox bbox = coverage.getLatLonBoundingBox(); + Assert.assertTrue(bbox != null); + Assert.assertEquals("EPSG:4326", bbox.getCRS()); + Assert.assertEquals(-180.0, bbox.getMinX(), 0); + Assert.assertEquals(180.0, bbox.getMaxX(), 0); + Assert.assertEquals(-90, bbox.getMinY(), 0); + Assert.assertEquals(90, bbox.getMaxY(), 0); + } + + @Test + public void testNativeBoundingBox() { + RESTBoundingBox bbox = coverage.getNativeBoundingBox(); + Assert.assertTrue(bbox != null); + Assert.assertEquals("EPSG:4326", bbox.getCRS()); + Assert.assertEquals(-180.0, bbox.getMinX(), 0); + Assert.assertEquals(180.0, bbox.getMaxX(), 0); + Assert.assertEquals(-90, bbox.getMinY(), 0); + Assert.assertEquals(90, bbox.getMaxY(), 0); + } + @Test public void testMetadataLinkInfo() throws IOException {