use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.complex.JTSCompositeCurve in project geotoolkit by Geomatys.
the class JTSGeometryBindingTest method CompositeCurveMarshalingTest.
/**
* Test Composite curve Marshalling.
*/
@Test
public void CompositeCurveMarshalingTest() throws Exception {
CoordinateReferenceSystem crs = CRS.forCode("urn:ogc:def:crs:epsg::27572");
assertTrue(crs != null);
DirectPosition p1 = new GeneralDirectPosition(crs);
p1.setOrdinate(0, 402000);
p1.setOrdinate(1, 3334850);
DirectPosition p2 = new GeneralDirectPosition(crs);
p2.setOrdinate(0, 402200);
p2.setOrdinate(1, 3335200);
JTSLineString l1 = new JTSLineString();
l1.getControlPoints().add(p1);
l1.getControlPoints().add(p2);
JTSCurve c2 = new JTSCurve(crs);
c2.getSegments().add(l1);
JTSCurve c1 = new JTSCurve(crs);
JTSLineString l2 = new JTSLineString();
DirectPosition p21 = new GeneralDirectPosition(crs);
p21.setOrdinate(0, 401500);
p21.setOrdinate(1, 3334500);
DirectPosition p22 = new GeneralDirectPosition(crs);
p22.setOrdinate(0, 401700);
p22.setOrdinate(1, 3334850);
DirectPosition p23 = new GeneralDirectPosition(crs);
p23.setOrdinate(0, 402200);
p23.setOrdinate(1, 3335200);
l2.getControlPoints().add(p21);
l2.getControlPoints().add(p22);
l2.getControlPoints().add(p23);
c1.getSegments().add(l2);
JTSLineString l3 = new JTSLineString();
DirectPosition p31 = new GeneralDirectPosition(crs);
p31.setOrdinate(0, 402320);
p31.setOrdinate(1, 3334850);
DirectPosition p32 = new GeneralDirectPosition(crs);
p32.setOrdinate(0, 402200);
p32.setOrdinate(1, 3335200);
l3.getControlPoints().add(p31);
l3.getControlPoints().add(p32);
c1.getSegments().add(l3);
JTSCompositeCurve compositeCurve = new JTSCompositeCurve(null, crs);
// compositeCurve.getElements().add(l1); TODO
compositeCurve.getElements().add(c1);
compositeCurve.getElements().add(c2);
StringWriter sw = new StringWriter();
m.marshal(factory.createJTSCompositeCurve(compositeCurve), sw);
String result = sw.toString();
result = result.replaceAll("(?i)epsg\\:\\d+\\.\\d+\\.?\\d*\\:", "epsg::");
String expResult = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<gml:CompositeCurve xmlns:gml=\"http://www.opengis.net/gml\" srsName=\"urn:ogc:def:crs:epsg::27572\" >" + '\n' + " <gml:curveMember>" + '\n' + " <gml:Curve srsName=\"urn:ogc:def:crs:epsg::27572\">" + '\n' + " <gml:segments>" + '\n' + " <gml:LineStringSegment interpolation=\"linear\">" + '\n' + " <gml:pos>401500.0 3334500.0</gml:pos>" + '\n' + " <gml:pos>401700.0 3334850.0</gml:pos>" + '\n' + " <gml:pos>402200.0 3335200.0</gml:pos>" + '\n' + " </gml:LineStringSegment>" + '\n' + " <gml:LineStringSegment interpolation=\"linear\">" + '\n' + " <gml:pos>402320.0 3334850.0</gml:pos>" + '\n' + " <gml:pos>402200.0 3335200.0</gml:pos>" + '\n' + " </gml:LineStringSegment>" + '\n' + " </gml:segments>" + '\n' + " </gml:Curve>" + '\n' + " </gml:curveMember>" + '\n' + " <gml:curveMember>" + '\n' + " <gml:Curve srsName=\"urn:ogc:def:crs:epsg::27572\">" + '\n' + " <gml:segments>" + '\n' + " <gml:LineStringSegment interpolation=\"linear\">" + '\n' + " <gml:pos>402000.0 3334850.0</gml:pos>" + '\n' + " <gml:pos>402200.0 3335200.0</gml:pos>" + '\n' + " </gml:LineStringSegment>" + '\n' + " </gml:segments>" + '\n' + " </gml:Curve>" + '\n' + " </gml:curveMember>" + '\n' + "</gml:CompositeCurve>" + '\n';
assertXmlEquals(expResult, result, "xmlns:*");
}
use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.complex.JTSCompositeCurve in project geotoolkit by Geomatys.
the class JTSGeometryBindingTest method CompositeCurveUnmarshalingTest.
/**
* Test Composite curve Marshalling.
*/
@Test
public void CompositeCurveUnmarshalingTest() throws Exception {
CoordinateReferenceSystem crs = CRS.forCode("urn:ogc:def:crs:epsg::27572");
assertTrue(crs != null);
DirectPosition p1 = new GeneralDirectPosition(crs);
p1.setOrdinate(0, 402000);
p1.setOrdinate(1, 3334850);
DirectPosition p2 = new GeneralDirectPosition(crs);
p2.setOrdinate(0, 402200);
p2.setOrdinate(1, 3335200);
JTSLineString l1 = new JTSLineString(crs);
l1.getControlPoints().add(p1);
l1.getControlPoints().add(p2);
JTSCurve c2 = new JTSCurve(crs);
c2.getSegments().add(l1);
JTSCurve c1 = new JTSCurve(crs);
JTSLineString l2 = new JTSLineString(crs);
DirectPosition p21 = new GeneralDirectPosition(crs);
p21.setOrdinate(0, 401500);
p21.setOrdinate(1, 3334500);
DirectPosition p22 = new GeneralDirectPosition(crs);
p22.setOrdinate(0, 401700);
p22.setOrdinate(1, 3334850);
DirectPosition p23 = new GeneralDirectPosition(crs);
p23.setOrdinate(0, 402200);
p23.setOrdinate(1, 3335200);
l2.getControlPoints().add(p21);
l2.getControlPoints().add(p22);
l2.getControlPoints().add(p23);
c1.getSegments().add(l2);
JTSLineString l3 = new JTSLineString(crs);
DirectPosition p31 = new GeneralDirectPosition(crs);
p31.setOrdinate(0, 402320);
p31.setOrdinate(1, 3334850);
DirectPosition p32 = new GeneralDirectPosition(crs);
p32.setOrdinate(0, 402200);
p32.setOrdinate(1, 3335200);
l3.getControlPoints().add(p31);
l3.getControlPoints().add(p32);
c1.getSegments().add(l3);
JTSCompositeCurve expResult = new JTSCompositeCurve(null, crs);
// compositeCurve.getElements().add(l1); TODO
expResult.getElements().add(c1);
expResult.getElements().add(c2);
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<gml:CompositeCurve srsName=\"urn:ogc:def:crs:epsg::27572\" xmlns:gml=\"http://www.opengis.net/gml\">" + '\n' + " <gml:curveMember>" + '\n' + " <gml:Curve srsName=\"urn:ogc:def:crs:epsg::27572\">" + '\n' + " <gml:segments>" + '\n' + " <gml:LineStringSegment interpolation=\"linear\">" + '\n' + " <gml:pos>401500.0 3334500.0</gml:pos>" + '\n' + " <gml:pos>401700.0 3334850.0</gml:pos>" + '\n' + " <gml:pos>402200.0 3335200.0</gml:pos>" + '\n' + " </gml:LineStringSegment>" + '\n' + " <gml:LineStringSegment interpolation=\"linear\">" + '\n' + " <gml:pos>402320.0 3334850.0</gml:pos>" + '\n' + " <gml:pos>402200.0 3335200.0</gml:pos>" + '\n' + " </gml:LineStringSegment>" + '\n' + " </gml:segments>" + '\n' + " </gml:Curve>" + '\n' + " </gml:curveMember>" + '\n' + " <gml:curveMember>" + '\n' + " <gml:Curve srsName=\"urn:ogc:def:crs:epsg::27572\">" + '\n' + " <gml:segments>" + '\n' + " <gml:LineStringSegment interpolation=\"linear\">" + '\n' + " <gml:pos>402000.0 3334850.0</gml:pos>" + '\n' + " <gml:pos>402200.0 3335200.0</gml:pos>" + '\n' + " </gml:LineStringSegment>" + '\n' + " </gml:segments>" + '\n' + " </gml:Curve>" + '\n' + " </gml:curveMember>" + '\n' + "</gml:CompositeCurve>" + '\n';
JTSCompositeCurve result = (JTSCompositeCurve) ((JAXBElement) un.unmarshal(new StringReader(xml))).getValue();
assertEquals(((JTSLineString) ((JTSCurve) expResult.getElements().iterator().next()).getSegments().get(0)).getCoordinateReferenceSystem(), ((JTSLineString) ((JTSCurve) result.getElements().iterator().next()).getSegments().get(0)).getCoordinateReferenceSystem());
assertEquals(((JTSCurve) expResult.getElements().iterator().next()).getSegments().get(0), ((JTSCurve) result.getElements().iterator().next()).getSegments().get(0));
assertEquals(((JTSCurve) expResult.getElements().iterator().next()).getSegments(), ((JTSCurve) result.getElements().iterator().next()).getSegments());
assertEquals(expResult.getElements().iterator().next(), result.getElements().iterator().next());
assertEquals(expResult, result);
}
Aggregations