Search in sources :

Example 6 with AbstractObservationValue

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

the class AbstractOmV20XmlStreamWriter method writeResult.

/**
 * write om:result 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 writeResult() throws XMLStreamException, EncodingException {
    OmObservation observation = getElement();
    if (observation.getValue() instanceof AbstractObservationValue<?>) {
        ((AbstractObservationValue<?>) observation.getValue()).setValuesForResultEncoding(observation);
    }
    XmlObject createResult = (XmlObject) getEncoder(getEncodeNamespace().orElse(OmConstants.NS_OM_2), observation.getValue()).encode(observation.getValue());
    if (createResult != null) {
        if (createResult.xmlText().contains(XML_FRAGMENT)) {
            XmlObject set = OMObservationType.Factory.newInstance(getXmlOptions()).addNewResult().set(createResult);
            writeXmlObject(set, OmConstants.QN_OM_20_RESULT);
        } else {
            if (checkResult(createResult)) {
                QName name = createResult.schemaType().getName();
                String prefix = name.getPrefix();
                if (Strings.isNullOrEmpty(prefix)) {
                    XmlCursor newCursor = createResult.newCursor();
                    prefix = newCursor.prefixForNamespace(name.getNamespaceURI());
                    newCursor.setAttributeText(W3CConstants.QN_XSI_TYPE, prefix + ":" + name.getLocalPart());
                    newCursor.dispose();
                }
                writeXmlObject(createResult, OmConstants.QN_OM_20_RESULT);
            } else {
                start(OmConstants.QN_OM_20_RESULT);
                writeXmlObject(createResult, OmConstants.QN_OM_20_RESULT);
                end(OmConstants.QN_OM_20_RESULT);
            }
        }
    } else {
        empty(OmConstants.QN_OM_20_RESULT);
    }
}
Also used : AbstractObservationValue(org.n52.shetland.ogc.om.AbstractObservationValue) QName(javax.xml.namespace.QName) OmObservation(org.n52.shetland.ogc.om.OmObservation) XmlObject(org.apache.xmlbeans.XmlObject) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 7 with AbstractObservationValue

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

the class MultiPointObservation method setValue.

@Override
public void setValue(ObservationValue<?> value) {
    if (value.getValue() instanceof MultiPointCoverage) {
        super.setValue(value);
    } else {
        MultiPointCoverage multiPointCoverage = new MultiPointCoverage(getObservationID());
        multiPointCoverage.setUnit(((AbstractObservationValue<?>) value).getUnit());
        multiPointCoverage.addValue(new PointValuePair(getPoint(), value.getValue()));
        super.setValue(new SingleObservationValue<>(value.getPhenomenonTime(), multiPointCoverage));
    }
}
Also used : MultiPointCoverage(org.n52.shetland.ogc.om.values.MultiPointCoverage) PointValuePair(org.n52.shetland.ogc.om.PointValuePair)

Example 8 with AbstractObservationValue

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

the class PointObservation method setValue.

@Override
public void setValue(ObservationValue<?> value) {
    if (value instanceof StreamingValue<?>) {
        super.setValue(value);
    } else if (value.getValue() instanceof CvDiscretePointCoverage) {
        super.setValue(value);
    } else {
        CvDiscretePointCoverage cvDiscretePointCoverage = new CvDiscretePointCoverage(getObservationID());
        cvDiscretePointCoverage.setRangeType(new ReferenceType(getObservationConstellation().getObservablePropertyIdentifier()));
        cvDiscretePointCoverage.setUnit(((AbstractObservationValue<?>) value).getUnit());
        Geometry geometry = null;
        String domainExtent = "";
        if (isSetSpatialFilteringProfileParameter() && getSpatialFilteringProfileParameter().getValue() instanceof GeometryValue) {
            GeometryValue geometryValue = (GeometryValue) getSpatialFilteringProfileParameter().getValue();
            geometry = getSpatialFilteringProfileParameter().getValue().getValue();
            domainExtent = geometryValue.getGmlId();
        } else if (checkForFeatureGeometry(this)) {
            geometry = getGeometryFromFeature(this);
            domainExtent = getObservationConstellation().getFeatureOfInterest().getGmlId();
        }
        if (geometry != null) {
            cvDiscretePointCoverage.setDomainExtent("#" + geometry.getGeometryType() + "_" + domainExtent);
            Point point = null;
            if (geometry instanceof Point) {
                point = (Point) geometry;
            } else {
                point = geometry.getCentroid();
            }
            cvDiscretePointCoverage.setValue(new PointValuePair(point, value.getValue()));
        }
        super.setValue(new SingleObservationValue<>(value.getPhenomenonTime(), cvDiscretePointCoverage));
    }
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) CvDiscretePointCoverage(org.n52.shetland.ogc.om.values.CvDiscretePointCoverage) AbstractObservationValue(org.n52.shetland.ogc.om.AbstractObservationValue) GeometryValue(org.n52.shetland.ogc.om.values.GeometryValue) SingleObservationValue(org.n52.shetland.ogc.om.SingleObservationValue) StreamingValue(org.n52.shetland.ogc.om.StreamingValue) Point(org.locationtech.jts.geom.Point) ReferenceType(org.n52.shetland.ogc.gml.ReferenceType) PointValuePair(org.n52.shetland.ogc.om.PointValuePair)

Example 9 with AbstractObservationValue

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

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

the class WmlTDREncoderv20 method getTimePositionList.

private TimePositionListDocument getTimePositionList(AbstractObservationValue<?> observationValue) throws EncodingException {
    TimePositionListDocument timePositionListDoc = TimePositionListDocument.Factory.newInstance();
    TimePositionListType timePositionList = timePositionListDoc.addNewTimePositionList();
    timePositionList.setId(TIME_POSITION_LIST_ID_PREFIX + observationValue.getObservationID());
    timePositionList.setTimePositionList(getTimeArray((MultiObservationValues<?>) observationValue));
    return timePositionListDoc;
}
Also used : TimePositionListDocument(net.opengis.watermlDr.x20.TimePositionListDocument) MultiObservationValues(org.n52.shetland.ogc.om.MultiObservationValues) TimePositionListType(net.opengis.watermlDr.x20.TimePositionListType)

Aggregations

MultiObservationValues (org.n52.shetland.ogc.om.MultiObservationValues)6 SingleObservationValue (org.n52.shetland.ogc.om.SingleObservationValue)4 List (java.util.List)3 TVPDefaultMetadataPropertyType (net.opengis.waterml.x20.TVPDefaultMetadataPropertyType)3 AbstractObservationValue (org.n52.shetland.ogc.om.AbstractObservationValue)3 TimeLocationValueTriple (org.n52.shetland.ogc.om.TimeLocationValueTriple)3 TLVTValue (org.n52.shetland.ogc.om.values.TLVTValue)3 DefaultTVPMeasurementMetadataDocument (net.opengis.waterml.x20.DefaultTVPMeasurementMetadataDocument)2 MeasurementTimeseriesDocument (net.opengis.waterml.x20.MeasurementTimeseriesDocument)2 MeasurementTimeseriesType (net.opengis.waterml.x20.MeasurementTimeseriesType)2 TVPMeasurementMetadataType (net.opengis.waterml.x20.TVPMeasurementMetadataType)2 Geometry (org.locationtech.jts.geom.Geometry)2 PointValuePair (org.n52.shetland.ogc.om.PointValuePair)2 StreamingValue (org.n52.shetland.ogc.om.StreamingValue)2 TimeValuePair (org.n52.shetland.ogc.om.TimeValuePair)2 TVPValue (org.n52.shetland.ogc.om.values.TVPValue)2 QName (javax.xml.namespace.QName)1 MeasureOrNilReasonListType (net.opengis.gml.x32.MeasureOrNilReasonListType)1 QuantityListDocument (net.opengis.gml.x32.QuantityListDocument)1 CategoricalTimeseriesDocument (net.opengis.waterml.x20.CategoricalTimeseriesDocument)1