Search in sources :

Example 1 with MeasurementTimeseriesDocument

use of net.opengis.waterml.x20.MeasurementTimeseriesDocument in project arctic-sea by 52North.

the class TrajectoryObservationTypeEncoder method createMeasurementTimeseries.

/**
 * Encode {@link AbstractObservationValue} to
 * {@link MeasurementTimeseriesDocument}
 *
 * @param observationValue
 *            The {@link AbstractObservationValue} to encode
 * @return The encoded {@link AbstractObservationValue}
 * @throws EncodingException
 *             If an error occurs
 */
private XmlObject createMeasurementTimeseries(AbstractObservationValue<?> observationValue) throws EncodingException {
    MeasurementTimeseriesDocument measurementTimeseriesDoc = MeasurementTimeseriesDocument.Factory.newInstance();
    MeasurementTimeseriesType measurementTimeseries = measurementTimeseriesDoc.addNewMeasurementTimeseries();
    if (!observationValue.isSetObservationID()) {
        observationValue.setObservationID(JavaHelper.generateID(observationValue.toString()));
    }
    measurementTimeseries.setId(TIMESERIES_PREFIX + observationValue.getObservationID());
    measurementTimeseries.addNewMetadata().addNewTimeseriesMetadata().addNewTemporalExtent().setHref("#" + observationValue.getPhenomenonTime().getGmlId());
    TVPDefaultMetadataPropertyType xbMetaComponent = measurementTimeseries.addNewDefaultPointMetadata();
    DefaultTVPMeasurementMetadataDocument xbDefMeasureMetaComponent = DefaultTVPMeasurementMetadataDocument.Factory.newInstance();
    TVPMeasurementMetadataType defaultTVPMeasurementMetadata = xbDefMeasureMetaComponent.addNewDefaultTVPMeasurementMetadata();
    defaultTVPMeasurementMetadata.addNewInterpolationType().setHref("http://www.opengis.net/def/timeseriesType/WaterML/2.0/continuous");
    xbDefMeasureMetaComponent.getDefaultTVPMeasurementMetadata().getInterpolationType().setTitle("Instantaneous");
    String unit = null;
    if (observationValue instanceof SingleObservationValue) {
        SingleObservationValue<?> singleObservationValue = (SingleObservationValue<?>) observationValue;
        unit = singleObservationValue.getValue().getUnit();
        if (observationValue.getValue() instanceof TimeLocationValueTriple) {
            measurementTimeseries.addNewPoint().addNewMeasurementTVP().set(encodeTLVT((TimeLocationValueTriple) observationValue.getValue()));
        }
    } else if (observationValue instanceof MultiObservationValues) {
        MultiObservationValues<?> multiObservationValue = (MultiObservationValues<?>) observationValue;
        if (multiObservationValue.getValue() instanceof TLVTValue) {
            TLVTValue tlvtValue = (TLVTValue) multiObservationValue.getValue();
            List<TimeLocationValueTriple> timeLocationValueTriples = tlvtValue.getValue();
            unit = tlvtValue.getUnit();
            int counter = 0;
            for (TimeLocationValueTriple timeLocationValueTriple : timeLocationValueTriples) {
                timeLocationValueTriple.getLocation().setUserData(getUserObject(observationValue.getObservationID(), counter));
                measurementTimeseries.addNewPoint().addNewMeasurementTVP().set(encodeTLVT(timeLocationValueTriple));
                counter++;
            }
        }
    }
    if (unit != null && !unit.isEmpty()) {
        defaultTVPMeasurementMetadata.addNewUom().setCode(unit);
    }
    xbMetaComponent.set(xbDefMeasureMetaComponent);
    return measurementTimeseriesDoc;
}
Also used : MeasurementTimeseriesType(net.opengis.waterml.x20.MeasurementTimeseriesType) SingleObservationValue(org.n52.shetland.ogc.om.SingleObservationValue) TVPDefaultMetadataPropertyType(net.opengis.waterml.x20.TVPDefaultMetadataPropertyType) TVPMeasurementMetadataType(net.opengis.waterml.x20.TVPMeasurementMetadataType) DefaultTVPMeasurementMetadataDocument(net.opengis.waterml.x20.DefaultTVPMeasurementMetadataDocument) List(java.util.List) MeasurementTimeseriesDocument(net.opengis.waterml.x20.MeasurementTimeseriesDocument) TLVTValue(org.n52.shetland.ogc.om.values.TLVTValue) TimeLocationValueTriple(org.n52.shetland.ogc.om.TimeLocationValueTriple) MultiObservationValues(org.n52.shetland.ogc.om.MultiObservationValues)

Example 2 with MeasurementTimeseriesDocument

use of net.opengis.waterml.x20.MeasurementTimeseriesDocument in project arctic-sea by 52North.

the class WmlTVPEncoderv20 method createMeasurementTimeseries.

/**
 * Create a XML MeasurementTimeseries object from SOS observation for
 * om:result
 *
 * @param sosObservation
 *            SOS observation
 *
 * @return XML MeasurementTimeseries object
 *
 * @throws CodedException
 *             if the encoding fails
 */
private XmlObject createMeasurementTimeseries(OmObservation sosObservation) throws OwsExceptionReport {
    MeasurementTimeseriesDocument measurementTimeseriesDoc = MeasurementTimeseriesDocument.Factory.newInstance();
    MeasurementTimeseriesType measurementTimeseries = measurementTimeseriesDoc.addNewMeasurementTimeseries();
    measurementTimeseries.setId(TIMESERIES_ID_PREFIX + sosObservation.getObservationID());
    // Default value
    TimeseriesMetadata timeseriesMetadata = new MeasurementTimeseriesMetadata().setCumulative(false);
    if (sosObservation.isSetValue() && sosObservation.getValue().isSetValue() && sosObservation.getValue().getValue().getClass().isAssignableFrom(TVPValue.class) && sosObservation.getObservationConstellation().isSetMetadata() && sosObservation.getObservationConstellation().getMetadata().isSetTimeseriesMetadata()) {
        timeseriesMetadata = sosObservation.getObservationConstellation().getMetadata().getTimeseriesmetadata();
    }
    addTimeseriesMetadata(measurementTimeseries, sosObservation.getPhenomenonTime().getGmlId(), timeseriesMetadata);
    TVPDefaultMetadataPropertyType xbMetaComponent = measurementTimeseries.addNewDefaultPointMetadata();
    DefaultTVPMeasurementMetadataDocument xbDefMeasureMetaComponent = DefaultTVPMeasurementMetadataDocument.Factory.newInstance();
    TVPMeasurementMetadataType defaultTVPMeasurementMetadata = xbDefMeasureMetaComponent.addNewDefaultTVPMeasurementMetadata();
    // Default value
    InterpolationType interpolationType = InterpolationType.Continuous;
    if (sosObservation.isSetValue() && sosObservation.getValue().isSetValue() && sosObservation.getObservationConstellation().isSetDefaultPointMetadata() && sosObservation.getObservationConstellation().getDefaultPointMetadata().isSetDefaultTVPMeasurementMetadata() && sosObservation.getObservationConstellation().getDefaultPointMetadata().getDefaultTVPMeasurementMetadata().isSetInterpolationType()) {
        interpolationType = sosObservation.getObservationConstellation().getDefaultPointMetadata().getDefaultTVPMeasurementMetadata().getInterpolationtype();
    }
    defaultTVPMeasurementMetadata.addNewInterpolationType().setHref(interpolationType.getIdentifier());
    xbDefMeasureMetaComponent.getDefaultTVPMeasurementMetadata().getInterpolationType().setTitle(interpolationType.getTitle());
    String unit = addValues(measurementTimeseries, sosObservation.getValue());
    // set uom
    if (unit != null && !unit.isEmpty()) {
        defaultTVPMeasurementMetadata.addNewUom().setCode(unit);
    } else {
        OmObservableProperty observableProperty = (OmObservableProperty) sosObservation.getObservationConstellation().getObservableProperty();
        if (observableProperty.isSetUnit()) {
            defaultTVPMeasurementMetadata.addNewUom().setCode(observableProperty.getUnit());
        }
    }
    xbMetaComponent.set(xbDefMeasureMetaComponent);
    return measurementTimeseriesDoc;
}
Also used : TimeseriesMetadata(org.n52.shetland.ogc.om.series.wml.TimeseriesMetadata) MeasurementTimeseriesMetadata(org.n52.shetland.ogc.om.series.wml.MeasurementTimeseriesMetadata) MeasurementTimeseriesType(net.opengis.waterml.x20.MeasurementTimeseriesType) TVPValue(org.n52.shetland.ogc.om.values.TVPValue) TVPDefaultMetadataPropertyType(net.opengis.waterml.x20.TVPDefaultMetadataPropertyType) MeasurementTimeseriesMetadata(org.n52.shetland.ogc.om.series.wml.MeasurementTimeseriesMetadata) TVPMeasurementMetadataType(net.opengis.waterml.x20.TVPMeasurementMetadataType) DefaultTVPMeasurementMetadataDocument(net.opengis.waterml.x20.DefaultTVPMeasurementMetadataDocument) InterpolationType(org.n52.shetland.ogc.om.series.wml.WaterMLConstants.InterpolationType) MeasurementTimeseriesDocument(net.opengis.waterml.x20.MeasurementTimeseriesDocument) OmObservableProperty(org.n52.shetland.ogc.om.OmObservableProperty)

Example 3 with MeasurementTimeseriesDocument

use of net.opengis.waterml.x20.MeasurementTimeseriesDocument in project arctic-sea by 52North.

the class WmlTVPEncoderv20Test method shouldEncodeInterpolationType.

@Test
public void shouldEncodeInterpolationType() throws EncodingException, XmlException {
    final InterpolationType type = WaterMLConstants.InterpolationType.MinPrec;
    mv.setDefaultPointMetadata(new DefaultPointMetadata().setDefaultTVPMeasurementMetadata(new DefaultTVPMeasurementMetadata().setInterpolationtype(type)));
    XmlObject encodedElement = encoder.encode(mv);
    TVPDefaultMetadataPropertyType defaultPointMetadata = ((MeasurementTimeseriesDocument) encodedElement).getTimeseries().getDefaultPointMetadataArray(0);
    DefaultTVPMeasurementMetadataDocument tvpMeasurementMetadataDocument = DefaultTVPMeasurementMetadataDocument.Factory.parse(defaultPointMetadata.xmlText());
    ReferenceType interpolationType = tvpMeasurementMetadataDocument.getDefaultTVPMeasurementMetadata().getInterpolationType();
    Assert.assertThat(interpolationType.getHref(), Is.is("http://www.opengis.net/def/waterml/2.0/interpolationType/MinPrec"));
    Assert.assertThat(interpolationType.getTitle(), Is.is("MinPrec"));
}
Also used : DefaultPointMetadata(org.n52.shetland.ogc.om.series.wml.DefaultPointMetadata) TVPDefaultMetadataPropertyType(net.opengis.waterml.x20.TVPDefaultMetadataPropertyType) DefaultTVPMeasurementMetadata(org.n52.shetland.ogc.om.series.wml.DefaultTVPMeasurementMetadata) XmlObject(org.apache.xmlbeans.XmlObject) DefaultTVPMeasurementMetadataDocument(net.opengis.waterml.x20.DefaultTVPMeasurementMetadataDocument) InterpolationType(org.n52.shetland.ogc.om.series.wml.WaterMLConstants.InterpolationType) ReferenceType(net.opengis.gml.x32.ReferenceType) Test(org.junit.Test)

Example 4 with MeasurementTimeseriesDocument

use of net.opengis.waterml.x20.MeasurementTimeseriesDocument in project arctic-sea by 52North.

the class WmlTVPEncoderv20Test method shouldEncodeCumulativeProperty.

@Test
public void shouldEncodeCumulativeProperty() throws EncodingException {
    mv.setMetadata(new Metadata().setTimeseriesmetadata(new MeasurementTimeseriesMetadata().setCumulative(true)));
    XmlObject encodedElement = encoder.encode(mv);
    Assert.assertThat(((MeasurementTimeseriesMetadataType) ((MeasurementTimeseriesDocument) encodedElement).getTimeseries().getMetadata().getTimeseriesMetadata()).getCumulative(), Is.is(true));
}
Also used : DefaultTVPMeasurementMetadata(org.n52.shetland.ogc.om.series.wml.DefaultTVPMeasurementMetadata) DefaultPointMetadata(org.n52.shetland.ogc.om.series.wml.DefaultPointMetadata) Metadata(org.n52.shetland.ogc.om.series.wml.Metadata) MeasurementTimeseriesMetadata(org.n52.shetland.ogc.om.series.wml.MeasurementTimeseriesMetadata) MeasurementTimeseriesMetadata(org.n52.shetland.ogc.om.series.wml.MeasurementTimeseriesMetadata) XmlObject(org.apache.xmlbeans.XmlObject) MeasurementTimeseriesDocument(net.opengis.waterml.x20.MeasurementTimeseriesDocument) Test(org.junit.Test)

Example 5 with MeasurementTimeseriesDocument

use of net.opengis.waterml.x20.MeasurementTimeseriesDocument in project arctic-sea by 52North.

the class WmlTVPEncoderv20Test method shouldSetDefaultCumulativeProperty.

@Test
public void shouldSetDefaultCumulativeProperty() throws EncodingException {
    XmlObject encodedElement = encoder.encode(mv);
    Assert.assertThat(encodedElement, CoreMatchers.instanceOf(MeasurementTimeseriesDocument.class));
    final MeasurementTimeseriesDocument measurementTimeseriesDocument = (MeasurementTimeseriesDocument) encodedElement;
    Assert.assertThat(measurementTimeseriesDocument.getTimeseries().isSetMetadata(), Is.is(true));
    Assert.assertThat(measurementTimeseriesDocument.getTimeseries().getMetadata().getTimeseriesMetadata(), CoreMatchers.instanceOf(MeasurementTimeseriesMetadataType.class));
    final MeasurementTimeseriesMetadataType measurementTimeseriesMetadataType = (MeasurementTimeseriesMetadataType) measurementTimeseriesDocument.getTimeseries().getMetadata().getTimeseriesMetadata();
    Assert.assertThat(measurementTimeseriesMetadataType.isSetCumulative(), Is.is(true));
    Assert.assertThat(measurementTimeseriesMetadataType.getCumulative(), Is.is(false));
}
Also used : MeasurementTimeseriesMetadataType(net.opengis.waterml.x20.MeasurementTimeseriesMetadataType) XmlObject(org.apache.xmlbeans.XmlObject) MeasurementTimeseriesDocument(net.opengis.waterml.x20.MeasurementTimeseriesDocument) Test(org.junit.Test)

Aggregations

DefaultTVPMeasurementMetadataDocument (net.opengis.waterml.x20.DefaultTVPMeasurementMetadataDocument)5 MeasurementTimeseriesDocument (net.opengis.waterml.x20.MeasurementTimeseriesDocument)5 TVPDefaultMetadataPropertyType (net.opengis.waterml.x20.TVPDefaultMetadataPropertyType)5 XmlObject (org.apache.xmlbeans.XmlObject)4 Test (org.junit.Test)4 MeasurementTimeseriesType (net.opengis.waterml.x20.MeasurementTimeseriesType)3 TVPMeasurementMetadataType (net.opengis.waterml.x20.TVPMeasurementMetadataType)3 MeasurementTimeseriesMetadata (org.n52.shetland.ogc.om.series.wml.MeasurementTimeseriesMetadata)3 InterpolationType (org.n52.shetland.ogc.om.series.wml.WaterMLConstants.InterpolationType)3 ReferenceType (net.opengis.gml.x32.ReferenceType)2 DefaultPointMetadata (org.n52.shetland.ogc.om.series.wml.DefaultPointMetadata)2 DefaultTVPMeasurementMetadata (org.n52.shetland.ogc.om.series.wml.DefaultTVPMeasurementMetadata)2 TimeseriesMetadata (org.n52.shetland.ogc.om.series.wml.TimeseriesMetadata)2 List (java.util.List)1 MeasurementTimeseriesMetadataType (net.opengis.waterml.x20.MeasurementTimeseriesMetadataType)1 MultiObservationValues (org.n52.shetland.ogc.om.MultiObservationValues)1 OmObservableProperty (org.n52.shetland.ogc.om.OmObservableProperty)1 SingleObservationValue (org.n52.shetland.ogc.om.SingleObservationValue)1 TimeLocationValueTriple (org.n52.shetland.ogc.om.TimeLocationValueTriple)1 Metadata (org.n52.shetland.ogc.om.series.wml.Metadata)1