Search in sources :

Example 6 with ObservationValue

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

the class OmDecoderv20 method getResult.

private ObservationValue<?> getResult(OMObservationType omObservation) throws DecodingException {
    XmlObject xbResult = omObservation.getResult();
    if (xbResult.schemaType() == XmlAnyTypeImpl.type) {
        // Template observation for InsertResultTemplate operation
        if (!xbResult.getDomNode().hasChildNodes()) {
            return new SingleObservationValue<>(new NilTemplateValue());
        } else {
            try {
                xbResult = XmlObject.Factory.parse(xbResult.xmlText().trim());
            } catch (XmlException e) {
                LOGGER.error("Error while parsing NamedValueValue", e);
            }
        }
    }
    if (xbResult.schemaType() == XmlBoolean.type) {
        // TruthObservation
        XmlBoolean xbBoolean = (XmlBoolean) xbResult;
        BooleanValue booleanValue = new BooleanValue(xbBoolean.getBooleanValue());
        return new SingleObservationValue<>(booleanValue);
    } else if (xbResult.schemaType() == XmlInteger.type) {
        // CountObservation
        XmlInteger xbInteger = (XmlInteger) xbResult;
        CountValue countValue = new CountValue(Integer.parseInt(xbInteger.getBigIntegerValue().toString()));
        return new SingleObservationValue<>(countValue);
    } else if (xbResult.schemaType() == XmlString.type) {
        // TextObservation
        XmlString xbString = (XmlString) xbResult;
        TextValue stringValue = new TextValue(xbString.getStringValue());
        return new SingleObservationValue<>(stringValue);
    } else {
        // result elements with other encoding like SWE_ARRAY_OBSERVATION
        Object decodedObject = decodeXmlObject(xbResult);
        if (decodedObject instanceof ObservationValue) {
            return (ObservationValue<?>) decodedObject;
        } else if (decodedObject instanceof GmlMeasureType) {
            GmlMeasureType measureType = (GmlMeasureType) decodedObject;
            QuantityValue quantitiyValue = new QuantityValue(measureType.getValue(), measureType.getUnit());
            return new SingleObservationValue<>(quantitiyValue);
        } else if (decodedObject instanceof ReferenceType) {
            if (omObservation.isSetType() && omObservation.getType().isSetHref() && omObservation.getType().getHref().equals(OmConstants.OBS_TYPE_REFERENCE_OBSERVATION)) {
                return new SingleObservationValue<>(new ReferenceValue((ReferenceType) decodedObject));
            }
            return new SingleObservationValue<>(new CategoryValue(((ReferenceType) decodedObject).getHref()));
        } else if (decodedObject instanceof Geometry) {
            return new SingleObservationValue<>(new GeometryValue((Geometry) decodedObject));
        } else if (decodedObject instanceof AbstractGeometry) {
            SingleObservationValue<Geometry> result = new SingleObservationValue<>();
            result.setValue(new GeometryValue(((AbstractGeometry) decodedObject).getGeometry()));
            return result;
        } else if (decodedObject instanceof SweDataArray) {
            return new SingleObservationValue<>(new SweDataArrayValue((SweDataArray) decodedObject));
        } else if (decodedObject instanceof SweDataRecord) {
            return new SingleObservationValue<>(new ComplexValue((SweDataRecord) decodedObject));
        }
        throw new DecodingException(Sos2Constants.InsertObservationParams.observation, "The requested result type '{}' is not supported by this service!", decodedObject.getClass().getSimpleName());
    }
}
Also used : AbstractGeometry(org.n52.shetland.ogc.gml.AbstractGeometry) XmlBoolean(org.apache.xmlbeans.XmlBoolean) ReferenceValue(org.n52.shetland.ogc.om.values.ReferenceValue) XmlInteger(org.apache.xmlbeans.XmlInteger) DecodingException(org.n52.svalbard.decode.exception.DecodingException) ReferenceType(org.n52.shetland.ogc.gml.ReferenceType) SweDataArrayValue(org.n52.shetland.ogc.om.values.SweDataArrayValue) SingleObservationValue(org.n52.shetland.ogc.om.SingleObservationValue) CountValue(org.n52.shetland.ogc.om.values.CountValue) BooleanValue(org.n52.shetland.ogc.om.values.BooleanValue) ComplexValue(org.n52.shetland.ogc.om.values.ComplexValue) XmlString(org.apache.xmlbeans.XmlString) SweDataArray(org.n52.shetland.ogc.swe.SweDataArray) Geometry(org.locationtech.jts.geom.Geometry) AbstractGeometry(org.n52.shetland.ogc.gml.AbstractGeometry) GeometryValue(org.n52.shetland.ogc.om.values.GeometryValue) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) XmlException(org.apache.xmlbeans.XmlException) TextValue(org.n52.shetland.ogc.om.values.TextValue) QuantityValue(org.n52.shetland.ogc.om.values.QuantityValue) CategoryValue(org.n52.shetland.ogc.om.values.CategoryValue) XmlObject(org.apache.xmlbeans.XmlObject) XmlObject(org.apache.xmlbeans.XmlObject) SingleObservationValue(org.n52.shetland.ogc.om.SingleObservationValue) ObservationValue(org.n52.shetland.ogc.om.ObservationValue) NilTemplateValue(org.n52.shetland.ogc.om.values.NilTemplateValue) GmlMeasureType(org.n52.shetland.ogc.gml.GmlMeasureType)

Example 7 with ObservationValue

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

the class OmEncoderv100 method addSingleObservationToResult.

// FIXME String.equals(QName) !?
private void addSingleObservationToResult(XmlObject xbResult, OmObservation sosObservation) throws EncodingException {
    String observationType = sosObservation.getObservationConstellation().getObservationType();
    SingleObservationValue<?> observationValue = (SingleObservationValue<?>) sosObservation.getValue();
    if (observationValue.getValue() instanceof QuantityValue) {
        QuantityValue quantityValue = (QuantityValue) observationValue.getValue();
        xbResult.set(encodeObjectToXml(GmlConstants.NS_GML, quantityValue));
    } else if (observationValue.getValue() instanceof CountValue) {
        CountValue countValue = (CountValue) observationValue.getValue();
        XmlInteger xbInteger = XmlInteger.Factory.newInstance(getXmlOptions());
        if (countValue.getValue() != null && countValue.getValue() != Integer.MIN_VALUE) {
            xbInteger.setBigIntegerValue(new BigInteger(countValue.getValue().toString()));
        } else {
            xbInteger.setNil();
        }
        xbResult.set(xbInteger);
    } else if (observationValue.getValue() instanceof TextValue) {
        TextValue textValue = (TextValue) observationValue.getValue();
        XmlString xbString = XmlString.Factory.newInstance(getXmlOptions());
        if (textValue.getValue() != null && !textValue.getValue().isEmpty()) {
            xbString.setStringValue(textValue.getValue());
        } else {
            xbString.setNil();
        }
        xbResult.set(xbString);
    } else if (observationValue.getValue() instanceof BooleanValue) {
        BooleanValue booleanValue = (BooleanValue) observationValue.getValue();
        XmlBoolean xbBoolean = XmlBoolean.Factory.newInstance(getXmlOptions());
        if (booleanValue.getValue() != null) {
            xbBoolean.setBooleanValue(booleanValue.getValue());
        } else {
            xbBoolean.setNil();
        }
        xbResult.set(xbBoolean);
    } else if (observationValue.getValue() instanceof CategoryValue) {
        CategoryValue categoryValue = (CategoryValue) observationValue.getValue();
        if (categoryValue.getValue() != null && !categoryValue.getValue().isEmpty()) {
            xbResult.set(encodeObjectToXml(GmlConstants.NS_GML, categoryValue, EncodingContext.of(XmlBeansEncodingFlags.GMLID, SosConstants.OBS_ID_PREFIX + sosObservation.getObservationID())));
        } else {
            xbResult.setNil();
        }
    } else if (observationValue.getValue() instanceof GeometryValue) {
        GeometryValue geometryValue = (GeometryValue) observationValue.getValue();
        if (geometryValue.getValue() != null) {
            xbResult.set(encodeObjectToXml(GmlConstants.NS_GML, geometryValue.getValue(), EncodingContext.of(XmlBeansEncodingFlags.GMLID, SosConstants.OBS_ID_PREFIX + sosObservation.getObservationID())));
        } else {
            xbResult.setNil();
        }
    } else if (OmConstants.OBS_TYPE_SWE_ARRAY_OBSERVATION.equals(observationType) || OmConstants.RESULT_MODEL_OBSERVATION.getLocalPart().equals(observationType)) {
        SweDataArray dataArray = sweHelper.createSosSweDataArray(sosObservation);
        xbResult.set(encodeObjectToXml(SweConstants.NS_SWE_101, dataArray, EncodingContext.of(XmlBeansEncodingFlags.FOR_OBSERVATION)));
    }
}
Also used : XmlBoolean(org.apache.xmlbeans.XmlBoolean) XmlInteger(org.apache.xmlbeans.XmlInteger) XmlString(org.apache.xmlbeans.XmlString) XmlString(org.apache.xmlbeans.XmlString) SweDataArray(org.n52.shetland.ogc.swe.SweDataArray) GeometryValue(org.n52.shetland.ogc.om.values.GeometryValue) SingleObservationValue(org.n52.shetland.ogc.om.SingleObservationValue) CountValue(org.n52.shetland.ogc.om.values.CountValue) QuantityValue(org.n52.shetland.ogc.om.values.QuantityValue) TextValue(org.n52.shetland.ogc.om.values.TextValue) BooleanValue(org.n52.shetland.ogc.om.values.BooleanValue) BigInteger(java.math.BigInteger) CategoryValue(org.n52.shetland.ogc.om.values.CategoryValue)

Example 8 with ObservationValue

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

the class TrajectoryObservationTypeEncoder method createCategoricalTimeseries.

/**
 * Encode {@link AbstractObservationValue} to
 * {@link CategoricalTimeseriesDocument}
 *
 * @param observationValue
 *            The {@link AbstractObservationValue} to encode
 * @return The encoded {@link AbstractObservationValue}
 * @throws EncodingException
 *             If an error occurs
 */
private XmlObject createCategoricalTimeseries(AbstractObservationValue<?> observationValue) throws EncodingException {
    CategoricalTimeseriesDocument categoricalTimeseriesDoc = CategoricalTimeseriesDocument.Factory.newInstance();
    CategoricalTimeseriesType categoricalTimeseries = categoricalTimeseriesDoc.addNewCategoricalTimeseries();
    categoricalTimeseries.setId(TIMESERIES_PREFIX + observationValue.getObservationID());
    categoricalTimeseries.addNewMetadata().addNewTimeseriesMetadata().addNewTemporalExtent().setHref("#" + observationValue.getPhenomenonTime().getGmlId());
    TVPDefaultMetadataPropertyType xbMetaComponent = categoricalTimeseries.addNewDefaultPointMetadata();
    DefaultTVPCategoricalMetadataDocument xbDefCateMetaComponent = DefaultTVPCategoricalMetadataDocument.Factory.newInstance();
    DefaultCategoricalTVPMetadataType defaultTVPCateMetadata = xbDefCateMetaComponent.addNewDefaultTVPCategoricalMetadata();
    String unit = null;
    if (observationValue instanceof SingleObservationValue) {
        SingleObservationValue<?> singleObservationValue = (SingleObservationValue<?>) observationValue;
        unit = singleObservationValue.getValue().getUnit();
        if (observationValue.getValue() instanceof TimeLocationValueTriple) {
            categoricalTimeseries.addNewPoint().addNewCategoricalTVP().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));
                categoricalTimeseries.addNewPoint().addNewCategoricalTVP().set(encodeTLVT(timeLocationValueTriple));
                counter++;
            }
        }
    }
    if (unit != null && !unit.isEmpty()) {
        defaultTVPCateMetadata.setCodeSpace(unit);
    }
    xbMetaComponent.set(xbDefCateMetaComponent);
    return categoricalTimeseriesDoc;
}
Also used : DefaultTVPCategoricalMetadataDocument(net.opengis.waterml.x20.DefaultTVPCategoricalMetadataDocument) CategoricalTimeseriesDocument(net.opengis.waterml.x20.CategoricalTimeseriesDocument) SingleObservationValue(org.n52.shetland.ogc.om.SingleObservationValue) TVPDefaultMetadataPropertyType(net.opengis.waterml.x20.TVPDefaultMetadataPropertyType) DefaultCategoricalTVPMetadataType(net.opengis.waterml.x20.DefaultCategoricalTVPMetadataType) List(java.util.List) CategoricalTimeseriesType(net.opengis.waterml.x20.CategoricalTimeseriesType) TLVTValue(org.n52.shetland.ogc.om.values.TLVTValue) TimeLocationValueTriple(org.n52.shetland.ogc.om.TimeLocationValueTriple) MultiObservationValues(org.n52.shetland.ogc.om.MultiObservationValues)

Example 9 with ObservationValue

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

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

the class WmlTDREncoderv20 method createDataRecord.

private XmlObject createDataRecord(AbstractObservationValue<?> observationValue, String unit) throws EncodingException {
    // AbstractPhenomenon observableProperty =
    // sosObservation.getObservationConstellation().getObservableProperty();
    SweQuantity quantity = new SweQuantity();
    quantity.setDefinition(observationValue.getObservableProperty());
    quantity.setUom(unit);
    return createDataRecord(quantity, observationValue.getObservationID());
}
Also used : SweQuantity(org.n52.shetland.ogc.swe.simpleType.SweQuantity)

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