Search in sources :

Example 36 with EnvelopeType

use of org.geotoolkit.gml.xml.v321.EnvelopeType 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("bound-1", 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=\"" + GML + '"' + " 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';
    assertXmlEquals(expResult, result, "xmlns:*");
    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=\"" + GML + "\">\n" + "  <gml:posList>1.0 1.1 1.2</gml:posList>" + '\n' + "</gml:LineStringSegment>" + '\n';
    assertXmlEquals(expResult, result, "xmlns:*");
    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=\"" + GML + "\">\n" + "  <gml:pos>1.1 1.2</gml:pos>" + '\n' + "  <gml:pos>2.3 48.1</gml:pos>" + '\n' + "</gml:LineStringSegment>" + '\n';
    assertXmlEquals(expResult, result, "xmlns:*");
}
Also used : EnvelopeType(org.geotoolkit.gml.xml.v311.EnvelopeType) LineStringSegmentType(org.geotoolkit.gml.xml.v311.LineStringSegmentType) DirectPositionType(org.geotoolkit.gml.xml.v311.DirectPositionType) StringWriter(java.io.StringWriter) TimePeriodType(org.geotoolkit.gml.xml.v311.TimePeriodType) DirectPositionListType(org.geotoolkit.gml.xml.v311.DirectPositionListType) Duration(javax.xml.datatype.Duration) TimePositionType(org.geotoolkit.gml.xml.v311.TimePositionType)

Example 37 with EnvelopeType

use of org.geotoolkit.gml.xml.v321.EnvelopeType in project geotoolkit by Geomatys.

the class GeometrytoJTSTest method gmlEnvelopeToJTSTest2D.

@Test
public void gmlEnvelopeToJTSTest2D() throws Exception {
    final EnvelopeType env = new EnvelopeType(new DirectPositionType(2.0, 2.0), new DirectPositionType(4.0, 4.0), "EPSG:4326");
    final Geometry geom = GeometrytoJTS.toJTS(env);
    Coordinate[] expectedPoints = { new Coordinate(2.0, 2.0), new Coordinate(2.0, 4.0), new Coordinate(4.0, 4.0), new Coordinate(4.0, 2.0), new Coordinate(2.0, 2.0) };
    Assert.assertTrue(GF.createPolygon(expectedPoints).equalsTopo(geom));
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) EnvelopeType(org.geotoolkit.gml.xml.v321.EnvelopeType) DirectPositionType(org.geotoolkit.gml.xml.v321.DirectPositionType) Coordinate(org.locationtech.jts.geom.Coordinate) Test(org.junit.Test)

Aggregations

EnvelopeType (net.opengis.gml.v_3_1_1.EnvelopeType)11 EnvelopeType (org.geotoolkit.gml.xml.v311.EnvelopeType)11 DirectPositionType (org.geotoolkit.gml.xml.v311.DirectPositionType)9 JAXBElement (javax.xml.bind.JAXBElement)8 DirectPositionType (net.opengis.gml.v_3_1_1.DirectPositionType)8 BBOXType (net.opengis.filter.v_1_1_0.BBOXType)6 Test (org.junit.Test)6 Envelope (org.locationtech.jts.geom.Envelope)6 ArrayList (java.util.ArrayList)5 EnvelopeType (org.geosdi.geoplatform.xml.gml.v311.EnvelopeType)5 StringWriter (java.io.StringWriter)4 List (java.util.List)4 FilterType (net.opengis.filter.v_1_1_0.FilterType)4 AnyValueType (net.opengis.cat.wrs.v_1_0_2.AnyValueType)3 PointType (net.opengis.gml.v_3_1_1.PointType)3 EnvelopeType (net.opengis.swe.x101.EnvelopeType)3 DirectPositionType (org.geotoolkit.gml.xml.v321.DirectPositionType)3 EnvelopeType (org.geotoolkit.gml.xml.v321.EnvelopeType)3 OverlapsType (org.geotoolkit.ogc.xml.v110.OverlapsType)3 PropertyNameType (org.geotoolkit.ogc.xml.v110.PropertyNameType)3