use of org.n52.shetland.ogc.om.values.TVPValue 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;
}
use of org.n52.shetland.ogc.om.values.TVPValue in project arctic-sea by 52North.
the class ObservationEncoder method encodeTVPValue.
private JsonNode encodeTVPValue(TVPValue value) throws EncodingException {
ArrayNode arrayNode = nodeFactory().arrayNode();
for (TimeValuePair tvp : value.getValue()) {
ObjectNode node = nodeFactory().objectNode();
node.set(JSONConstants.TIME, encodeObjectToJson(tvp.getTime()));
node.set(JSONConstants.VALUE, encodeValue(value));
arrayNode.add(node);
}
return arrayNode;
}
use of org.n52.shetland.ogc.om.values.TVPValue in project arctic-sea by 52North.
the class ObservationEncoder method encodeTVPValue.
private JsonNode encodeTVPValue(OmObservation o) throws EncodingException {
TVPValue tvpValue = (TVPValue) o.getValue().getValue();
ObjectNode result = nodeFactory().objectNode();
List<TimeValuePair> values = tvpValue.getValue();
if (values != null && !values.isEmpty()) {
String obsProp = o.getObservationConstellation().getObservableProperty().getIdentifier();
SweTime timeDef = new SweTime();
timeDef.setDefinition(OmConstants.PHENOMENON_TIME);
timeDef.setUom(OmConstants.PHEN_UOM_ISO8601);
SweField timeField = new SweField(OmConstants.PHENOMENON_TIME_NAME, timeDef);
SweField valueField = getFieldForValue(obsProp, values.get(0).getValue());
result.putArray(JSONConstants.FIELDS).add(encodeObjectToJson(timeField)).add(encodeObjectToJson(valueField));
ArrayNode jvalues = result.putArray(JSONConstants.VALUES);
for (TimeValuePair tvp : values) {
if (tvp != null && tvp.getValue() != null && tvp.getValue().isSetValue()) {
jvalues.addArray().add(encodeObjectToJson(tvp.getTime())).add(getTokenForValue(tvp.getValue()));
}
}
}
return result;
}
use of org.n52.shetland.ogc.om.values.TVPValue in project arctic-sea by 52North.
the class WmlTVPEncoderv20XmlStreamWriter method writeResult.
@Override
protected void writeResult() throws XMLStreamException, EncodingException {
start(OmConstants.QN_OM_20_RESULT);
namespace(WaterMLConstants.NS_WML_20_PREFIX, WaterMLConstants.NS_WML_20);
start(WaterMLConstants.QN_MEASUREMENT_TIMESERIES);
OmObservation observation = getElement();
attr(GmlConstants.QN_ID_32, "timeseries." + observation.getObservationID());
writeMeasurementTimeseriesMetadata(observation);
if (observation.getValue() instanceof SingleObservationValue) {
SingleObservationValue<?> observationValue = (SingleObservationValue<?>) observation.getValue();
writeDefaultPointMetadata(observationValue, observationValue.getValue().getUnit());
String time = getTimeString(observationValue.getPhenomenonTime());
writePoint(time, getValue(observation.getValue().getValue()));
close();
} else if (observation.getValue() instanceof MultiObservationValues) {
// XML streaming to client
MultiObservationValues<?> observationValue = (MultiObservationValues<?>) observation.getValue();
writeDefaultPointMetadata(observationValue, observationValue.getValue().getUnit());
TVPValue tvpValue = (TVPValue) observationValue.getValue();
List<TimeValuePair> timeValuePairs = tvpValue.getValue();
for (TimeValuePair timeValuePair : timeValuePairs) {
if (timeValuePair != null) {
writePoint(getTimeString(timeValuePair.getTime()), getValue(timeValuePair.getValue()));
}
}
close();
} else if (observation.getValue() instanceof StreamingValue) {
// Database streaming + XML streaming to client
StreamingValue<?> observationValue = (StreamingValue<?>) observation.getValue();
if (observationValue.isSetUnit()) {
writeDefaultPointMetadata(observationValue, observationValue.getUnit());
} else if (observation.getObservationConstellation().getObservableProperty() instanceof OmObservableProperty && ((OmObservableProperty) observation.getObservationConstellation().getObservableProperty()).isSetUnit()) {
writeDefaultPointMetadata(observationValue, ((OmObservableProperty) observation.getObservationConstellation().getObservableProperty()).getUnit());
} else {
writeDefaultPointMetadata(observationValue, null);
}
try {
while (observationValue.hasNext()) {
TimeValuePair timeValuePair = observationValue.nextValue();
if (timeValuePair != null) {
writePoint(getTimeString(timeValuePair.getTime()), getValue(timeValuePair.getValue()));
}
}
} catch (DateTimeFormatException | OwsExceptionReport e) {
throw new EncodingException(e);
}
close();
} else {
super.writeResult();
}
}
use of org.n52.shetland.ogc.om.values.TVPValue in project arctic-sea by 52North.
the class WmlTDREncoderv20 method createMeasurementDomainRange.
/**
* Create a XML MeasurementTimeseriesDomainRange object from SOS observation
* for om:result
*
* @param sosObservation
* SOS observation
* @return XML MeasurementTimeseriesDomainRange object for om:result
* @throws EncodingException
* If an error occurs
*/
private XmlObject createMeasurementDomainRange(OmObservation sosObservation) throws EncodingException {
if (!sosObservation.getObservationConstellation().isSetObservationType() || (sosObservation.getObservationConstellation().isSetObservationType() && isInvalidObservationType(sosObservation.getObservationConstellation().getObservationType()))) {
throw new UnsupportedEncoderInputException(this, sosObservation.getObservationConstellation().isSetObservationType());
}
MeasurementTimeseriesDomainRangeDocument xbMearuementTimeseriesDomainRangeDoc = MeasurementTimeseriesDomainRangeDocument.Factory.newInstance();
MeasurementTimeseriesCoverageType xbMeasurementTimeseriesDomainRange = xbMearuementTimeseriesDomainRangeDoc.addNewMeasurementTimeseriesDomainRange();
xbMeasurementTimeseriesDomainRange.setId(TIMESERIES_ID_PREFIX + sosObservation.getObservationID());
// set time position list
xbMeasurementTimeseriesDomainRange.addNewDomainSet().set(getTimePositionList(sosObservation));
// initialize unit
AbstractPhenomenon observableProperty = sosObservation.getObservationConstellation().getObservableProperty();
String unit = null;
// create quantity list from values
QuantityListDocument quantityListDoc = QuantityListDocument.Factory.newInstance();
MeasureOrNilReasonListType quantityList = quantityListDoc.addNewQuantityList();
if (sosObservation.getValue() instanceof MultiObservationValues) {
MultiObservationValues<?> observationValue = (MultiObservationValues<?>) sosObservation.getValue();
TVPValue tvpValue = (TVPValue) 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(sosObservation));
// set om:Result
return xbMearuementTimeseriesDomainRangeDoc;
}
Aggregations