Search in sources :

Example 36 with OmObservation

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

the class TrajectoryObservationTypeEncoderTest method getQuantityObservation.

private OmObservation getQuantityObservation() throws EncodingException, ParseException, DecodingException, XmlException, IOException {
    MultiObservationValues<List<TimeLocationValueTriple>> multiObservationValues = new MultiObservationValues<List<TimeLocationValueTriple>>();
    TLVTValue tlvtValue = new TLVTValue();
    tlvtValue.addValue(getTimeLocationValueTriple(new QuantityValue(15.6, "C")));
    tlvtValue.addValue(getTimeLocationValueTriple(new QuantityValue(16.5, "C")));
    tlvtValue.addValue(getTimeLocationValueTriple(new QuantityValue(17.6, "C")));
    tlvtValue.addValue(getTimeLocationValueTriple(new QuantityValue(18.7, "C")));
    multiObservationValues.setValue(tlvtValue);
    OmObservation observation = createObservation();
    observation.setValue(multiObservationValues);
    return observation;
}
Also used : QuantityValue(org.n52.shetland.ogc.om.values.QuantityValue) OmObservation(org.n52.shetland.ogc.om.OmObservation) List(java.util.List) TLVTValue(org.n52.shetland.ogc.om.values.TLVTValue) MultiObservationValues(org.n52.shetland.ogc.om.MultiObservationValues) TimeLocationValueTriple(org.n52.shetland.ogc.om.TimeLocationValueTriple)

Example 37 with OmObservation

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

the class TrajectoryObservationTypeEncoderTest method getCountObservation.

private OmObservation getCountObservation() throws EncodingException, ParseException, DecodingException, XmlException, IOException {
    MultiObservationValues<List<TimeLocationValueTriple>> multiObservationValues = new MultiObservationValues<List<TimeLocationValueTriple>>();
    TLVTValue tlvtValue = new TLVTValue();
    tlvtValue.addValue(getTimeLocationValueTriple(new CountValue(15)));
    tlvtValue.addValue(getTimeLocationValueTriple(new CountValue(16)));
    tlvtValue.addValue(getTimeLocationValueTriple(new CountValue(17)));
    tlvtValue.addValue(getTimeLocationValueTriple(new CountValue(18)));
    multiObservationValues.setValue(tlvtValue);
    OmObservation observation = createObservation();
    observation.setValue(multiObservationValues);
    return observation;
}
Also used : CountValue(org.n52.shetland.ogc.om.values.CountValue) OmObservation(org.n52.shetland.ogc.om.OmObservation) List(java.util.List) TLVTValue(org.n52.shetland.ogc.om.values.TLVTValue) MultiObservationValues(org.n52.shetland.ogc.om.MultiObservationValues) TimeLocationValueTriple(org.n52.shetland.ogc.om.TimeLocationValueTriple)

Example 38 with OmObservation

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

the class GetObservationResponseXmlStreamWriter method writeGetObservationResponseDoc.

private void writeGetObservationResponseDoc() throws XMLStreamException, EncodingException {
    start(Sos2StreamingConstants.GET_OBSERVATION_RESPONSE);
    namespace(W3CConstants.NS_XLINK_PREFIX, W3CConstants.NS_XLINK);
    namespace(SosConstants.NS_SOS_PREFIX, Sos2Constants.NS_SOS_20);
    GetObservationResponse response = getElement();
    // get observation encoder
    ObservationEncoder<XmlObject, OmObservation> encoder = findObservationEncoder(response.getResponseFormat());
    // write schemaLocation
    schemaLocation(getSchemaLocation(encoder));
    EncodingContext ctx = getContext().with(XmlEncoderFlags.ENCODE_NAMESPACE, response.getResponseFormat()).with(XmlBeansEncodingFlags.DOCUMENT).with(StreamingEncoderFlags.EMBEDDED).without(XmlBeansEncodingFlags.PROPERTY_TYPE).without(XmlBeansEncodingFlags.TYPE);
    try {
        ObservationStream stream = response.getObservationCollection();
        if (encoder.shouldObservationsWithSameXBeMerged()) {
            stream = stream.merge();
        }
        while (stream.hasNext()) {
            OmObservation o = stream.next();
            if (o.getValue() instanceof ObservationStream) {
                ObservationStream value = (ObservationStream) o.getValue();
                if (encoder.supportsResultStreamingForMergedValues()) {
                    writeObservationData(ctx, o, encoder);
                } else {
                    while (value.hasNext()) {
                        writeObservationData(ctx, value.next(), encoder);
                    }
                }
            } else {
                writeObservationData(ctx, o, encoder);
            }
        }
    } catch (OwsExceptionReport owse) {
        throw new EncodingException(owse);
    }
    end(Sos2StreamingConstants.GET_OBSERVATION_RESPONSE);
}
Also used : EncodingContext(org.n52.svalbard.encode.EncodingContext) ObservationStream(org.n52.shetland.ogc.om.ObservationStream) EncodingException(org.n52.svalbard.encode.exception.EncodingException) GetObservationResponse(org.n52.shetland.ogc.sos.response.GetObservationResponse) OmObservation(org.n52.shetland.ogc.om.OmObservation) XmlObject(org.apache.xmlbeans.XmlObject) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport)

Example 39 with OmObservation

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

the class UVFEncoder method getTemporalBBoxFromObservations.

private TimePeriod getTemporalBBoxFromObservations(List<OmObservation> observationCollection) throws EncodingException {
    DateTime start = null;
    DateTime end = null;
    for (OmObservation observation : observationCollection) {
        Time phenomenonTime = observation.getPhenomenonTime();
        if (phenomenonTime instanceof TimeInstant) {
            final DateTime time = ((TimeInstant) phenomenonTime).getTimePosition().getTime();
            if (start == null || time.isBefore(start)) {
                start = time;
            }
            if (end == null || time.isAfter(end)) {
                end = time;
            }
        } else {
            final DateTime periodStart = ((TimePeriod) phenomenonTime).getStart();
            if (start == null || periodStart.isBefore(start)) {
                start = periodStart;
            }
            final DateTime periodEnd = ((TimePeriod) phenomenonTime).getEnd();
            if (end == null || periodEnd.isAfter(end)) {
                end = periodEnd;
            }
        }
    }
    if (start != null && end != null) {
        return new TimePeriod(start, end);
    } else {
        final String message = "Could not extract centuries from observation collection";
        LOGGER.error(message);
        throw new EncodingException(message);
    }
}
Also used : EncodingException(org.n52.svalbard.encode.exception.EncodingException) 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) DateTime(org.joda.time.DateTime) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant)

Example 40 with OmObservation

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

the class UVFEncoder method writeLine2.

private void writeLine2(Writer fw, OmObservation o, TimePeriod centuries, String lineEnding) throws IOException {
    // 2.Zeile ABFLUSS m3/s 1900 1900
    StringBuilder sb = new StringBuilder(39);
    // Identifier
    AbstractPhenomenon observableProperty = o.getObservationConstellation().getObservableProperty();
    String observablePropertyIdentifier = observableProperty.getIdentifier();
    if (observablePropertyIdentifier != null && !observablePropertyIdentifier.isEmpty()) {
        observablePropertyIdentifier = ensureIdentifierLength(observablePropertyIdentifier, UVFConstants.MAX_IDENTIFIER_LENGTH);
    }
    sb.append(observablePropertyIdentifier);
    fillWithSpaces(sb, UVFConstants.MAX_IDENTIFIER_LENGTH);
    // Unit (optional)
    String unit = getUnit(o);
    if (unit != null && !unit.isEmpty()) {
        unit = ensureIdentifierLength(unit, UVFConstants.MAX_IDENTIFIER_LENGTH);
        sb.append(" ");
        sb.append(unit);
    }
    fillWithSpaces(sb, 30);
    // Centuries
    sb.append(centuries.getStart().getCenturyOfEra() + "00 " + centuries.getEnd().getCenturyOfEra() + "00");
    writeToFile(fw, sb.toString(), lineEnding);
}
Also used : AbstractPhenomenon(org.n52.shetland.ogc.om.AbstractPhenomenon)

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