Search in sources :

Example 21 with ObservationValue

use of org.n52.shetland.ogc.om.ObservationValue in project arctic-sea by 52North.

the class OmDecoderv20 method getObservationValue.

private ObservationValue<?> getObservationValue(OMObservationType omObservation) throws DecodingException {
    Time phenomenonTime = getPhenomenonTime(omObservation);
    ObservationValue<?> observationValue;
    if (!omObservation.getResult().getDomNode().hasChildNodes() && phenomenonTime.isSetNilReason() && phenomenonTime.getNilReason().equals(NilReason.template)) {
        observationValue = new SingleObservationValue<>(new NilTemplateValue());
    } else {
        observationValue = getResult(omObservation);
    }
    observationValue.setPhenomenonTime(phenomenonTime);
    return observationValue;
}
Also used : Time(org.n52.shetland.ogc.gml.time.Time) NilTemplateValue(org.n52.shetland.ogc.om.values.NilTemplateValue)

Example 22 with ObservationValue

use of org.n52.shetland.ogc.om.ObservationValue in project arctic-sea by 52North.

the class InsertObservationRequestEncoderTest method createInsertObservationRequest.

private InsertObservationRequest createInsertObservationRequest() throws InvalidSridException, ParseException {
    SamplingFeature samplingFeature = new SamplingFeature(new CodeWithAuthority("test-feature-uri"));
    samplingFeature.setName(new CodeType("test-feature-name"));
    samplingFeature.setSampledFeatures(Arrays.asList(new SamplingFeature(new CodeWithAuthority("test-parent-feature-uri"))));
    samplingFeature.setGeometry(JTSHelper.createGeometryFromWKT("POINT(52.0 42.0)", 4326));
    PhysicalSystem procedure = new PhysicalSystem();
    procedure.setIdentifier("test-procedure");
    OmObservationConstellation observationConstellation = new OmObservationConstellation();
    observationConstellation.setGmlId("o1");
    observationConstellation.setObservationType(OmConstants.OBS_TYPE_MEASUREMENT);
    observationConstellation.setObservableProperty(new OmObservableProperty("test-property"));
    observationConstellation.setFeatureOfInterest(samplingFeature);
    observationConstellation.setProcedure(procedure);
    TimeInstant time = new TimeInstant(new Date(0));
    QuantityValue quantity = new QuantityValue(23.0, "test-uom");
    ObservationValue<?> value = new SingleObservationValue<>(time, quantity);
    OmObservation omObservation = new OmObservation();
    omObservation.setObservationConstellation(observationConstellation);
    omObservation.setResultTime(time);
    omObservation.setValue(value);
    InsertObservationRequest request = new InsertObservationRequest("SOS", "2.0.0");
    request.setOfferings(Arrays.asList(OFFERING_ID));
    request.addObservation(omObservation);
    return request;
}
Also used : PhysicalSystem(org.n52.shetland.ogc.sensorML.v20.PhysicalSystem) OmObservation(org.n52.shetland.ogc.om.OmObservation) SamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature) OmObservationConstellation(org.n52.shetland.ogc.om.OmObservationConstellation) Date(java.util.Date) SingleObservationValue(org.n52.shetland.ogc.om.SingleObservationValue) QuantityValue(org.n52.shetland.ogc.om.values.QuantityValue) InsertObservationRequest(org.n52.shetland.ogc.sos.request.InsertObservationRequest) CodeType(org.n52.shetland.ogc.gml.CodeType) CodeWithAuthority(org.n52.shetland.ogc.gml.CodeWithAuthority) OmObservableProperty(org.n52.shetland.ogc.om.OmObservableProperty) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant)

Example 23 with ObservationValue

use of org.n52.shetland.ogc.om.ObservationValue in project arctic-sea by 52North.

the class WmlTVPEncoderv20XmlStreamWriter method writeResult.

@Override
protected void writeResult() throws XMLStreamException, EncodingException {
    start(OmConstants.QN_OM_20_RESULT);
    namespace(WaterMLConstants.NS_WML_20_PREFIX, WaterMLConstants.NS_WML_20);
    start(WaterMLConstants.QN_MEASUREMENT_TIMESERIES);
    OmObservation observation = getElement();
    attr(GmlConstants.QN_ID_32, "timeseries." + observation.getObservationID());
    writeMeasurementTimeseriesMetadata(observation);
    if (observation.getValue() instanceof SingleObservationValue) {
        SingleObservationValue<?> observationValue = (SingleObservationValue<?>) observation.getValue();
        writeDefaultPointMetadata(observationValue, observationValue.getValue().getUnit());
        String time = getTimeString(observationValue.getPhenomenonTime());
        writePoint(time, getValue(observation.getValue().getValue()));
        close();
    } else if (observation.getValue() instanceof MultiObservationValues) {
        // XML streaming to client
        MultiObservationValues<?> observationValue = (MultiObservationValues<?>) observation.getValue();
        writeDefaultPointMetadata(observationValue, observationValue.getValue().getUnit());
        TVPValue tvpValue = (TVPValue) observationValue.getValue();
        List<TimeValuePair> timeValuePairs = tvpValue.getValue();
        for (TimeValuePair timeValuePair : timeValuePairs) {
            if (timeValuePair != null) {
                writePoint(getTimeString(timeValuePair.getTime()), getValue(timeValuePair.getValue()));
            }
        }
        close();
    } else if (observation.getValue() instanceof StreamingValue) {
        // Database streaming + XML streaming to client
        StreamingValue<?> observationValue = (StreamingValue<?>) observation.getValue();
        if (observationValue.isSetUnit()) {
            writeDefaultPointMetadata(observationValue, observationValue.getUnit());
        } else if (observation.getObservationConstellation().getObservableProperty() instanceof OmObservableProperty && ((OmObservableProperty) observation.getObservationConstellation().getObservableProperty()).isSetUnit()) {
            writeDefaultPointMetadata(observationValue, ((OmObservableProperty) observation.getObservationConstellation().getObservableProperty()).getUnit());
        } else {
            writeDefaultPointMetadata(observationValue, null);
        }
        try {
            while (observationValue.hasNext()) {
                TimeValuePair timeValuePair = observationValue.nextValue();
                if (timeValuePair != null) {
                    writePoint(getTimeString(timeValuePair.getTime()), getValue(timeValuePair.getValue()));
                }
            }
        } catch (DateTimeFormatException | OwsExceptionReport e) {
            throw new EncodingException(e);
        }
        close();
    } else {
        super.writeResult();
    }
}
Also used : TVPValue(org.n52.shetland.ogc.om.values.TVPValue) StreamingValue(org.n52.shetland.ogc.om.StreamingValue) EncodingException(org.n52.svalbard.encode.exception.EncodingException) OmObservation(org.n52.shetland.ogc.om.OmObservation) DateTimeFormatException(org.n52.shetland.util.DateTimeFormatException) MultiObservationValues(org.n52.shetland.ogc.om.MultiObservationValues) SingleObservationValue(org.n52.shetland.ogc.om.SingleObservationValue) List(java.util.List) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport) OmObservableProperty(org.n52.shetland.ogc.om.OmObservableProperty) TimeValuePair(org.n52.shetland.ogc.om.TimeValuePair)

Example 24 with ObservationValue

use of org.n52.shetland.ogc.om.ObservationValue in project arctic-sea by 52North.

the class WmlTDREncoderv20 method createMeasurementDomainRange.

/**
 * Create a XML MeasurementTimeseriesDomainRange object from SOS observation
 * for om:result
 *
 * @param sosObservation
 *            SOS observation
 * @return XML MeasurementTimeseriesDomainRange object for om:result
 * @throws EncodingException
 *             If an error occurs
 */
private XmlObject createMeasurementDomainRange(OmObservation sosObservation) throws EncodingException {
    if (!sosObservation.getObservationConstellation().isSetObservationType() || (sosObservation.getObservationConstellation().isSetObservationType() && isInvalidObservationType(sosObservation.getObservationConstellation().getObservationType()))) {
        throw new UnsupportedEncoderInputException(this, sosObservation.getObservationConstellation().isSetObservationType());
    }
    MeasurementTimeseriesDomainRangeDocument xbMearuementTimeseriesDomainRangeDoc = MeasurementTimeseriesDomainRangeDocument.Factory.newInstance();
    MeasurementTimeseriesCoverageType xbMeasurementTimeseriesDomainRange = xbMearuementTimeseriesDomainRangeDoc.addNewMeasurementTimeseriesDomainRange();
    xbMeasurementTimeseriesDomainRange.setId(TIMESERIES_ID_PREFIX + sosObservation.getObservationID());
    // set time position list
    xbMeasurementTimeseriesDomainRange.addNewDomainSet().set(getTimePositionList(sosObservation));
    // initialize unit
    AbstractPhenomenon observableProperty = sosObservation.getObservationConstellation().getObservableProperty();
    String unit = null;
    // create quantity list from values
    QuantityListDocument quantityListDoc = QuantityListDocument.Factory.newInstance();
    MeasureOrNilReasonListType quantityList = quantityListDoc.addNewQuantityList();
    if (sosObservation.getValue() instanceof MultiObservationValues) {
        MultiObservationValues<?> observationValue = (MultiObservationValues<?>) sosObservation.getValue();
        TVPValue tvpValue = (TVPValue) observationValue.getValue();
        List<TimeValuePair> timeValuePairs = tvpValue.getValue();
        if (Strings.isNullOrEmpty(unit) && CollectionHelper.isNotEmpty(timeValuePairs) && timeValuePairs.get(0).getValue().isSetUnit()) {
            unit = timeValuePairs.get(0).getValue().getUnit();
        }
        quantityList.setListValue(getValueList(timeValuePairs));
    }
    if (Strings.isNullOrEmpty(unit)) {
        unit = OGCConstants.UNKNOWN;
    }
    quantityList.setUom(unit);
    // set unit to SosObservableProperty if not set.
    if (observableProperty instanceof OmObservableProperty && !((OmObservableProperty) observableProperty).isSetUnit()) {
        ((OmObservableProperty) observableProperty).setUnit(unit);
    }
    // set up range set
    xbMeasurementTimeseriesDomainRange.addNewRangeSet().set(quantityListDoc);
    // set up rangeType
    xbMeasurementTimeseriesDomainRange.addNewRangeType().set(createDataRecord(sosObservation));
    // set om:Result
    return xbMearuementTimeseriesDomainRangeDoc;
}
Also used : TVPValue(org.n52.shetland.ogc.om.values.TVPValue) MeasureOrNilReasonListType(net.opengis.gml.x32.MeasureOrNilReasonListType) MultiObservationValues(org.n52.shetland.ogc.om.MultiObservationValues) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException) MeasurementTimeseriesDomainRangeDocument(net.opengis.watermlDr.x20.MeasurementTimeseriesDomainRangeDocument) AbstractPhenomenon(org.n52.shetland.ogc.om.AbstractPhenomenon) QuantityListDocument(net.opengis.gml.x32.QuantityListDocument) MeasurementTimeseriesCoverageType(net.opengis.watermlDr.x20.MeasurementTimeseriesCoverageType) OmObservableProperty(org.n52.shetland.ogc.om.OmObservableProperty) TimeValuePair(org.n52.shetland.ogc.om.TimeValuePair)

Example 25 with ObservationValue

use of org.n52.shetland.ogc.om.ObservationValue in project arctic-sea by 52North.

the class WmlTDREncoderv20 method createMeasurementDomainRange.

private XmlObject createMeasurementDomainRange(AbstractObservationValue<?> observationValue) throws EncodingException {
    if (!observationValue.isSetObservationType() || (observationValue.isSetObservationType() && isInvalidObservationType(observationValue.getObservationType()))) {
        return null;
    }
    MeasurementTimeseriesDomainRangeDocument xbMearuementTimeseriesDomainRangeDoc = MeasurementTimeseriesDomainRangeDocument.Factory.newInstance();
    MeasurementTimeseriesCoverageType xbMeasurementTimeseriesDomainRange = xbMearuementTimeseriesDomainRangeDoc.addNewMeasurementTimeseriesDomainRange();
    xbMeasurementTimeseriesDomainRange.setId(TIMESERIES_ID_PREFIX + observationValue.getObservationID());
    // set time position list
    xbMeasurementTimeseriesDomainRange.addNewDomainSet().set(getTimePositionList(observationValue));
    // initialize unit
    // AbstractPhenomenon observableProperty =
    // observationValue.getObservableProperty();
    String unit = null;
    // create quantity list from values
    QuantityListDocument quantityListDoc = QuantityListDocument.Factory.newInstance();
    MeasureOrNilReasonListType quantityList = quantityListDoc.addNewQuantityList();
    if (observationValue instanceof MultiObservationValues) {
        TVPValue tvpValue = (TVPValue) ((MultiObservationValues<?>) observationValue).getValue();
        List<TimeValuePair> timeValuePairs = tvpValue.getValue();
        if (Strings.isNullOrEmpty(unit) && CollectionHelper.isNotEmpty(timeValuePairs) && timeValuePairs.get(0).getValue().isSetUnit()) {
            unit = timeValuePairs.get(0).getValue().getUnit();
        }
        quantityList.setListValue(getValueList(timeValuePairs));
    }
    if (Strings.isNullOrEmpty(unit)) {
        unit = OGCConstants.UNKNOWN;
    }
    quantityList.setUom(unit);
    // set unit to SosObservableProperty if not set.
    // if (observableProperty instanceof OmObservableProperty
    // && !((OmObservableProperty) observableProperty).isSetUnit()) {
    // ((OmObservableProperty) observableProperty).setUnit(unit);
    // }
    // set up range set
    xbMeasurementTimeseriesDomainRange.addNewRangeSet().set(quantityListDoc);
    // set up rangeType
    xbMeasurementTimeseriesDomainRange.addNewRangeType().set(createDataRecord(observationValue, unit));
    // set om:Result
    return xbMearuementTimeseriesDomainRangeDoc;
}
Also used : MeasurementTimeseriesDomainRangeDocument(net.opengis.watermlDr.x20.MeasurementTimeseriesDomainRangeDocument) TVPValue(org.n52.shetland.ogc.om.values.TVPValue) MeasureOrNilReasonListType(net.opengis.gml.x32.MeasureOrNilReasonListType) QuantityListDocument(net.opengis.gml.x32.QuantityListDocument) MeasurementTimeseriesCoverageType(net.opengis.watermlDr.x20.MeasurementTimeseriesCoverageType) MultiObservationValues(org.n52.shetland.ogc.om.MultiObservationValues) TimeValuePair(org.n52.shetland.ogc.om.TimeValuePair)

Aggregations

MultiObservationValues (org.n52.shetland.ogc.om.MultiObservationValues)9 SingleObservationValue (org.n52.shetland.ogc.om.SingleObservationValue)9 Test (org.junit.Test)7 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)7 QuantityValue (org.n52.shetland.ogc.om.values.QuantityValue)6 List (java.util.List)5 TimeValuePair (org.n52.shetland.ogc.om.TimeValuePair)5 TVPValue (org.n52.shetland.ogc.om.values.TVPValue)5 Geometry (org.locationtech.jts.geom.Geometry)4 StreamingValue (org.n52.shetland.ogc.om.StreamingValue)4 TimeLocationValueTriple (org.n52.shetland.ogc.om.TimeLocationValueTriple)4 CountValue (org.n52.shetland.ogc.om.values.CountValue)4 GeometryValue (org.n52.shetland.ogc.om.values.GeometryValue)4 TVPDefaultMetadataPropertyType (net.opengis.waterml.x20.TVPDefaultMetadataPropertyType)3 OmObservableProperty (org.n52.shetland.ogc.om.OmObservableProperty)3 BooleanValue (org.n52.shetland.ogc.om.values.BooleanValue)3 TLVTValue (org.n52.shetland.ogc.om.values.TLVTValue)3 SweDataArray (org.n52.shetland.ogc.swe.SweDataArray)3 MeasureOrNilReasonListType (net.opengis.gml.x32.MeasureOrNilReasonListType)2 QuantityListDocument (net.opengis.gml.x32.QuantityListDocument)2