use of org.n52.shetland.ogc.om.SingleObservationValue in project arctic-sea by 52North.
the class OmDecoderv20 method getObservationValue.
private ObservationValue<?> getObservationValue(OMObservationType omObservation) throws DecodingException {
Time phenomenonTime = getPhenomenonTime(omObservation);
ObservationValue<?> observationValue;
if (!omObservation.getResult().getDomNode().hasChildNodes() && phenomenonTime.isSetNilReason() && phenomenonTime.getNilReason().equals(NilReason.template)) {
observationValue = new SingleObservationValue<>(new NilTemplateValue());
} else {
observationValue = getResult(omObservation);
}
observationValue.setPhenomenonTime(phenomenonTime);
return observationValue;
}
use of org.n52.shetland.ogc.om.SingleObservationValue in project arctic-sea by 52North.
the class InsertObservationRequestEncoderTest method createInsertObservationRequest.
private InsertObservationRequest createInsertObservationRequest() throws InvalidSridException, ParseException {
SamplingFeature samplingFeature = new SamplingFeature(new CodeWithAuthority("test-feature-uri"));
samplingFeature.setName(new CodeType("test-feature-name"));
samplingFeature.setSampledFeatures(Arrays.asList(new SamplingFeature(new CodeWithAuthority("test-parent-feature-uri"))));
samplingFeature.setGeometry(JTSHelper.createGeometryFromWKT("POINT(52.0 42.0)", 4326));
PhysicalSystem procedure = new PhysicalSystem();
procedure.setIdentifier("test-procedure");
OmObservationConstellation observationConstellation = new OmObservationConstellation();
observationConstellation.setGmlId("o1");
observationConstellation.setObservationType(OmConstants.OBS_TYPE_MEASUREMENT);
observationConstellation.setObservableProperty(new OmObservableProperty("test-property"));
observationConstellation.setFeatureOfInterest(samplingFeature);
observationConstellation.setProcedure(procedure);
TimeInstant time = new TimeInstant(new Date(0));
QuantityValue quantity = new QuantityValue(23.0, "test-uom");
ObservationValue<?> value = new SingleObservationValue<>(time, quantity);
OmObservation omObservation = new OmObservation();
omObservation.setObservationConstellation(observationConstellation);
omObservation.setResultTime(time);
omObservation.setValue(value);
InsertObservationRequest request = new InsertObservationRequest("SOS", "2.0.0");
request.setOfferings(Arrays.asList(OFFERING_ID));
request.addObservation(omObservation);
return request;
}
use of org.n52.shetland.ogc.om.SingleObservationValue 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.SingleObservationValue in project arctic-sea by 52North.
the class WmlTDREncoderv20 method getTimePositionList.
/**
* Create a TimePositionList XML object from time values
*
* @param sosObservation
* SOS observation
* @return XML TimePositionList object
* @throws EncodingException
* If an error occurs
*/
private TimePositionListDocument getTimePositionList(OmObservation sosObservation) throws EncodingException {
TimePositionListDocument timePositionListDoc = TimePositionListDocument.Factory.newInstance();
TimePositionListType timePositionList = timePositionListDoc.addNewTimePositionList();
timePositionList.setId(TIME_POSITION_LIST_ID_PREFIX + sosObservation.getObservationID());
if (sosObservation.getValue() instanceof SingleObservationValue<?>) {
timePositionList.setTimePositionList(Lists.newArrayList(getTimeString(sosObservation.getValue().getPhenomenonTime())));
} else if (sosObservation.getValue() instanceof MultiObservationValues<?>) {
timePositionList.setTimePositionList(getTimeArray((MultiObservationValues<?>) sosObservation.getValue()));
}
return timePositionListDoc;
}
Aggregations