Search in sources :

Example 56 with OmObservation

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

the class AbstractOmV20XmlStreamWriter method writeObservation.

/**
 * Write {@link OmObservation} XML encoded to stream
 *
 * @param observation the observation
 *
 * @throws XMLStreamException If an error occurs when writing to stream
 * @throws EncodingException  If an error occurs when creating elements to be written If an error occurs when
 *                            creating elements to be written
 */
protected void writeObservation(OmObservation observation) throws XMLStreamException, EncodingException {
    start(getDocumentName());
    namespace(W3CConstants.NS_XLINK_PREFIX, W3CConstants.NS_XLINK);
    namespace(W3CConstants.NS_XSI_PREFIX, W3CConstants.NS_XSI);
    namespace(OmConstants.NS_OM_PREFIX, OmConstants.NS_OM_2);
    namespace(GmlConstants.NS_GML_PREFIX, GmlConstants.NS_GML_32);
    writeAddtitionalNamespaces();
    String observationID = addGmlId(observation);
    checkAndWriteIdentifier();
    checkAndWriteName();
    checkAndWriteDescription();
    if (observation.getObservationConstellation().isSetObservationType()) {
        writeObservationType(observation.getObservationConstellation().getObservationType());
    }
    if (observation.isSetMetaDataProperty()) {
        writeMetaDataProperty(observation.getMetaDataProperty());
    }
    Time phenomenonTime = observation.getPhenomenonTime();
    if (phenomenonTime.getGmlId() == null) {
        phenomenonTime.setGmlId(OmConstants.PHENOMENON_TIME_NAME + "_" + observationID);
    }
    writePhenomenonTime(phenomenonTime);
    writeResultTime();
    if (observation.isSetValidTime()) {
        writeValidTime(observation.getValidTime());
    }
    writeProcedure();
    if (observation.isSetParameter()) {
        writeParameter();
    }
    writeObservableProperty();
    writeFeatureOfIntererst();
    writeResult();
    end(getDocumentName());
}
Also used : Time(org.n52.shetland.ogc.gml.time.Time) DateTime(org.joda.time.DateTime)

Example 57 with OmObservation

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

the class AbstractOmV20XmlStreamWriter method writeResultTime.

/**
 * Write om:resultTime to stream
 *
 * @throws XMLStreamException
 *             If an error occurs when writing to stream
 * @throws EncodingException
 *             If an error occurs when creating elements to be written
 */
protected void writeResultTime() throws XMLStreamException, EncodingException {
    OmObservation observation = getElement();
    TimeInstant resultTime = observation.getResultTime();
    Time phenomenonTime = observation.getPhenomenonTime();
    // get result time from SOS result time
    if (observation.getResultTime() != null) {
        if (resultTime.equals(phenomenonTime)) {
            empty(OmConstants.QN_OM_20_RESULT_TIME);
            addXlinkHrefAttr("#".concat(phenomenonTime.getGmlId()));
        } else {
            addResultTime(resultTime);
        }
    } else if (phenomenonTime instanceof TimeInstant) {
        // if result time is not set, get result time from phenomenon time
        empty(OmConstants.QN_OM_20_RESULT_TIME);
        addXlinkHrefAttr("#".concat(phenomenonTime.getGmlId()));
    } else if (phenomenonTime instanceof TimePeriod) {
        TimeInstant rsTime = new TimeInstant(((TimePeriod) observation.getPhenomenonTime()).getEnd());
        addResultTime(rsTime);
    }
}
Also used : TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) OmObservation(org.n52.shetland.ogc.om.OmObservation) Time(org.n52.shetland.ogc.gml.time.Time) DateTime(org.joda.time.DateTime) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant)

Example 58 with OmObservation

use of org.n52.shetland.ogc.om.OmObservation 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 59 with OmObservation

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

the class OmEncoderv100 method getEnvelope.

private ReferencedEnvelope getEnvelope(List<OmObservation> sosObservationCollection) {
    ReferencedEnvelope sosEnvelope = new ReferencedEnvelope();
    sosObservationCollection.stream().map(o -> (SamplingFeature) o.getObservationConstellation().getFeatureOfInterest()).forEach(f -> {
        sosEnvelope.setSrid(f.getGeometry().getSRID());
        sosEnvelope.expandToInclude(f.getGeometry().getEnvelopeInternal());
    });
    return sosEnvelope;
}
Also used : SingleObservationValue(org.n52.shetland.ogc.om.SingleObservationValue) BooleanValue(org.n52.shetland.ogc.om.values.BooleanValue) GeometryObservationDocument(net.opengis.om.x10.GeometryObservationDocument) LoggerFactory(org.slf4j.LoggerFactory) SosConstants(org.n52.shetland.ogc.sos.SosConstants) QuantityValue(org.n52.shetland.ogc.om.values.QuantityValue) Time(org.n52.shetland.ogc.gml.time.Time) MultiObservationValues(org.n52.shetland.ogc.om.MultiObservationValues) MeasurementDocument(net.opengis.om.x10.MeasurementDocument) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant) TruthObservationType(net.opengis.om.x10.TruthObservationType) Map(java.util.Map) ObservationStream(org.n52.shetland.ogc.om.ObservationStream) OmObservableProperty(org.n52.shetland.ogc.om.OmObservableProperty) BigInteger(java.math.BigInteger) MeasurementType(net.opengis.om.x10.MeasurementType) ObservationCollectionDocument(net.opengis.om.x10.ObservationCollectionDocument) EncodingException(org.n52.svalbard.encode.exception.EncodingException) N52XmlHelper(org.n52.svalbard.util.N52XmlHelper) ImmutableSet(com.google.common.collect.ImmutableSet) XmlBoolean(org.apache.xmlbeans.XmlBoolean) XmlInteger(org.apache.xmlbeans.XmlInteger) Set(java.util.Set) CountValue(org.n52.shetland.ogc.om.values.CountValue) ObservationPropertyType(net.opengis.om.x10.ObservationPropertyType) GetObservationByIdResponse(org.n52.shetland.ogc.sos.response.GetObservationByIdResponse) Sets(com.google.common.collect.Sets) List(java.util.List) CountObservationDocument(net.opengis.om.x10.CountObservationDocument) GmlConstants(org.n52.shetland.ogc.gml.GmlConstants) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) SchemaLocation(org.n52.shetland.w3c.SchemaLocation) GeometryValue(org.n52.shetland.ogc.om.values.GeometryValue) CategoryValue(org.n52.shetland.ogc.om.values.CategoryValue) CollectionHelper(org.n52.shetland.util.CollectionHelper) ObservationType(net.opengis.om.x10.ObservationType) SweHelper(org.n52.svalbard.util.SweHelper) SupportedType(org.n52.shetland.ogc.SupportedType) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) Joiner(com.google.common.base.Joiner) GetObservationResponse(org.n52.shetland.ogc.sos.response.GetObservationResponse) OmConstants(org.n52.shetland.ogc.om.OmConstants) CategoryObservationType(net.opengis.om.x10.CategoryObservationType) StreamingValue(org.n52.shetland.ogc.om.StreamingValue) XmlHelper(org.n52.svalbard.util.XmlHelper) MediaType(org.n52.janmayen.http.MediaType) ReferencedEnvelope(org.n52.shetland.util.ReferencedEnvelope) OmObservation(org.n52.shetland.ogc.om.OmObservation) GmlHelper(org.n52.svalbard.util.GmlHelper) ObservationCollectionType(net.opengis.om.x10.ObservationCollectionType) ArrayList(java.util.ArrayList) TruthObservationDocument(net.opengis.om.x10.TruthObservationDocument) Inject(javax.inject.Inject) SamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature) Strings(com.google.common.base.Strings) ObservationDocument(net.opengis.om.x10.ObservationDocument) OmCompositePhenomenon(org.n52.shetland.ogc.om.OmCompositePhenomenon) OMHelper(org.n52.shetland.util.OMHelper) SweConstants(org.n52.shetland.ogc.swe.SweConstants) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException) XmlObject(org.apache.xmlbeans.XmlObject) TextValue(org.n52.shetland.ogc.om.values.TextValue) LinkedList(java.util.LinkedList) CountObservationType(net.opengis.om.x10.CountObservationType) Sos2Constants(org.n52.shetland.ogc.sos.Sos2Constants) Logger(org.slf4j.Logger) DateTime(org.joda.time.DateTime) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport) GeometryObservationType(net.opengis.om.x10.GeometryObservationType) Sos1Constants(org.n52.shetland.ogc.sos.Sos1Constants) SweDataArray(org.n52.shetland.ogc.swe.SweDataArray) XmlString(org.apache.xmlbeans.XmlString) CodingHelper(org.n52.svalbard.util.CodingHelper) CategoryObservationDocument(net.opengis.om.x10.CategoryObservationDocument) Collections(java.util.Collections) ReferencedEnvelope(org.n52.shetland.util.ReferencedEnvelope) SamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature)

Example 60 with OmObservation

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

the class OmEncoderv100 method addMultiObservationValueToResult.

private void addMultiObservationValueToResult(XmlObject xbResult, OmObservation sosObservation) throws EncodingException {
    SweDataArray dataArray = sweHelper.createSosSweDataArray(sosObservation);
    xbResult.set(encodeObjectToXml(SweConstants.NS_SWE_101, dataArray, EncodingContext.of(XmlBeansEncodingFlags.FOR_OBSERVATION)));
}
Also used : SweDataArray(org.n52.shetland.ogc.swe.SweDataArray)

Aggregations

OmObservation (org.n52.shetland.ogc.om.OmObservation)32 XmlObject (org.apache.xmlbeans.XmlObject)17 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)16 Time (org.n52.shetland.ogc.gml.time.Time)15 EncodingException (org.n52.svalbard.encode.exception.EncodingException)14 DateTime (org.joda.time.DateTime)13 TimePeriod (org.n52.shetland.ogc.gml.time.TimePeriod)11 OmObservableProperty (org.n52.shetland.ogc.om.OmObservableProperty)11 OwsExceptionReport (org.n52.shetland.ogc.ows.exception.OwsExceptionReport)10 XmlString (org.apache.xmlbeans.XmlString)9 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)9 CodeWithAuthority (org.n52.shetland.ogc.gml.CodeWithAuthority)9 MultiObservationValues (org.n52.shetland.ogc.om.MultiObservationValues)7 ObservationStream (org.n52.shetland.ogc.om.ObservationStream)7 SingleObservationValue (org.n52.shetland.ogc.om.SingleObservationValue)7 OmObservationConstellation (org.n52.shetland.ogc.om.OmObservationConstellation)6 SweDataArray (org.n52.shetland.ogc.swe.SweDataArray)6 List (java.util.List)5 SamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature)5 QuantityValue (org.n52.shetland.ogc.om.values.QuantityValue)5