Search in sources :

Example 6 with CountValue

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

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

the class WmlTVPEncoderv20 method addValues.

private String addValues(MeasurementTimeseriesType measurementTimeseries, ObservationValue<?> observationValue) throws CodedException {
    String unit = null;
    if (observationValue instanceof SingleObservationValue) {
        SingleObservationValue<?> singleObservationValue = (SingleObservationValue<?>) observationValue;
        String time = getTimeString(singleObservationValue.getPhenomenonTime());
        unit = singleObservationValue.getValue().getUnit();
        String value = null;
        if (singleObservationValue.getValue() instanceof QuantityValue) {
            QuantityValue quantityValue = (QuantityValue) singleObservationValue.getValue();
            if (quantityValue.isSetValue()) {
                value = quantityValue.getValue().toPlainString();
            }
        } else if (singleObservationValue.getValue() instanceof CountValue) {
            CountValue countValue = (CountValue) singleObservationValue.getValue();
            if (countValue.getValue() != null) {
                value = Integer.toString(countValue.getValue());
            }
        } else if (singleObservationValue.getValue() instanceof ProfileValue) {
            ProfileValue profileValue = (ProfileValue) singleObservationValue.getValue();
            if (profileValue.isSetValue()) {
                if (profileValue.getValue().iterator().next().getSimpleValue() instanceof QuantityValue) {
                    QuantityValue quantityValue = (QuantityValue) profileValue.getValue().iterator().next().getSimpleValue();
                    if (quantityValue.isSetValue()) {
                        value = Double.toString(quantityValue.getValue().doubleValue());
                    }
                }
            }
        }
        addValuesToMeasurementTVP(measurementTimeseries.addNewPoint().addNewMeasurementTVP(), time, value);
    } else if (observationValue instanceof MultiObservationValues) {
        MultiObservationValues<?> mov = (MultiObservationValues<?>) observationValue;
        TVPValue tvpValue = (TVPValue) mov.getValue();
        List<TimeValuePair> timeValuePairs = tvpValue.getValue();
        unit = tvpValue.getUnit();
        for (TimeValuePair timeValuePair : timeValuePairs) {
            String time = getTimeString(timeValuePair.getTime());
            String value = null;
            if (timeValuePair.getValue() instanceof QuantityValue) {
                QuantityValue quantityValue = (QuantityValue) timeValuePair.getValue();
                if (quantityValue.isSetValue()) {
                    value = quantityValue.getValue().toPlainString();
                }
            } else if (timeValuePair.getValue() instanceof ProfileValue) {
                ProfileValue profileValue = (ProfileValue) timeValuePair.getValue();
                if (profileValue.isSetValue()) {
                    if (profileValue.getValue().iterator().next().getSimpleValue() instanceof QuantityValue) {
                        QuantityValue quantityValue = (QuantityValue) profileValue.getValue().iterator().next().getSimpleValue();
                        if (quantityValue.isSetValue()) {
                            value = Double.toString(quantityValue.getValue().doubleValue());
                        }
                    }
                }
            } else if (timeValuePair.getValue() instanceof CountValue) {
                CountValue countValue = (CountValue) timeValuePair.getValue();
                if (countValue.isSetValue()) {
                    value = Integer.toString(countValue.getValue());
                }
            } else {
                throw new NoApplicableCodeException().withMessage("The types of values '%s' is not yet supported", mov.getValue().getClass().getSimpleName());
            }
            addValuesToMeasurementTVP(measurementTimeseries.addNewPoint().addNewMeasurementTVP(), time, value);
        }
    }
    return unit;
}
Also used : SingleObservationValue(org.n52.shetland.ogc.om.SingleObservationValue) TVPValue(org.n52.shetland.ogc.om.values.TVPValue) CountValue(org.n52.shetland.ogc.om.values.CountValue) QuantityValue(org.n52.shetland.ogc.om.values.QuantityValue) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) List(java.util.List) MultiObservationValues(org.n52.shetland.ogc.om.MultiObservationValues) ProfileValue(org.n52.shetland.ogc.om.values.ProfileValue) TimeValuePair(org.n52.shetland.ogc.om.TimeValuePair)

Example 8 with CountValue

use of org.n52.shetland.ogc.om.values.CountValue 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 9 with CountValue

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

the class ObservationDecoder method parseNamedValueValue.

private NamedValue<?> parseNamedValueValue(JsonNode value) throws DecodingException {
    if (value.isTextual()) {
        NamedValue<W3CHrefAttribute> nv = new NamedValue<>();
        nv.setValue(new HrefAttributeValue(new W3CHrefAttribute(value.asText())));
        return nv;
    } else if (value.isBoolean()) {
        NamedValue<Boolean> nv = new NamedValue<>();
        nv.setValue(new BooleanValue(value.asBoolean()));
        return nv;
    } else if (value.isInt()) {
        NamedValue<Integer> nv = new NamedValue<>();
        nv.setValue(new CountValue(value.asInt()));
        return nv;
    } else if (value.isObject()) {
        if (value.has(JSONConstants.CODESPACE)) {
            NamedValue<String> nv = new NamedValue<>();
            nv.setValue(parseCategroyValue(value));
            return nv;
        } else if (value.has(JSONConstants.UOM)) {
            NamedValue<BigDecimal> nv = new NamedValue<>();
            nv.setValue(parseQuantityValue(value));
            return nv;
        } else if (value.has(JSONConstants.COORDINATES)) {
            NamedValue<Geometry> nv = new NamedValue<>();
            nv.setValue(new GeometryValue(geometryDecoder.decodeJSON(value, false)));
            return nv;
        }
    }
    throw new DecodingException("%s is not yet supported", value.toString());
}
Also used : NamedValue(org.n52.shetland.ogc.om.NamedValue) DecodingException(org.n52.svalbard.decode.exception.DecodingException) W3CHrefAttribute(org.n52.shetland.w3c.xlink.W3CHrefAttribute) BigDecimal(java.math.BigDecimal) GeometryValue(org.n52.shetland.ogc.om.values.GeometryValue) CountValue(org.n52.shetland.ogc.om.values.CountValue) BooleanValue(org.n52.shetland.ogc.om.values.BooleanValue) HrefAttributeValue(org.n52.shetland.ogc.om.values.HrefAttributeValue)

Example 10 with CountValue

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

the class AbstractTimeLocationValueTripleTypeEncoder method createMeasurementTimeLocationValueTripleType.

/**
 * Create a {@link MeasurementTimeLocationValueTripleType} from
 * {@link TimeLocationValueTriple}
 *
 * @param timeLocationValueTriple
 *            The {@link TimeLocationValueTriple} to encode
 * @return The encoded {@link TimeLocationValueTriple}
 * @throws EncodingException
 *             If an error occurs
 */
private TimeValuePairType createMeasurementTimeLocationValueTripleType(TimeLocationValueTriple timeLocationValueTriple) throws EncodingException {
    MeasurementTimeLocationValueTripleType mtlvtt = MeasurementTimeLocationValueTripleType.Factory.newInstance();
    mtlvtt.addNewTime().setStringValue(getTimeString(timeLocationValueTriple.getTime()));
    mtlvtt.addNewLocation().addNewPoint().set(encodeGML(timeLocationValueTriple.getLocation()));
    String value = null;
    if (timeLocationValueTriple.getValue() instanceof QuantityValue) {
        QuantityValue quantityValue = (QuantityValue) timeLocationValueTriple.getValue();
        if (quantityValue.isSetValue()) {
            value = quantityValue.getValue().toPlainString();
        }
    } else if (timeLocationValueTriple.getValue() instanceof CountValue) {
        CountValue countValue = (CountValue) timeLocationValueTriple.getValue();
        if (countValue.getValue() != null) {
            value = Integer.toString(countValue.getValue().intValue());
        }
    }
    if (value != null && !value.isEmpty()) {
        mtlvtt.addNewValue().setStringValue(value);
    } else {
        mtlvtt.addNewValue().setNil();
        mtlvtt.addNewMetadata().addNewTVPMeasurementMetadata().addNewNilReason().setNilReason(MISSING);
    }
    return mtlvtt;
}
Also used : CountValue(org.n52.shetland.ogc.om.values.CountValue) MeasurementTimeLocationValueTripleType(eu.europa.ec.inspire.schemas.omso.x30.MeasurementTimeLocationValueTripleType) QuantityValue(org.n52.shetland.ogc.om.values.QuantityValue)

Aggregations

CountValue (org.n52.shetland.ogc.om.values.CountValue)10 QuantityValue (org.n52.shetland.ogc.om.values.QuantityValue)7 BooleanValue (org.n52.shetland.ogc.om.values.BooleanValue)6 CategoryValue (org.n52.shetland.ogc.om.values.CategoryValue)5 GeometryValue (org.n52.shetland.ogc.om.values.GeometryValue)5 TextValue (org.n52.shetland.ogc.om.values.TextValue)5 XmlBoolean (org.apache.xmlbeans.XmlBoolean)3 XmlInteger (org.apache.xmlbeans.XmlInteger)3 XmlString (org.apache.xmlbeans.XmlString)3 Test (org.junit.Test)3 SingleObservationValue (org.n52.shetland.ogc.om.SingleObservationValue)3 BigDecimal (java.math.BigDecimal)2 List (java.util.List)2 XmlException (org.apache.xmlbeans.XmlException)2 XmlObject (org.apache.xmlbeans.XmlObject)2 Geometry (org.locationtech.jts.geom.Geometry)2 BinaryLogicFilter (org.n52.shetland.ogc.filter.BinaryLogicFilter)2 ComparisonFilter (org.n52.shetland.ogc.filter.ComparisonFilter)2 Filter (org.n52.shetland.ogc.filter.Filter)2 SpatialFilter (org.n52.shetland.ogc.filter.SpatialFilter)2