129 fix: create RESTBoundingBox class and wrap latLonBoundingBox and nativeBoundingBox attributes

This commit is contained in:
Nico Mandery 2014-06-30 09:01:17 +02:00
parent ba8f17c5b1
commit 33b951c8ab
3 changed files with 95 additions and 11 deletions

View File

@ -0,0 +1,48 @@
package it.geosolutions.geoserver.rest.decoder;
import org.jdom.Element;
/**
* Parse a Boundingbox of the following structure
*
* <minx>472800.0</minx>
* <maxx>817362.0</maxx>
* <miny>35053.40625</miny>
* <maxy>301500.0</maxy>
* <crs class="projected">EPSG:21781</crs>
*
* @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");
}
}

View File

@ -110,30 +110,43 @@ public class RESTResource {
return atom.getAttributeValue("href"); return atom.getAttributeValue("href");
} }
public String getCRS() { public RESTBoundingBox getNativeBoundingBox() {
Element elBBox = rootElem.getChild("latLonBoundingBox"); RESTBoundingBox bbox = null;
return elBBox.getChildText("crs"); Element bboxElement = rootElem.getChild("nativeBoundingBox");
if (bboxElement != null) {
bbox = new RESTBoundingBox(bboxElement);
}
return bbox;
} }
protected double getLatLonEdge(String edge) { public RESTBoundingBox getLatLonBoundingBox() {
Element elBBox = rootElem.getChild("latLonBoundingBox"); RESTBoundingBox bbox = null;
return Double.parseDouble(elBBox.getChildText(edge)); Element bboxElement = rootElem.getChild("latLonBoundingBox");
if (bboxElement != null) {
bbox = new RESTBoundingBox(bboxElement);
}
return bbox;
}
public String getCRS() {
RESTBoundingBox bbox = this.getLatLonBoundingBox();
return bbox.getCRS();
} }
public double getMinX() { public double getMinX() {
return getLatLonEdge("minx"); return this.getLatLonBoundingBox().getMinX();
} }
public double getMaxX() { public double getMaxX() {
return getLatLonEdge("maxx"); return this.getLatLonBoundingBox().getMaxX();
} }
public double getMinY() { public double getMinY() {
return getLatLonEdge("miny"); return this.getLatLonBoundingBox().getMinY();
} }
public double getMaxY() { public double getMaxY() {
return getLatLonEdge("maxy"); return this.getLatLonBoundingBox().getMaxY();
} }
/** /**

View File

@ -1,5 +1,6 @@
package it.geosolutions.geoserver.decoder; package it.geosolutions.geoserver.decoder;
import it.geosolutions.geoserver.rest.decoder.RESTBoundingBox;
import it.geosolutions.geoserver.rest.decoder.RESTCoverage; import it.geosolutions.geoserver.rest.decoder.RESTCoverage;
import it.geosolutions.geoserver.rest.encoder.dimensions.GSCoverageDimensionEncoder; import it.geosolutions.geoserver.rest.encoder.dimensions.GSCoverageDimensionEncoder;
import it.geosolutions.geoserver.rest.encoder.metadatalink.GSMetadataLinkInfoEncoder; import it.geosolutions.geoserver.rest.encoder.metadatalink.GSMetadataLinkInfoEncoder;
@ -94,6 +95,28 @@ public class ResourceDecoderTest {
Assert.assertEquals(coverage.getMaxY(), 90, 0); 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 @Test
public void testMetadataLinkInfo() throws IOException { public void testMetadataLinkInfo() throws IOException {