Search in sources :

Example 6 with JTSPoint

use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPoint in project geotoolkit by Geomatys.

the class JTSGeometryBindingTest method MultiPointMarshalingTest.

/**
 * Test multiPoint Marshalling.
 */
@Test
public void MultiPointMarshalingTest() 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);
    JTSPoint pt1 = new JTSPoint(p1);
    DirectPosition p2 = new GeneralDirectPosition(crs);
    p2.setOrdinate(0, 402200);
    p2.setOrdinate(1, 3335200);
    JTSPoint pt2 = new JTSPoint(p2);
    JTSMultiPoint multiPoint = new JTSMultiPoint(crs);
    multiPoint.getElements().add(pt1);
    multiPoint.getElements().add(pt2);
    StringWriter sw = new StringWriter();
    m.marshal(factory.createJTSMultiPoint(multiPoint), 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:MultiPoint xmlns:gml=\"http://www.opengis.net/gml\" srsName=\"urn:ogc:def:crs:epsg::27572\" >" + '\n' + "  <gml:pointMember>" + '\n' + "    <gml:Point srsName=\"urn:ogc:def:crs:epsg::27572\">" + '\n' + "      <gml:pos>402000.0 3334850.0</gml:pos>" + '\n' + "    </gml:Point>" + '\n' + "  </gml:pointMember>" + '\n' + "  <gml:pointMember>" + '\n' + "    <gml:Point srsName=\"urn:ogc:def:crs:epsg::27572\">" + '\n' + "      <gml:pos>402200.0 3335200.0</gml:pos>" + '\n' + "    </gml:Point>" + '\n' + "  </gml:pointMember>" + '\n' + "</gml:MultiPoint>" + '\n';
    assertXmlEquals(expResult, result, "xmlns:*");
}
Also used : GeneralDirectPosition(org.apache.sis.geometry.GeneralDirectPosition) DirectPosition(org.opengis.geometry.DirectPosition) GeneralDirectPosition(org.apache.sis.geometry.GeneralDirectPosition) StringWriter(java.io.StringWriter) JTSPoint(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPoint) JTSMultiPoint(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiPoint) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) JTSLineString(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString)

Example 7 with JTSPoint

use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPoint in project geotoolkit by Geomatys.

the class JTSGeometryBindingTest method PointUnMarshalingTest.

/**
 * Test point Marshalling.
 */
@Test
public void PointUnMarshalingTest() throws Exception {
    String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<gml:Point srsName=\"urn:ogc:def:crs:epsg::4326\" xmlns:gml=\"http://www.opengis.net/gml\">" + '\n' + "  <gml:pos>2.1 12.6</gml:pos>" + '\n' + "</gml:Point>" + '\n';
    JAXBElement<JTSPoint> result = (JAXBElement) un.unmarshal(new StringReader(xml));
    CoordinateReferenceSystem crs = CRS.forCode("urn:ogc:def:crs:epsg::4326");
    assertTrue(crs != null);
    DirectPosition dp = new GeneralDirectPosition(crs);
    dp.setOrdinate(0, 2.1);
    dp.setOrdinate(1, 12.6);
    JTSPoint expResult = new JTSPoint(dp, crs);
    assertEquals(expResult.getDirectPosition(), result.getValue().getDirectPosition());
    assertEquals(expResult, result.getValue());
}
Also used : GeneralDirectPosition(org.apache.sis.geometry.GeneralDirectPosition) DirectPosition(org.opengis.geometry.DirectPosition) GeneralDirectPosition(org.apache.sis.geometry.GeneralDirectPosition) JTSPoint(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPoint) StringReader(java.io.StringReader) JTSLineString(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString) JAXBElement(javax.xml.bind.JAXBElement) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Aggregations

JTSPoint (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPoint)7 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)7 GeneralDirectPosition (org.apache.sis.geometry.GeneralDirectPosition)6 JTSMultiPoint (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiPoint)4 JTSLineString (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString)4 DirectPosition (org.opengis.geometry.DirectPosition)4 StringReader (java.io.StringReader)2 StringWriter (java.io.StringWriter)2 Test (org.junit.Test)2 Coordinate (org.locationtech.jts.geom.Coordinate)2 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)2 Point (org.locationtech.jts.geom.Point)2 JAXBElement (javax.xml.bind.JAXBElement)1 FeatureTypeBuilder (org.apache.sis.feature.builder.FeatureTypeBuilder)1 JTSCurveBoundary (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSCurveBoundary)1 JTSSurfaceBoundary (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSSurfaceBoundary)1 Geometry (org.locationtech.jts.geom.Geometry)1 LinearRing (org.locationtech.jts.geom.LinearRing)1 MultiLineString (org.locationtech.jts.geom.MultiLineString)1 MultiPoint (org.locationtech.jts.geom.MultiPoint)1