Search in sources :

Example 6 with DirectPositionListType

use of net.opengis.gml._3.DirectPositionListType in project geotoolkit by Geomatys.

the class GmlXMLBindingTest method umarshallingTest.

@Test
public void umarshallingTest() throws Exception {
    LineStringSegmentType expResult = new LineStringSegmentType();
    DirectPositionListType posList = new DirectPositionListType();
    posList.setValue(Arrays.asList(1.0, 1.1, 1.2));
    expResult.setPosList(posList);
    String xml = "<gml:LineStringSegment xmlns:gml=\"http://www.opengis.net/gml\">" + '\n' + "  <gml:posList>1.0 1.1 1.2</gml:posList>" + '\n' + "</gml:LineStringSegment>" + '\n';
    Object result = unmarshaller.unmarshal(new StringReader(xml));
    if (result instanceof JAXBElement) {
        result = ((JAXBElement) result).getValue();
    }
    assertEquals(expResult, result);
    expResult = new LineStringSegmentType();
    DirectPositionType pos1 = new DirectPositionType(Arrays.asList(1.1, 1.2));
    DirectPositionType pos2 = new DirectPositionType(Arrays.asList(2.3, 48.1));
    expResult.getPos().add(pos1);
    expResult.getPos().add(pos2);
    xml = "<gml:LineStringSegment xmlns:gml=\"http://www.opengis.net/gml\">" + '\n' + "  <gml:pos>1.1 1.2</gml:pos>" + '\n' + "  <gml:pos>2.3 48.1</gml:pos>" + '\n' + "</gml:LineStringSegment>" + '\n';
    result = unmarshaller.unmarshal(new StringReader(xml));
    if (result instanceof JAXBElement) {
        result = ((JAXBElement) result).getValue();
    }
    assertEquals(expResult, result);
}
Also used : LineStringSegmentType(org.geotoolkit.gml.xml.v311.LineStringSegmentType) DirectPositionType(org.geotoolkit.gml.xml.v311.DirectPositionType) DirectPositionListType(org.geotoolkit.gml.xml.v311.DirectPositionListType) StringReader(java.io.StringReader) JAXBElement(javax.xml.bind.JAXBElement)

Example 7 with DirectPositionListType

use of net.opengis.gml._3.DirectPositionListType in project geotoolkit by Geomatys.

the class GmlXMLBindingTest method umarshallingTest.

@Test
public void umarshallingTest() throws Exception {
    LineStringSegmentType expResult = new LineStringSegmentType();
    DirectPositionListType posList = new DirectPositionListType();
    posList.setValue(Arrays.asList(1.0, 1.1, 1.2));
    expResult.setPosList(posList);
    String xml = "<gml:LineStringSegment xmlns:gml=\"http://www.opengis.net/gml/3.2\">" + '\n' + "    <gml:posList>1.0 1.1 1.2</gml:posList>" + '\n' + "</gml:LineStringSegment>" + '\n';
    Object result = unmarshaller.unmarshal(new StringReader(xml));
    if (result instanceof JAXBElement) {
        result = ((JAXBElement) result).getValue();
    }
    assertEquals(expResult, result);
    expResult = new LineStringSegmentType();
    DirectPositionType pos1 = new DirectPositionType(Arrays.asList(1.1, 1.2));
    DirectPositionType pos2 = new DirectPositionType(Arrays.asList(2.3, 48.1));
    expResult.getPos().add(pos1);
    expResult.getPos().add(pos2);
    xml = "<gml:LineStringSegment xmlns:gml=\"http://www.opengis.net/gml/3.2\">" + '\n' + "    <gml:pos>1.1 1.2</gml:pos>" + '\n' + "    <gml:pos>2.3 48.1</gml:pos>" + '\n' + "</gml:LineStringSegment>" + '\n';
    result = unmarshaller.unmarshal(new StringReader(xml));
    if (result instanceof JAXBElement) {
        result = ((JAXBElement) result).getValue();
    }
    assertEquals(expResult, result);
}
Also used : LineStringSegmentType(org.geotoolkit.gml.xml.v321.LineStringSegmentType) DirectPositionType(org.geotoolkit.gml.xml.v321.DirectPositionType) DirectPositionListType(org.geotoolkit.gml.xml.v321.DirectPositionListType) StringReader(java.io.StringReader) JAXBElement(javax.xml.bind.JAXBElement)

Example 8 with DirectPositionListType

use of net.opengis.gml._3.DirectPositionListType in project geotoolkit by Geomatys.

the class GmlXMLBindingTest method marshallingTest.

/**
 * Test simple Record Marshalling.
 *
 * @throws JAXBException
 */
@Test
public void marshallingTest() throws Exception {
    DirectPositionType lower = new DirectPositionType(-30.711, 134.196);
    DirectPositionType upper = new DirectPositionType(-30.702, 134.205);
    EnvelopeType env = new EnvelopeType(lower, upper, "urn:ogc:def:crs:EPSG:6.8:4283");
    StringWriter sw = new StringWriter();
    marshaller.marshal(FACTORY.createEnvelope(env), sw);
    String result = sw.toString();
    // we remove the first line
    result = result.substring(result.indexOf("?>") + 2).trim();
    String expResult = "<gml:Envelope xmlns:gml=\"http://www.opengis.net/gml/3.2\" srsName=\"urn:ogc:def:crs:EPSG:6.8:4283\" >" + '\n' + "    <gml:lowerCorner>-30.711 134.196</gml:lowerCorner>" + '\n' + "    <gml:upperCorner>-30.702 134.205</gml:upperCorner>" + '\n' + "</gml:Envelope>" + '\n';
    DocumentComparator comparator = new DocumentComparator(expResult, result) {

        @Override
        protected strictfp void compareNames(Node expected, Node actual) {
            final String[] exArray = expected.getNodeName().split(":");
            final String[] acArray = actual.getNodeName().split(":");
            assertEquals(exArray.length, acArray.length);
            assertEquals(exArray[exArray.length - 1], acArray[acArray.length - 1]);
        }
    };
    comparator.ignoredAttributes.add("http://www.w3.org/2000/xmlns:*");
    comparator.compare();
    Duration d1 = javax.xml.datatype.DatatypeFactory.newInstance().newDuration("P2D");
    TimePeriodType tp = new TimePeriodType(d1);
    marshaller.marshal(FACTORY.createTimePeriod(tp), sw);
    TimePositionType tpos = new TimePositionType("2002-08-15");
    tp = new TimePeriodType(tpos);
    marshaller.marshal(FACTORY.createTimePeriod(tp), sw);
    // System.out.println(sw.toString());
    LineStringSegmentType ls = new LineStringSegmentType();
    DirectPositionListType posList = new DirectPositionListType();
    posList.setValue(Arrays.asList(1.0, 1.1, 1.2));
    ls.setPosList(posList);
    sw = new StringWriter();
    marshaller.marshal(FACTORY.createLineStringSegment(ls), sw);
    result = sw.toString();
    // we remove the first line
    result = result.substring(result.indexOf("?>") + 2).trim();
    expResult = "<gml:LineStringSegment xmlns:gml=\"http://www.opengis.net/gml/3.2\">" + '\n' + "    <gml:posList>1.0 1.1 1.2</gml:posList>" + '\n' + "</gml:LineStringSegment>" + '\n';
    comparator = new DocumentComparator(expResult, result) {

        @Override
        protected strictfp void compareNames(Node expected, Node actual) {
            final String[] exArray = expected.getNodeName().split(":");
            final String[] acArray = actual.getNodeName().split(":");
            assertEquals(exArray.length, acArray.length);
            assertEquals(exArray[exArray.length - 1], acArray[acArray.length - 1]);
        }
    };
    comparator.ignoredAttributes.add("http://www.w3.org/2000/xmlns:*");
    comparator.compare();
    ls = new LineStringSegmentType();
    DirectPositionType pos1 = new DirectPositionType(Arrays.asList(1.1, 1.2));
    DirectPositionType pos2 = new DirectPositionType(Arrays.asList(2.3, 48.1));
    ls.getPos().add(pos1);
    ls.getPos().add(pos2);
    sw = new StringWriter();
    marshaller.marshal(FACTORY.createLineStringSegment(ls), sw);
    result = sw.toString();
    // we remove the first line
    result = result.substring(result.indexOf("?>") + 2).trim();
    expResult = "<gml:LineStringSegment xmlns:gml=\"http://www.opengis.net/gml/3.2\">" + '\n' + "    <gml:pos>1.1 1.2</gml:pos>" + '\n' + "    <gml:pos>2.3 48.1</gml:pos>" + '\n' + "</gml:LineStringSegment>" + '\n';
    comparator = new DocumentComparator(expResult, result) {

        @Override
        protected strictfp void compareNames(Node expected, Node actual) {
            final String[] exArray = expected.getNodeName().split(":");
            final String[] acArray = actual.getNodeName().split(":");
            assertEquals(exArray.length, acArray.length);
            assertEquals(exArray[exArray.length - 1], acArray[acArray.length - 1]);
        }
    };
    comparator.ignoredAttributes.add("http://www.w3.org/2000/xmlns:*");
    comparator.compare();
}
Also used : EnvelopeType(org.geotoolkit.gml.xml.v321.EnvelopeType) LineStringSegmentType(org.geotoolkit.gml.xml.v321.LineStringSegmentType) DirectPositionType(org.geotoolkit.gml.xml.v321.DirectPositionType) Node(org.w3c.dom.Node) DirectPositionListType(org.geotoolkit.gml.xml.v321.DirectPositionListType) Duration(javax.xml.datatype.Duration) StringWriter(java.io.StringWriter) TimePeriodType(org.geotoolkit.gml.xml.v321.TimePeriodType) DocumentComparator(org.apache.sis.test.xml.DocumentComparator) TimePositionType(org.geotoolkit.gml.xml.v321.TimePositionType)

Example 9 with DirectPositionListType

use of net.opengis.gml._3.DirectPositionListType in project tiamat by entur.

the class LineStringConverterTest method convertToLineString.

@Test
public void convertToLineString() throws Exception {
    LineStringType lineStringType = new LineStringType().withId("LineString").withPosList(new DirectPositionListType().withSrsDimension(BigInteger.valueOf(2L)).withValue(71.1, 9.1, 4.1, 9.5));
    LineString lineString = lineStringConverter.convertTo(lineStringType, new TypeBuilder<LineString>() {
    }.build(), mappingContext);
    assertThat(lineString).isNotNull();
    assertThat(lineString.getCoordinates()).hasSize(2);
    assertThat(lineString.getCoordinates()[0].x).isEqualTo(lineStringType.getPosList().getValue().get(1));
    assertThat(lineString.getCoordinates()[0].y).isEqualTo(lineStringType.getPosList().getValue().get(0));
    assertThat(lineString.getCoordinates()[1].x).isEqualTo(lineStringType.getPosList().getValue().get(3));
    assertThat(lineString.getCoordinates()[1].y).isEqualTo(lineStringType.getPosList().getValue().get(2));
}
Also used : LineString(org.locationtech.jts.geom.LineString) TypeBuilder(ma.glasnost.orika.metadata.TypeBuilder) DirectPositionListType(net.opengis.gml._3.DirectPositionListType) LineStringType(net.opengis.gml._3.LineStringType) Test(org.junit.Test)

Example 10 with DirectPositionListType

use of net.opengis.gml._3.DirectPositionListType in project tiamat by entur.

the class PolygonConverterTest method convertFromWithHoles.

@Test
public void convertFromWithHoles() throws Exception {
    List<Double> values = new ArrayList<>();
    values.add(9.8468);
    values.add(59.2649);
    values.add(9.8456);
    values.add(59.2654);
    values.add(9.8457);
    values.add(59.2655);
    values.add(values.get(0));
    values.add(values.get(1));
    DirectPositionListType positionList = new DirectPositionListType().withValue(values);
    LinearRingType linearRing = new LinearRingType().withPosList(positionList);
    PolygonType polygonType = new PolygonType().withId("KVE-07").withExterior(new AbstractRingPropertyType().withAbstractRing(openGisObjectFactory.createLinearRing(linearRing))).withInterior(new AbstractRingPropertyType().withAbstractRing(openGisObjectFactory.createLinearRing(linearRing)));
    Polygon polygon = polygonConverter.convertFrom(polygonType, new TypeBuilder<Polygon>() {
    }.build(), new MappingContext(new HashMap<>()));
    assertThat(polygon).isNotNull();
    assertThat(polygon.getExteriorRing().getCoordinates()).hasSize(values.size() / 2);
    assertThat(polygon.getNumInteriorRing()).isEqualTo(1);
    assertCoordinatesMatch(polygon.getExteriorRing(), values, "Exterior ring");
    assertInteriorRingsMatch(polygon, Arrays.asList(values));
}
Also used : MappingContext(ma.glasnost.orika.MappingContext) TypeBuilder(ma.glasnost.orika.metadata.TypeBuilder) HashMap(java.util.HashMap) LinearRingType(net.opengis.gml._3.LinearRingType) AbstractRingPropertyType(net.opengis.gml._3.AbstractRingPropertyType) ArrayList(java.util.ArrayList) DirectPositionListType(net.opengis.gml._3.DirectPositionListType) PolygonType(net.opengis.gml._3.PolygonType) Polygon(org.locationtech.jts.geom.Polygon) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 DirectPositionListType (net.opengis.gml._3.DirectPositionListType)7 ArrayList (java.util.ArrayList)6 Coordinate (org.locationtech.jts.geom.Coordinate)6 DirectPositionListType (net.opengis.gml.x32.DirectPositionListType)5 DirectPositionListType (org.geotoolkit.gml.xml.v321.DirectPositionListType)5 Polygon (org.locationtech.jts.geom.Polygon)5 LineStringType (net.opengis.gml._3.LineStringType)4 LineString (org.locationtech.jts.geom.LineString)4 TypeBuilder (ma.glasnost.orika.metadata.TypeBuilder)3 AbstractRingPropertyType (net.opengis.gml._3.AbstractRingPropertyType)3 LinearRingType (net.opengis.gml._3.LinearRingType)3 PolygonType (net.opengis.gml._3.PolygonType)3 Geometry (org.locationtech.jts.geom.Geometry)3 StringReader (java.io.StringReader)2 StringWriter (java.io.StringWriter)2 BigDecimal (java.math.BigDecimal)2 HashMap (java.util.HashMap)2 JAXBElement (javax.xml.bind.JAXBElement)2 Duration (javax.xml.datatype.Duration)2