use of org.n52.shetland.ogc.om.MultiObservationValues 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;
}
use of org.n52.shetland.ogc.om.MultiObservationValues in project arctic-sea by 52North.
the class TrajectoryObservationTypeEncoderTest method getQuantityObservation.
private OmObservation getQuantityObservation() throws EncodingException, ParseException, DecodingException, XmlException, IOException {
MultiObservationValues<List<TimeLocationValueTriple>> multiObservationValues = new MultiObservationValues<List<TimeLocationValueTriple>>();
TLVTValue tlvtValue = new TLVTValue();
tlvtValue.addValue(getTimeLocationValueTriple(new QuantityValue(15.6, "C")));
tlvtValue.addValue(getTimeLocationValueTriple(new QuantityValue(16.5, "C")));
tlvtValue.addValue(getTimeLocationValueTriple(new QuantityValue(17.6, "C")));
tlvtValue.addValue(getTimeLocationValueTriple(new QuantityValue(18.7, "C")));
multiObservationValues.setValue(tlvtValue);
OmObservation observation = createObservation();
observation.setValue(multiObservationValues);
return observation;
}
use of org.n52.shetland.ogc.om.MultiObservationValues 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;
}
use of org.n52.shetland.ogc.om.MultiObservationValues in project arctic-sea by 52North.
the class WmlTVPEncoderv20Test method initObjects.
@Before
public void initObjects() {
encoder = new WmlTVPEncoderv20();
MultiValue<List<TimeValuePair>> value = new TVPValue();
String unit = "test-unit";
value.setUnit(unit);
TimeValuePair tvp1 = new TimeValuePair(new TimeInstant(new Date(UTC_TIMESTAMP)), new QuantityValue(52.1234567890));
List<TimeValuePair> valueList = CollectionHelper.list(tvp1);
value.setValue(valueList);
mv = new MultiObservationValues<>();
mv.setValue(value);
}
use of org.n52.shetland.ogc.om.MultiObservationValues in project arctic-sea by 52North.
the class OmObservation method convertSingleValueToMultiValue.
/**
* Convert {@link SingleObservationValue} to {@link TVPValue}.
*
* @param singleValue
* Single observation value
*
* @return Converted TVPValue value
*/
public TVPValue convertSingleValueToMultiValue(final SingleObservationValue<?> singleValue) {
MultiObservationValues<List<TimeValuePair>> multiValue = new MultiObservationValues<>();
TVPValue tvpValue = new TVPValue();
if (singleValue.isSetUnit()) {
tvpValue.setUnit(singleValue.getUnit());
} else if (singleValue.getValue().isSetUnit()) {
tvpValue.setUnit(singleValue.getValue().getUnit());
}
if (singleValue.isSetMetadata()) {
multiValue.setMetadata(singleValue.getMetadata());
}
if (singleValue.isSetDefaultPointMetadata()) {
multiValue.setDefaultPointMetadata(singleValue.getDefaultPointMetadata());
}
TimeValuePair timeValuePair = new TimeValuePair(singleValue.getPhenomenonTime(), singleValue.getValue());
tvpValue.addValue(timeValuePair);
multiValue.setValue(tvpValue);
value = multiValue;
return tvpValue;
}
Aggregations