use of org.n52.shetland.ogc.om.TimeLocationValueTriple in project arctic-sea by 52North.
the class TrajectoryObservation method convertSingleValueToMultiValue.
/**
* Convert {@link SingleObservationValue} to {@link TVPValue}
*
* @param singleValue
* Single observation value
* @return Converted TVPValue value
*/
private TLVTValue convertSingleValueToMultiValue(final SingleObservationValue<?> singleValue, Geometry geom) {
final TLVTValue tlvpValue = new TLVTValue();
tlvpValue.setUnit(singleValue.getValue().getUnit());
final TimeLocationValueTriple timeLocationValueTriple = new TimeLocationValueTriple(singleValue.getPhenomenonTime(), singleValue.getValue(), geom);
tlvpValue.addValue(timeLocationValueTriple);
return tlvpValue;
}
use of org.n52.shetland.ogc.om.TimeLocationValueTriple in project arctic-sea by 52North.
the class TrajectoryObservation method setValue.
@SuppressWarnings("rawtypes")
@Override
public void setValue(ObservationValue<?> value) {
if (value instanceof StreamingValue || value.getValue() instanceof TLVTValue) {
super.setValue(value);
} else {
Geometry geometry = null;
if (isSetSpatialFilteringProfileParameter()) {
geometry = getSpatialFilteringProfileParameter().getValue().getValue();
} else {
if (getObservationConstellation().getFeatureOfInterest() instanceof AbstractSamplingFeature && ((AbstractSamplingFeature) getObservationConstellation().getFeatureOfInterest()).isSetGeometry()) {
geometry = ((AbstractSamplingFeature) getObservationConstellation().getFeatureOfInterest()).getGeometry();
}
}
TLVTValue tlvpValue = convertSingleValueToMultiValue((SingleObservationValue<?>) value, geometry);
if (!tlvpValue.isSetUnit() && ((AbstractObservationValue<?>) value).isSetUnit()) {
tlvpValue.setUnit(((AbstractObservationValue<?>) value).getUnit());
}
final MultiObservationValues<List<TimeLocationValueTriple>> multiValue = new MultiObservationValues<List<TimeLocationValueTriple>>();
multiValue.setValue(tlvpValue);
if (!multiValue.isSetObservationID()) {
if (value instanceof AbstractObservationValue && ((AbstractObservationValue) value).isSetObservationID()) {
multiValue.setObservationID(((AbstractObservationValue) value).getObservationID());
} else if (isSetObservationID()) {
multiValue.setObservationID(getObservationID());
}
}
super.setValue(multiValue);
}
}
use of org.n52.shetland.ogc.om.TimeLocationValueTriple in project arctic-sea by 52North.
the class TrajectoryObservationTypeEncoder method createCategoricalTimeseries.
/**
* Encode {@link AbstractObservationValue} to
* {@link CategoricalTimeseriesDocument}
*
* @param observationValue
* The {@link AbstractObservationValue} to encode
* @return The encoded {@link AbstractObservationValue}
* @throws EncodingException
* If an error occurs
*/
private XmlObject createCategoricalTimeseries(AbstractObservationValue<?> observationValue) throws EncodingException {
CategoricalTimeseriesDocument categoricalTimeseriesDoc = CategoricalTimeseriesDocument.Factory.newInstance();
CategoricalTimeseriesType categoricalTimeseries = categoricalTimeseriesDoc.addNewCategoricalTimeseries();
categoricalTimeseries.setId(TIMESERIES_PREFIX + observationValue.getObservationID());
categoricalTimeseries.addNewMetadata().addNewTimeseriesMetadata().addNewTemporalExtent().setHref("#" + observationValue.getPhenomenonTime().getGmlId());
TVPDefaultMetadataPropertyType xbMetaComponent = categoricalTimeseries.addNewDefaultPointMetadata();
DefaultTVPCategoricalMetadataDocument xbDefCateMetaComponent = DefaultTVPCategoricalMetadataDocument.Factory.newInstance();
DefaultCategoricalTVPMetadataType defaultTVPCateMetadata = xbDefCateMetaComponent.addNewDefaultTVPCategoricalMetadata();
String unit = null;
if (observationValue instanceof SingleObservationValue) {
SingleObservationValue<?> singleObservationValue = (SingleObservationValue<?>) observationValue;
unit = singleObservationValue.getValue().getUnit();
if (observationValue.getValue() instanceof TimeLocationValueTriple) {
categoricalTimeseries.addNewPoint().addNewCategoricalTVP().set(encodeTLVT((TimeLocationValueTriple) observationValue.getValue()));
}
} else if (observationValue instanceof MultiObservationValues) {
MultiObservationValues<?> multiObservationValue = (MultiObservationValues<?>) observationValue;
if (multiObservationValue.getValue() instanceof TLVTValue) {
TLVTValue tlvtValue = (TLVTValue) multiObservationValue.getValue();
List<TimeLocationValueTriple> timeLocationValueTriples = tlvtValue.getValue();
unit = tlvtValue.getUnit();
int counter = 0;
for (TimeLocationValueTriple timeLocationValueTriple : timeLocationValueTriples) {
timeLocationValueTriple.getLocation().setUserData(getUserObject(observationValue.getObservationID(), counter));
categoricalTimeseries.addNewPoint().addNewCategoricalTVP().set(encodeTLVT(timeLocationValueTriple));
counter++;
}
}
}
if (unit != null && !unit.isEmpty()) {
defaultTVPCateMetadata.setCodeSpace(unit);
}
xbMetaComponent.set(xbDefCateMetaComponent);
return categoricalTimeseriesDoc;
}
use of org.n52.shetland.ogc.om.TimeLocationValueTriple in project arctic-sea by 52North.
the class TrajectoryObservationTypeEncoder method createMeasurementTimeseries.
/**
* Encode {@link AbstractObservationValue} to
* {@link MeasurementTimeseriesDocument}
*
* @param observationValue
* The {@link AbstractObservationValue} to encode
* @return The encoded {@link AbstractObservationValue}
* @throws EncodingException
* If an error occurs
*/
private XmlObject createMeasurementTimeseries(AbstractObservationValue<?> observationValue) throws EncodingException {
MeasurementTimeseriesDocument measurementTimeseriesDoc = MeasurementTimeseriesDocument.Factory.newInstance();
MeasurementTimeseriesType measurementTimeseries = measurementTimeseriesDoc.addNewMeasurementTimeseries();
if (!observationValue.isSetObservationID()) {
observationValue.setObservationID(JavaHelper.generateID(observationValue.toString()));
}
measurementTimeseries.setId(TIMESERIES_PREFIX + observationValue.getObservationID());
measurementTimeseries.addNewMetadata().addNewTimeseriesMetadata().addNewTemporalExtent().setHref("#" + observationValue.getPhenomenonTime().getGmlId());
TVPDefaultMetadataPropertyType xbMetaComponent = measurementTimeseries.addNewDefaultPointMetadata();
DefaultTVPMeasurementMetadataDocument xbDefMeasureMetaComponent = DefaultTVPMeasurementMetadataDocument.Factory.newInstance();
TVPMeasurementMetadataType defaultTVPMeasurementMetadata = xbDefMeasureMetaComponent.addNewDefaultTVPMeasurementMetadata();
defaultTVPMeasurementMetadata.addNewInterpolationType().setHref("http://www.opengis.net/def/timeseriesType/WaterML/2.0/continuous");
xbDefMeasureMetaComponent.getDefaultTVPMeasurementMetadata().getInterpolationType().setTitle("Instantaneous");
String unit = null;
if (observationValue instanceof SingleObservationValue) {
SingleObservationValue<?> singleObservationValue = (SingleObservationValue<?>) observationValue;
unit = singleObservationValue.getValue().getUnit();
if (observationValue.getValue() instanceof TimeLocationValueTriple) {
measurementTimeseries.addNewPoint().addNewMeasurementTVP().set(encodeTLVT((TimeLocationValueTriple) observationValue.getValue()));
}
} else if (observationValue instanceof MultiObservationValues) {
MultiObservationValues<?> multiObservationValue = (MultiObservationValues<?>) observationValue;
if (multiObservationValue.getValue() instanceof TLVTValue) {
TLVTValue tlvtValue = (TLVTValue) multiObservationValue.getValue();
List<TimeLocationValueTriple> timeLocationValueTriples = tlvtValue.getValue();
unit = tlvtValue.getUnit();
int counter = 0;
for (TimeLocationValueTriple timeLocationValueTriple : timeLocationValueTriples) {
timeLocationValueTriple.getLocation().setUserData(getUserObject(observationValue.getObservationID(), counter));
measurementTimeseries.addNewPoint().addNewMeasurementTVP().set(encodeTLVT(timeLocationValueTriple));
counter++;
}
}
}
if (unit != null && !unit.isEmpty()) {
defaultTVPMeasurementMetadata.addNewUom().setCode(unit);
}
xbMetaComponent.set(xbDefMeasureMetaComponent);
return measurementTimeseriesDoc;
}
use of org.n52.shetland.ogc.om.TimeLocationValueTriple 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;
}
Aggregations