Search in sources :

Example 16 with QuantityValue

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

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

the class GmlEncoderv311 method encode.

@Override
public XmlObject encode(Object element, EncodingContext ctx) throws EncodingException {
    XmlObject encodedObject = null;
    if (element instanceof Time) {
        encodedObject = createTime((Time) element, ctx);
    } else if (element instanceof Geometry) {
        encodedObject = createPosition((Geometry) element, ctx.get(XmlBeansEncodingFlags.GMLID));
    } else if (element instanceof CategoryValue) {
        encodedObject = createReferenceTypeForCategroyValue((CategoryValue) element);
    } else if (element instanceof org.n52.shetland.ogc.gml.ReferenceType) {
        encodedObject = createReferencType((org.n52.shetland.ogc.gml.ReferenceType) element);
    } else if (element instanceof CodeWithAuthority) {
        encodedObject = createCodeWithAuthorityType((CodeWithAuthority) element);
    } else if (element instanceof QuantityValue) {
        encodedObject = createMeasureType((QuantityValue) element);
    } else if (element instanceof org.n52.shetland.ogc.gml.CodeType) {
        encodedObject = createCodeType((org.n52.shetland.ogc.gml.CodeType) element);
    } else if (element instanceof AbstractFeature) {
        encodedObject = createFeature((AbstractFeature) element);
    } else if (element instanceof ReferencedEnvelope) {
        encodedObject = createEnvelope((ReferencedEnvelope) element);
    } else if (element instanceof EnvelopeOrGeometry) {
        EnvelopeOrGeometry geom = (EnvelopeOrGeometry) element;
        if (geom.getGeometry().isPresent()) {
            encodedObject = createPosition(geom.getGeometry().get(), ctx.get(XmlBeansEncodingFlags.GMLID));
        } else if (geom.getEnvelope().isPresent()) {
            encodedObject = createEnvelope(geom.getEnvelope().get());
        } else {
            throw new UnsupportedEncoderInputException(this, element);
        }
    } else if (element instanceof GenericMetaData) {
        encodedObject = createGenericMetaData((GenericMetaData) element, ctx);
    } else {
        throw new UnsupportedEncoderInputException(this, element);
    }
    XmlHelper.validateDocument(encodedObject, EncodingException::new);
    return encodedObject;
}
Also used : GenericMetaData(org.n52.shetland.ogc.gml.GenericMetaData) EncodingException(org.n52.svalbard.encode.exception.EncodingException) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) Time(org.n52.shetland.ogc.gml.time.Time) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException) Geometry(org.locationtech.jts.geom.Geometry) EnvelopeOrGeometry(org.n52.shetland.util.EnvelopeOrGeometry) ReferencedEnvelope(org.n52.shetland.util.ReferencedEnvelope) EnvelopeOrGeometry(org.n52.shetland.util.EnvelopeOrGeometry) QuantityValue(org.n52.shetland.ogc.om.values.QuantityValue) CategoryValue(org.n52.shetland.ogc.om.values.CategoryValue) CodeType(net.opengis.gml.CodeType) XmlObject(org.apache.xmlbeans.XmlObject) CodeWithAuthority(org.n52.shetland.ogc.gml.CodeWithAuthority)

Example 18 with QuantityValue

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

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

the class GmlV321EncoderTest method isMeasureTypeValidWithoutUnitTest.

@Test
public void isMeasureTypeValidWithoutUnitTest() throws OwsExceptionReport, EncodingException {
    QuantityValue quantity = new QuantityValue(2.2);
    XmlObject encode = encoder.encode(quantity);
    assertTrue("Encoded Object is NOT valid", encode.validate());
}
Also used : QuantityValue(org.n52.shetland.ogc.om.values.QuantityValue) XmlObject(org.apache.xmlbeans.XmlObject) Test(org.junit.Test)

Example 20 with QuantityValue

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

the class RectifiedGridCoverageDocumentEncoderTest method getRectifiedGridCoverage.

private RectifiedGridCoverage getRectifiedGridCoverage() {
    RectifiedGridCoverage rgc = new RectifiedGridCoverage("quantity");
    rgc.addValue(new QuantityValue(2.5, "m"), new QuantityValue(10.0));
    rgc.addValue(new QuantityValue(5.0, "m"), new QuantityValue(8.0));
    rgc.addValue(new QuantityValue(10.0, "m"), new QuantityValue(3.0));
    rgc.setUnit("C");
    return rgc;
}
Also used : QuantityValue(org.n52.shetland.ogc.om.values.QuantityValue) RectifiedGridCoverage(org.n52.shetland.ogc.om.values.RectifiedGridCoverage)

Aggregations

QuantityValue (org.n52.shetland.ogc.om.values.QuantityValue)21 QuantityValue (org.n52.io.response.dataset.quantity.QuantityValue)8 CountValue (org.n52.shetland.ogc.om.values.CountValue)7 CategoryValue (org.n52.shetland.ogc.om.values.CategoryValue)6 XmlObject (org.apache.xmlbeans.XmlObject)5 Test (org.junit.Test)5 BooleanValue (org.n52.shetland.ogc.om.values.BooleanValue)5 TextValue (org.n52.shetland.ogc.om.values.TextValue)5 QuantityData (org.n52.io.response.dataset.quantity.QuantityData)4 SingleObservationValue (org.n52.shetland.ogc.om.SingleObservationValue)4 GeometryValue (org.n52.shetland.ogc.om.values.GeometryValue)4 BigDecimal (java.math.BigDecimal)3 List (java.util.List)3 XmlBoolean (org.apache.xmlbeans.XmlBoolean)3 XmlInteger (org.apache.xmlbeans.XmlInteger)3 XmlString (org.apache.xmlbeans.XmlString)3 Geometry (org.locationtech.jts.geom.Geometry)3 SweBoolean (org.n52.shetland.ogc.swe.simpleType.SweBoolean)3 Coordinate (com.vividsolutions.jts.geom.Coordinate)2 ArrayList (java.util.ArrayList)2