use of org.n52.shetland.ogc.om.AbstractObservationValue in project arctic-sea by 52North.
the class AbstractOmV20XmlStreamWriter method writeResult.
/**
* write om:result to stream
*
* @throws XMLStreamException
* If an error occurs when writing to stream
* @throws EncodingException
* If an error occurs when creating elements to be written
*/
protected void writeResult() throws XMLStreamException, EncodingException {
OmObservation observation = getElement();
if (observation.getValue() instanceof AbstractObservationValue<?>) {
((AbstractObservationValue<?>) observation.getValue()).setValuesForResultEncoding(observation);
}
XmlObject createResult = (XmlObject) getEncoder(getEncodeNamespace().orElse(OmConstants.NS_OM_2), observation.getValue()).encode(observation.getValue());
if (createResult != null) {
if (createResult.xmlText().contains(XML_FRAGMENT)) {
XmlObject set = OMObservationType.Factory.newInstance(getXmlOptions()).addNewResult().set(createResult);
writeXmlObject(set, OmConstants.QN_OM_20_RESULT);
} else {
if (checkResult(createResult)) {
QName name = createResult.schemaType().getName();
String prefix = name.getPrefix();
if (Strings.isNullOrEmpty(prefix)) {
XmlCursor newCursor = createResult.newCursor();
prefix = newCursor.prefixForNamespace(name.getNamespaceURI());
newCursor.setAttributeText(W3CConstants.QN_XSI_TYPE, prefix + ":" + name.getLocalPart());
newCursor.dispose();
}
writeXmlObject(createResult, OmConstants.QN_OM_20_RESULT);
} else {
start(OmConstants.QN_OM_20_RESULT);
writeXmlObject(createResult, OmConstants.QN_OM_20_RESULT);
end(OmConstants.QN_OM_20_RESULT);
}
}
} else {
empty(OmConstants.QN_OM_20_RESULT);
}
}
use of org.n52.shetland.ogc.om.AbstractObservationValue in project arctic-sea by 52North.
the class MultiPointObservation method setValue.
@Override
public void setValue(ObservationValue<?> value) {
if (value.getValue() instanceof MultiPointCoverage) {
super.setValue(value);
} else {
MultiPointCoverage multiPointCoverage = new MultiPointCoverage(getObservationID());
multiPointCoverage.setUnit(((AbstractObservationValue<?>) value).getUnit());
multiPointCoverage.addValue(new PointValuePair(getPoint(), value.getValue()));
super.setValue(new SingleObservationValue<>(value.getPhenomenonTime(), multiPointCoverage));
}
}
use of org.n52.shetland.ogc.om.AbstractObservationValue in project arctic-sea by 52North.
the class PointObservation method setValue.
@Override
public void setValue(ObservationValue<?> value) {
if (value instanceof StreamingValue<?>) {
super.setValue(value);
} else if (value.getValue() instanceof CvDiscretePointCoverage) {
super.setValue(value);
} else {
CvDiscretePointCoverage cvDiscretePointCoverage = new CvDiscretePointCoverage(getObservationID());
cvDiscretePointCoverage.setRangeType(new ReferenceType(getObservationConstellation().getObservablePropertyIdentifier()));
cvDiscretePointCoverage.setUnit(((AbstractObservationValue<?>) value).getUnit());
Geometry geometry = null;
String domainExtent = "";
if (isSetSpatialFilteringProfileParameter() && getSpatialFilteringProfileParameter().getValue() instanceof GeometryValue) {
GeometryValue geometryValue = (GeometryValue) getSpatialFilteringProfileParameter().getValue();
geometry = getSpatialFilteringProfileParameter().getValue().getValue();
domainExtent = geometryValue.getGmlId();
} else if (checkForFeatureGeometry(this)) {
geometry = getGeometryFromFeature(this);
domainExtent = getObservationConstellation().getFeatureOfInterest().getGmlId();
}
if (geometry != null) {
cvDiscretePointCoverage.setDomainExtent("#" + geometry.getGeometryType() + "_" + domainExtent);
Point point = null;
if (geometry instanceof Point) {
point = (Point) geometry;
} else {
point = geometry.getCentroid();
}
cvDiscretePointCoverage.setValue(new PointValuePair(point, value.getValue()));
}
super.setValue(new SingleObservationValue<>(value.getPhenomenonTime(), cvDiscretePointCoverage));
}
}
use of org.n52.shetland.ogc.om.AbstractObservationValue 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;
}
use of org.n52.shetland.ogc.om.AbstractObservationValue in project arctic-sea by 52North.
the class WmlTDREncoderv20 method getTimePositionList.
private TimePositionListDocument getTimePositionList(AbstractObservationValue<?> observationValue) throws EncodingException {
TimePositionListDocument timePositionListDoc = TimePositionListDocument.Factory.newInstance();
TimePositionListType timePositionList = timePositionListDoc.addNewTimePositionList();
timePositionList.setId(TIME_POSITION_LIST_ID_PREFIX + observationValue.getObservationID());
timePositionList.setTimePositionList(getTimeArray((MultiObservationValues<?>) observationValue));
return timePositionListDoc;
}
Aggregations