use of org.n52.shetland.ogc.om.OmObservation in project arctic-sea by 52North.
the class AbstractOmV20XmlStreamWriter method writeObservation.
/**
* Write {@link OmObservation} XML encoded to stream
*
* @param observation the observation
*
* @throws XMLStreamException If an error occurs when writing to stream
* @throws EncodingException If an error occurs when creating elements to be written If an error occurs when
* creating elements to be written
*/
protected void writeObservation(OmObservation observation) throws XMLStreamException, EncodingException {
start(getDocumentName());
namespace(W3CConstants.NS_XLINK_PREFIX, W3CConstants.NS_XLINK);
namespace(W3CConstants.NS_XSI_PREFIX, W3CConstants.NS_XSI);
namespace(OmConstants.NS_OM_PREFIX, OmConstants.NS_OM_2);
namespace(GmlConstants.NS_GML_PREFIX, GmlConstants.NS_GML_32);
writeAddtitionalNamespaces();
String observationID = addGmlId(observation);
checkAndWriteIdentifier();
checkAndWriteName();
checkAndWriteDescription();
if (observation.getObservationConstellation().isSetObservationType()) {
writeObservationType(observation.getObservationConstellation().getObservationType());
}
if (observation.isSetMetaDataProperty()) {
writeMetaDataProperty(observation.getMetaDataProperty());
}
Time phenomenonTime = observation.getPhenomenonTime();
if (phenomenonTime.getGmlId() == null) {
phenomenonTime.setGmlId(OmConstants.PHENOMENON_TIME_NAME + "_" + observationID);
}
writePhenomenonTime(phenomenonTime);
writeResultTime();
if (observation.isSetValidTime()) {
writeValidTime(observation.getValidTime());
}
writeProcedure();
if (observation.isSetParameter()) {
writeParameter();
}
writeObservableProperty();
writeFeatureOfIntererst();
writeResult();
end(getDocumentName());
}
use of org.n52.shetland.ogc.om.OmObservation in project arctic-sea by 52North.
the class AbstractOmV20XmlStreamWriter method writeResultTime.
/**
* Write om:resultTime 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 writeResultTime() throws XMLStreamException, EncodingException {
OmObservation observation = getElement();
TimeInstant resultTime = observation.getResultTime();
Time phenomenonTime = observation.getPhenomenonTime();
// get result time from SOS result time
if (observation.getResultTime() != null) {
if (resultTime.equals(phenomenonTime)) {
empty(OmConstants.QN_OM_20_RESULT_TIME);
addXlinkHrefAttr("#".concat(phenomenonTime.getGmlId()));
} else {
addResultTime(resultTime);
}
} else if (phenomenonTime instanceof TimeInstant) {
// if result time is not set, get result time from phenomenon time
empty(OmConstants.QN_OM_20_RESULT_TIME);
addXlinkHrefAttr("#".concat(phenomenonTime.getGmlId()));
} else if (phenomenonTime instanceof TimePeriod) {
TimeInstant rsTime = new TimeInstant(((TimePeriod) observation.getPhenomenonTime()).getEnd());
addResultTime(rsTime);
}
}
use of org.n52.shetland.ogc.om.OmObservation 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.OmObservation in project arctic-sea by 52North.
the class OmEncoderv100 method getEnvelope.
private ReferencedEnvelope getEnvelope(List<OmObservation> sosObservationCollection) {
ReferencedEnvelope sosEnvelope = new ReferencedEnvelope();
sosObservationCollection.stream().map(o -> (SamplingFeature) o.getObservationConstellation().getFeatureOfInterest()).forEach(f -> {
sosEnvelope.setSrid(f.getGeometry().getSRID());
sosEnvelope.expandToInclude(f.getGeometry().getEnvelopeInternal());
});
return sosEnvelope;
}
use of org.n52.shetland.ogc.om.OmObservation in project arctic-sea by 52North.
the class OmEncoderv100 method addMultiObservationValueToResult.
private void addMultiObservationValueToResult(XmlObject xbResult, OmObservation sosObservation) throws EncodingException {
SweDataArray dataArray = sweHelper.createSosSweDataArray(sosObservation);
xbResult.set(encodeObjectToXml(SweConstants.NS_SWE_101, dataArray, EncodingContext.of(XmlBeansEncodingFlags.FOR_OBSERVATION)));
}
Aggregations