use of org.n52.shetland.ogc.om.OmObservation in project arctic-sea by 52North.
the class SosDecoderv20 method checkReferencedElements.
private void checkReferencedElements(final List<OmObservation> observations, final Map<String, Time> phenomenonTimes, final Map<String, TimeInstant> resultTimes, final Map<String, AbstractFeature> features) throws DecodingException {
for (final OmObservation observation : observations) {
// phenomenonTime
final Time phenomenonTime = observation.getPhenomenonTime();
if (phenomenonTime.isReferenced()) {
observation.getValue().setPhenomenonTime(phenomenonTimes.get(phenomenonTime.getGmlId()));
}
// resultTime
final TimeInstant resultTime = observation.getResultTime();
if (resultTime.isReferenced()) {
if (resultTimes.containsKey(resultTime.getGmlId())) {
observation.setResultTime(resultTimes.get(resultTime.getGmlId()));
} else if (phenomenonTimes.containsKey(resultTime.getGmlId())) {
final Time iTime = phenomenonTimes.get(resultTime.getGmlId());
if (iTime instanceof TimeInstant) {
observation.setResultTime((TimeInstant) iTime);
} else if (iTime instanceof TimePeriod) {
final TimePeriod timePeriod = (TimePeriod) iTime;
observation.setResultTime(new TimeInstant(timePeriod.getEnd()));
} else {
throw new DecodingException("observation.resultTime", "The time value type is not supported");
}
}
}
// featureOfInterest
final AbstractFeature featureOfInterest = observation.getObservationConstellation().getFeatureOfInterest();
if (featureOfInterest.isReferenced()) {
observation.getObservationConstellation().setFeatureOfInterest(features.get(featureOfInterest.getGmlId()));
}
}
}
use of org.n52.shetland.ogc.om.OmObservation in project arctic-sea by 52North.
the class TrajectoryObservationTypeEncoderTest method getCategoricalObservation.
private OmObservation getCategoricalObservation() throws EncodingException, ParseException, DecodingException, XmlException, IOException {
MultiObservationValues<List<TimeLocationValueTriple>> multiObservationValues = new MultiObservationValues<List<TimeLocationValueTriple>>();
TLVTValue tlvtValue = new TLVTValue();
tlvtValue.addValue(getTimeLocationValueTriple(new CategoryValue("test_1", "test_voc")));
tlvtValue.addValue(getTimeLocationValueTriple(new CategoryValue("test_1", "test_voc")));
tlvtValue.addValue(getTimeLocationValueTriple(new CategoryValue("test_3", "test_voc")));
tlvtValue.addValue(getTimeLocationValueTriple(new CategoryValue("test_4", "test_voc")));
multiObservationValues.setValue(tlvtValue);
OmObservation observation = createObservation();
observation.setValue(multiObservationValues);
return observation;
}
use of org.n52.shetland.ogc.om.OmObservation in project arctic-sea by 52North.
the class TrajectoryObservationTypeEncoderTest method createObservation.
private OmObservation createObservation() throws DecodingException, XmlException, IOException {
DateTime now = new DateTime(DateTimeZone.UTC);
TimeInstant resultTime = new TimeInstant(now);
TrajectoryObservation observation = new TrajectoryObservation();
observation.setObservationID("123");
OmObservationConstellation observationConstellation = new OmObservationConstellation();
observationConstellation.setFeatureOfInterest(new SamplingFeature(new CodeWithAuthority("feature", CODE_SPACE)));
OmObservableProperty observableProperty = new OmObservableProperty(OBSERVABLE_PROPERTY);
observationConstellation.setObservableProperty(observableProperty);
observationConstellation.addOffering(OFFERING);
Process procedure = createProcessFromFile();
observationConstellation.setProcedure(procedure);
observation.setObservationConstellation(observationConstellation);
observation.setResultTime(resultTime);
return observation;
}
use of org.n52.shetland.ogc.om.OmObservation 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.OmObservation in project arctic-sea by 52North.
the class WmlTDREncoderv20 method createDataRecord.
/**
* Create a SOS DataRecord object from SOS observation and encode to
* XmlBeans object
*
* @param sosObservation
* SOS observation
* @return XML DataRecord object
* @throws EncodingException
* If an error occurs
*/
private XmlObject createDataRecord(OmObservation sosObservation) throws EncodingException {
AbstractPhenomenon observableProperty = sosObservation.getObservationConstellation().getObservableProperty();
SweQuantity quantity = new SweQuantity();
quantity.setDefinition(observableProperty.getIdentifier());
quantity.setDescription(observableProperty.getDescription());
if (observableProperty instanceof OmObservableProperty && ((OmObservableProperty) observableProperty).isSetUnit()) {
quantity.setUom(((OmObservableProperty) observableProperty).getUnit());
}
return createDataRecord(quantity, sosObservation.getObservationID());
}
Aggregations