use of org.n52.shetland.ogc.om.ObservationValue 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.ObservationValue 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.ObservationValue 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.ObservationValue 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;
}
use of org.n52.shetland.ogc.om.ObservationValue in project arctic-sea by 52North.
the class WmlTDREncoderv20 method createMeasurementDomainRange.
private XmlObject createMeasurementDomainRange(AbstractObservationValue<?> observationValue) throws EncodingException {
if (!observationValue.isSetObservationType() || (observationValue.isSetObservationType() && isInvalidObservationType(observationValue.getObservationType()))) {
return null;
}
MeasurementTimeseriesDomainRangeDocument xbMearuementTimeseriesDomainRangeDoc = MeasurementTimeseriesDomainRangeDocument.Factory.newInstance();
MeasurementTimeseriesCoverageType xbMeasurementTimeseriesDomainRange = xbMearuementTimeseriesDomainRangeDoc.addNewMeasurementTimeseriesDomainRange();
xbMeasurementTimeseriesDomainRange.setId(TIMESERIES_ID_PREFIX + observationValue.getObservationID());
// set time position list
xbMeasurementTimeseriesDomainRange.addNewDomainSet().set(getTimePositionList(observationValue));
// initialize unit
// AbstractPhenomenon observableProperty =
// observationValue.getObservableProperty();
String unit = null;
// create quantity list from values
QuantityListDocument quantityListDoc = QuantityListDocument.Factory.newInstance();
MeasureOrNilReasonListType quantityList = quantityListDoc.addNewQuantityList();
if (observationValue instanceof MultiObservationValues) {
TVPValue tvpValue = (TVPValue) ((MultiObservationValues<?>) 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(observationValue, unit));
// set om:Result
return xbMearuementTimeseriesDomainRangeDoc;
}
Aggregations