Search in sources :

Example 26 with TimePositionType

use of org.geotoolkit.gml.xml.v311.TimePositionType in project arctic-sea by 52North.

the class GmlEncoderv321 method createTimePositionType.

private TimePositionType createTimePositionType(TimePosition timePosition) throws DateTimeFormatException {
    TimePositionType xbTimePosition = TimePositionType.Factory.newInstance();
    if (!timePosition.isSetTime()) {
        String indeterminateValue = Optional.ofNullable(timePosition.getIndeterminateValue()).orElse(IndeterminateValue.UNKNOWN).getValue();
        if (TimeIndeterminateValueType.Enum.forString(indeterminateValue) != null) {
            xbTimePosition.setIndeterminatePosition(TimeIndeterminateValueType.Enum.forString(indeterminateValue));
        } else {
            xbTimePosition.setStringValue(indeterminateValue);
        }
    } else {
        String endString = DateTimeHelper.formatDateTime2String(timePosition);
        // concat minutes for timeZone offset, because gml requires
        // xs:dateTime, which needs minutes in
        // timezone offset
        // TODO enable really
        xbTimePosition.setStringValue(endString);
    }
    return xbTimePosition;
}
Also used : MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) TimePositionType(net.opengis.gml.x32.TimePositionType)

Example 27 with TimePositionType

use of org.geotoolkit.gml.xml.v311.TimePositionType in project geotoolkit by Geomatys.

the class GetCoverageType method getTime.

/**
 * {@inheritDoc}
 */
@Override
public String getTime() {
    if (domainSubset == null || domainSubset.getTemporalSubSet() == null || domainSubset.getTemporalSubSet().getTimePositionOrTimePeriod() == null) {
        return null;
    }
    final List<Object> times = domainSubset.getTemporalSubSet().getTimePositionOrTimePeriod();
    final Object timeObj = times.get(0);
    if (timeObj instanceof TimePositionType) {
        return ((TimePositionType) timeObj).getValue();
    } else {
        return null;
    }
}
Also used : IdentifiedObject(org.opengis.referencing.IdentifiedObject) TimePositionType(org.geotoolkit.gml.xml.v311.TimePositionType)

Example 28 with TimePositionType

use of org.geotoolkit.gml.xml.v311.TimePositionType in project geotoolkit by Geomatys.

the class GetCoverageType method getTime.

/**
 * {@inheritDoc}
 */
@Override
public String getTime() {
    if (domainSubset == null || domainSubset.getTemporalSubset() == null) {
        return null;
    }
    final List<Object> times = domainSubset.getTemporalSubset().getTimePositionOrTimePeriod();
    final Object obj = times.get(0);
    if (obj instanceof TimePositionType) {
        return ((TimePositionType) obj).getValue();
    } else {
        return null;
    }
}
Also used : IdentifiedObject(org.opengis.referencing.IdentifiedObject) TimePositionType(org.geotoolkit.gml.xml.v311.TimePositionType)

Example 29 with TimePositionType

use of org.geotoolkit.gml.xml.v311.TimePositionType 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 30 with TimePositionType

use of org.geotoolkit.gml.xml.v311.TimePositionType in project geotoolkit by Geomatys.

the class TimePeriodTypeTest method getTime2Test.

@Test
public void getTime2Test() throws Exception {
    TimePositionType tn = null;
    TimePositionType tb = new TimePositionType("2008-11-01T02:00:00");
    TimePositionType te = new TimePositionType("2008-11-01T02:01:00");
    TimePeriodType tp = new TimePeriodType(new TimeInstantType(tb), new TimeInstantType(te));
    assertEquals(60000, tp.getTime());
    tb = new TimePositionType("2008-11-01T01:00:00");
    te = new TimePositionType("2008-11-01T02:00:00");
    tp = new TimePeriodType(new TimeInstantType(tb), new TimeInstantType(te));
    assertEquals(3600000, tp.getTime());
    tp = new TimePeriodType(new TimeInstantType(tb), new TimeInstantType(tn));
    assertEquals(-1, tp.getTime());
    tb = null;
    tp = new TimePeriodType(new TimeInstantType(tb), new TimeInstantType(te));
    assertEquals(-1, tp.getTime());
    tb = null;
    te = null;
    tp = new TimePeriodType(new TimeInstantType(tb), new TimeInstantType(te));
    assertEquals(-1, tp.getTime());
}
Also used : TimeInstantType(org.geotoolkit.gml.xml.v311.TimeInstantType) TimePeriodType(org.geotoolkit.gml.xml.v311.TimePeriodType) TimePositionType(org.geotoolkit.gml.xml.v311.TimePositionType)

Aggregations

Date (java.util.Date)17 TimePositionType (net.opengis.gml.v_3_2_1.TimePositionType)14 BinaryTemporalOpType (net.opengis.filter.v_2_0_0.BinaryTemporalOpType)13 FilterType (net.opengis.filter.v_2_0_0.FilterType)13 Test (org.junit.Test)12 TimePositionType (org.geotoolkit.gml.xml.v311.TimePositionType)11 ArrayList (java.util.ArrayList)10 TimePeriodType (net.opengis.gml.v_3_2_1.TimePeriodType)9 TimeInstantType (net.opengis.gml.v_3_2_1.TimeInstantType)7 TimePeriodType (org.geotoolkit.gml.xml.v311.TimePeriodType)7 FilterCapabilities (net.opengis.filter.v_2_0_0.FilterCapabilities)6 TimePositionType (org.geotoolkit.gml.xml.v321.TimePositionType)6 JAXBElement (javax.xml.bind.JAXBElement)4 TimePeriodType (org.geotoolkit.gml.xml.v321.TimePeriodType)4 StringWriter (java.io.StringWriter)3 List (java.util.List)3 TimeInstantType (org.geotoolkit.gml.xml.v311.TimeInstantType)3 StringReader (java.io.StringReader)2 Calendar (java.util.Calendar)2 Duration (javax.xml.datatype.Duration)2