use of org.geotoolkit.internal.jaxb.PolyhedralSurfaceType in project geotoolkit by Geomatys.
the class JTSGeometryBindingTest method PolyHedralSurfaceUnmarshalingTest.
/**
* Test PolyHedral surface Unmarshalling.
*/
@Test
public void PolyHedralSurfaceUnmarshalingTest() throws Exception {
CoordinateReferenceSystem crs = CRS.forCode("urn:ogc:def:crs:epsg::27572");
assertTrue(crs != null);
JTSPolyhedralSurface expResult = new JTSPolyhedralSurface(crs);
/*
* FIRST POLYGON
*/
// EXTERIOR
JTSRing exterior1 = new JTSRing(crs);
JTSCurve c1 = new JTSCurve(crs);
JTSLineString c1l1 = new JTSLineString();
DirectPosition c1l1p1 = new GeneralDirectPosition(crs);
c1l1p1.setOrdinate(0, 401500);
c1l1p1.setOrdinate(1, 3334500);
DirectPosition c1l1p2 = new GeneralDirectPosition(crs);
c1l1p2.setOrdinate(0, 401700);
c1l1p2.setOrdinate(1, 3334850);
DirectPosition c1l1p3 = new GeneralDirectPosition(crs);
c1l1p3.setOrdinate(0, 402200);
c1l1p3.setOrdinate(1, 3335200);
DirectPosition c1l2p1 = new GeneralDirectPosition(crs);
c1l2p1.setOrdinate(0, 402320);
c1l2p1.setOrdinate(1, 3334850);
DirectPosition c1l2p2 = new GeneralDirectPosition(crs);
c1l2p2.setOrdinate(0, 402200);
c1l2p2.setOrdinate(1, 3335200);
c1l1.getControlPoints().add(c1l1p1);
c1l1.getControlPoints().add(c1l1p2);
c1l1.getControlPoints().add(c1l1p3);
c1l1.getControlPoints().add(c1l2p1);
c1l1.getControlPoints().add(c1l2p2);
c1.getSegments().add(c1l1);
exterior1.getElements().add(c1);
// INTERIOR
Ring[] interiors1 = new Ring[1];
JTSRing interior1 = new JTSRing(crs);
JTSCurve c2 = new JTSCurve(crs);
JTSLineString c2l1 = new JTSLineString();
DirectPosition c2l1p1 = new GeneralDirectPosition(crs);
c2l1p1.setOrdinate(0, 401500);
c2l1p1.setOrdinate(1, 3334500);
DirectPosition c2l1p2 = new GeneralDirectPosition(crs);
c2l1p2.setOrdinate(0, 401700);
c2l1p2.setOrdinate(1, 3334850);
DirectPosition c2l1p3 = new GeneralDirectPosition(crs);
c2l1p3.setOrdinate(0, 402200);
c2l1p3.setOrdinate(1, 3335200);
c2l1.getControlPoints().add(c2l1p1);
c2l1.getControlPoints().add(c2l1p2);
c2l1.getControlPoints().add(c2l1p3);
c2.getSegments().add(c2l1);
interior1.getElements().add(c2);
interiors1[0] = interior1;
JTSSurfaceBoundary bound1 = new JTSSurfaceBoundary(crs, exterior1, interiors1);
JTSPolygon p1 = new JTSPolygon(bound1);
/*
* SECOND POLYGON
*/
// EXTERIOR
JTSRing exterior2 = new JTSRing(crs);
JTSCurve c3 = new JTSCurve(crs);
JTSLineString c3l1 = new JTSLineString();
DirectPosition c3l1p1 = new GeneralDirectPosition(crs);
c3l1p1.setOrdinate(0, 401500);
c3l1p1.setOrdinate(1, 3334500);
DirectPosition c3l1p2 = new GeneralDirectPosition(crs);
c3l1p2.setOrdinate(0, 401700);
c3l1p2.setOrdinate(1, 3334850);
DirectPosition c3l1p3 = new GeneralDirectPosition(crs);
c3l1p3.setOrdinate(0, 402200);
c3l1p3.setOrdinate(1, 3335200);
c3l1.getControlPoints().add(c3l1p1);
c3l1.getControlPoints().add(c3l1p2);
c3l1.getControlPoints().add(c3l1p3);
c3.getSegments().add(c3l1);
exterior2.getElements().add(c3);
// INTERIOR
JTSRing interior2 = new JTSRing(crs);
JTSCurve c4 = new JTSCurve(crs);
JTSLineString c4l1 = new JTSLineString();
DirectPosition c4l1p1 = new GeneralDirectPosition(crs);
c4l1p1.setOrdinate(0, 401500);
c4l1p1.setOrdinate(1, 3334500);
DirectPosition c4l1p2 = new GeneralDirectPosition(crs);
c4l1p2.setOrdinate(0, 401700);
c4l1p2.setOrdinate(1, 3334850);
DirectPosition c4l1p3 = new GeneralDirectPosition(crs);
c4l1p3.setOrdinate(0, 402200);
c4l1p3.setOrdinate(1, 3335200);
c4l1.getControlPoints().add(c4l1p1);
c4l1.getControlPoints().add(c4l1p2);
c4l1.getControlPoints().add(c4l1p3);
c4.getSegments().add(c4l1);
interior2.getElements().add(c4);
Ring[] interiors2 = new Ring[1];
interiors2[0] = interior2;
JTSSurfaceBoundary bound2 = new JTSSurfaceBoundary(crs, exterior2, interiors2);
JTSPolygon p2 = new JTSPolygon(bound2);
expResult.getPatches().add(p1);
expResult.getPatches().add(p2);
// TODO remove the srsName
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<gml:PolyhedralSurface srsName=\"urn:ogc:def:crs:epsg::27572\" xmlns:gml=\"http://www.opengis.net/gml\">" + '\n' + " <gml:polygonPatches>" + '\n' + " <gml:PolygonPatch>" + '\n' + " <gml:exterior>" + '\n' + " <gml:LinearRing>" + '\n' + " <gml:posList>401500.0 3334500.0 401700.0 3334850.0 402200.0 3335200.0 402320.0 3334850.0 402200.0 3335200.0</gml:posList>" + '\n' + " </gml:LinearRing>" + '\n' + " </gml:exterior>" + '\n' + " <gml:interior>" + '\n' + " <gml:LinearRing>" + '\n' + " <gml:posList>401500.0 3334500.0 401700.0 3334850.0 402200.0 3335200.0</gml:posList>" + '\n' + " </gml:LinearRing>" + '\n' + " </gml:interior>" + '\n' + " </gml:PolygonPatch>" + '\n' + " <gml:PolygonPatch>" + '\n' + " <gml:exterior>" + '\n' + " <gml:LinearRing>" + '\n' + " <gml:posList>401500.0 3334500.0 401700.0 3334850.0 402200.0 3335200.0</gml:posList>" + '\n' + " </gml:LinearRing>" + '\n' + " </gml:exterior>" + '\n' + " <gml:interior>" + '\n' + " <gml:LinearRing>" + '\n' + " <gml:posList>401500.0 3334500.0 401700.0 3334850.0 402200.0 3335200.0</gml:posList>" + '\n' + " </gml:LinearRing>" + '\n' + " </gml:interior>" + '\n' + " </gml:PolygonPatch>" + '\n' + " </gml:polygonPatches>" + '\n' + "</gml:PolyhedralSurface>" + '\n';
PolyhedralSurfaceType tmp = (PolyhedralSurfaceType) ((JAXBElement) un.unmarshal(new StringReader(xml))).getValue();
JTSPolyhedralSurface result = tmp.getIsoPolyHedralSurface();
JTSSurfaceBoundary expBoundary = (JTSSurfaceBoundary) expResult.getPatches().get(0).getBoundary();
JTSSurfaceBoundary resBoundary = (JTSSurfaceBoundary) result.getPatches().get(0).getBoundary();
JTSCurve expCurve = (JTSCurve) expBoundary.getExterior().getElements().iterator().next();
JTSCurve resCurve = (JTSCurve) resBoundary.getExterior().getElements().iterator().next();
assertEquals(((JTSLineString) expCurve.getSegments().get(0)).getControlPoints().get(0), ((JTSLineString) resCurve.getSegments().get(0)).getControlPoints().get(0));
assertEquals(expCurve.getSegments().get(0), resCurve.getSegments().get(0));
assertEquals(expCurve, resCurve);
assertEquals(expBoundary.getExterior(), resBoundary.getExterior());
assertEquals(expBoundary.getInteriors(), resBoundary.getInteriors());
assertEquals(expBoundary, resBoundary);
assertEquals(expResult.getPatches().get(0), result.getPatches().get(0));
assertEquals(expResult.getPatches().get(1), result.getPatches().get(1));
assertEquals(expResult.getPatches(), result.getPatches());
assertEquals(expResult, result);
}
Aggregations