Search in sources :

Example 11 with OmObservableProperty

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

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

the class TrajectoryObservationTypeEncoderTest method createObservation.

private OmObservation createObservation() throws DecodingException, XmlException, IOException {
    DateTime now = new DateTime(DateTimeZone.UTC);
    TimeInstant resultTime = new TimeInstant(now);
    TrajectoryObservation observation = new TrajectoryObservation();
    observation.setObservationID("123");
    OmObservationConstellation observationConstellation = new OmObservationConstellation();
    observationConstellation.setFeatureOfInterest(new SamplingFeature(new CodeWithAuthority("feature", CODE_SPACE)));
    OmObservableProperty observableProperty = new OmObservableProperty(OBSERVABLE_PROPERTY);
    observationConstellation.setObservableProperty(observableProperty);
    observationConstellation.addOffering(OFFERING);
    Process procedure = createProcessFromFile();
    observationConstellation.setProcedure(procedure);
    observation.setObservationConstellation(observationConstellation);
    observation.setResultTime(resultTime);
    return observation;
}
Also used : TrajectoryObservation(org.n52.shetland.inspire.omso.TrajectoryObservation) SamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature) Process(org.n52.shetland.inspire.ompr.Process) CodeWithAuthority(org.n52.shetland.ogc.gml.CodeWithAuthority) OmObservationConstellation(org.n52.shetland.ogc.om.OmObservationConstellation) DateTime(org.joda.time.DateTime) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant) OmObservableProperty(org.n52.shetland.ogc.om.OmObservableProperty)

Example 13 with OmObservableProperty

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

use of org.n52.shetland.ogc.om.OmObservableProperty 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)

Example 15 with OmObservableProperty

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

the class WmlTDREncoderv20 method createDataRecord.

/**
 * Create a SOS DataRecord object from SOS observation and encode to
 * XmlBeans object
 *
 * @param sosObservation
 *            SOS observation
 * @return XML DataRecord object
 * @throws EncodingException
 *             If an error occurs
 */
private XmlObject createDataRecord(OmObservation sosObservation) throws EncodingException {
    AbstractPhenomenon observableProperty = sosObservation.getObservationConstellation().getObservableProperty();
    SweQuantity quantity = new SweQuantity();
    quantity.setDefinition(observableProperty.getIdentifier());
    quantity.setDescription(observableProperty.getDescription());
    if (observableProperty instanceof OmObservableProperty && ((OmObservableProperty) observableProperty).isSetUnit()) {
        quantity.setUom(((OmObservableProperty) observableProperty).getUnit());
    }
    return createDataRecord(quantity, sosObservation.getObservationID());
}
Also used : SweQuantity(org.n52.shetland.ogc.swe.simpleType.SweQuantity) AbstractPhenomenon(org.n52.shetland.ogc.om.AbstractPhenomenon) OmObservableProperty(org.n52.shetland.ogc.om.OmObservableProperty)

Aggregations

OmObservableProperty (org.n52.shetland.ogc.om.OmObservableProperty)14 OmObservationConstellation (org.n52.shetland.ogc.om.OmObservationConstellation)8 CodeWithAuthority (org.n52.shetland.ogc.gml.CodeWithAuthority)5 SamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature)5 OMObservationType (net.opengis.om.x20.OMObservationType)4 Test (org.junit.Test)4 TVPValue (org.n52.shetland.ogc.om.values.TVPValue)4 Matchers.containsString (org.hamcrest.Matchers.containsString)3 DateTime (org.joda.time.DateTime)3 CodeType (org.n52.shetland.ogc.gml.CodeType)3 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)3 MultiObservationValues (org.n52.shetland.ogc.om.MultiObservationValues)3 OmObservation (org.n52.shetland.ogc.om.OmObservation)3 TimeValuePair (org.n52.shetland.ogc.om.TimeValuePair)3 MeasureOrNilReasonListType (net.opengis.gml.x32.MeasureOrNilReasonListType)2 QuantityListDocument (net.opengis.gml.x32.QuantityListDocument)2 DefaultTVPMeasurementMetadataDocument (net.opengis.waterml.x20.DefaultTVPMeasurementMetadataDocument)2 MeasurementTimeseriesDocument (net.opengis.waterml.x20.MeasurementTimeseriesDocument)2 MeasurementTimeseriesType (net.opengis.waterml.x20.MeasurementTimeseriesType)2 TVPDefaultMetadataPropertyType (net.opengis.waterml.x20.TVPDefaultMetadataPropertyType)2