use of org.n52.shetland.ogc.om.OmObservation 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;
}
use of org.n52.shetland.ogc.om.OmObservation in project arctic-sea by 52North.
the class TrajectoryObservationTypeEncoderTest method getCountObservation.
private OmObservation getCountObservation() throws EncodingException, ParseException, DecodingException, XmlException, IOException {
MultiObservationValues<List<TimeLocationValueTriple>> multiObservationValues = new MultiObservationValues<List<TimeLocationValueTriple>>();
TLVTValue tlvtValue = new TLVTValue();
tlvtValue.addValue(getTimeLocationValueTriple(new CountValue(15)));
tlvtValue.addValue(getTimeLocationValueTriple(new CountValue(16)));
tlvtValue.addValue(getTimeLocationValueTriple(new CountValue(17)));
tlvtValue.addValue(getTimeLocationValueTriple(new CountValue(18)));
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 GetObservationResponseXmlStreamWriter method writeGetObservationResponseDoc.
private void writeGetObservationResponseDoc() throws XMLStreamException, EncodingException {
start(Sos2StreamingConstants.GET_OBSERVATION_RESPONSE);
namespace(W3CConstants.NS_XLINK_PREFIX, W3CConstants.NS_XLINK);
namespace(SosConstants.NS_SOS_PREFIX, Sos2Constants.NS_SOS_20);
GetObservationResponse response = getElement();
// get observation encoder
ObservationEncoder<XmlObject, OmObservation> encoder = findObservationEncoder(response.getResponseFormat());
// write schemaLocation
schemaLocation(getSchemaLocation(encoder));
EncodingContext ctx = getContext().with(XmlEncoderFlags.ENCODE_NAMESPACE, response.getResponseFormat()).with(XmlBeansEncodingFlags.DOCUMENT).with(StreamingEncoderFlags.EMBEDDED).without(XmlBeansEncodingFlags.PROPERTY_TYPE).without(XmlBeansEncodingFlags.TYPE);
try {
ObservationStream stream = response.getObservationCollection();
if (encoder.shouldObservationsWithSameXBeMerged()) {
stream = stream.merge();
}
while (stream.hasNext()) {
OmObservation o = stream.next();
if (o.getValue() instanceof ObservationStream) {
ObservationStream value = (ObservationStream) o.getValue();
if (encoder.supportsResultStreamingForMergedValues()) {
writeObservationData(ctx, o, encoder);
} else {
while (value.hasNext()) {
writeObservationData(ctx, value.next(), encoder);
}
}
} else {
writeObservationData(ctx, o, encoder);
}
}
} catch (OwsExceptionReport owse) {
throw new EncodingException(owse);
}
end(Sos2StreamingConstants.GET_OBSERVATION_RESPONSE);
}
use of org.n52.shetland.ogc.om.OmObservation in project arctic-sea by 52North.
the class UVFEncoder method getTemporalBBoxFromObservations.
private TimePeriod getTemporalBBoxFromObservations(List<OmObservation> observationCollection) throws EncodingException {
DateTime start = null;
DateTime end = null;
for (OmObservation observation : observationCollection) {
Time phenomenonTime = observation.getPhenomenonTime();
if (phenomenonTime instanceof TimeInstant) {
final DateTime time = ((TimeInstant) phenomenonTime).getTimePosition().getTime();
if (start == null || time.isBefore(start)) {
start = time;
}
if (end == null || time.isAfter(end)) {
end = time;
}
} else {
final DateTime periodStart = ((TimePeriod) phenomenonTime).getStart();
if (start == null || periodStart.isBefore(start)) {
start = periodStart;
}
final DateTime periodEnd = ((TimePeriod) phenomenonTime).getEnd();
if (end == null || periodEnd.isAfter(end)) {
end = periodEnd;
}
}
}
if (start != null && end != null) {
return new TimePeriod(start, end);
} else {
final String message = "Could not extract centuries from observation collection";
LOGGER.error(message);
throw new EncodingException(message);
}
}
use of org.n52.shetland.ogc.om.OmObservation in project arctic-sea by 52North.
the class UVFEncoder method writeLine2.
private void writeLine2(Writer fw, OmObservation o, TimePeriod centuries, String lineEnding) throws IOException {
// 2.Zeile ABFLUSS m3/s 1900 1900
StringBuilder sb = new StringBuilder(39);
// Identifier
AbstractPhenomenon observableProperty = o.getObservationConstellation().getObservableProperty();
String observablePropertyIdentifier = observableProperty.getIdentifier();
if (observablePropertyIdentifier != null && !observablePropertyIdentifier.isEmpty()) {
observablePropertyIdentifier = ensureIdentifierLength(observablePropertyIdentifier, UVFConstants.MAX_IDENTIFIER_LENGTH);
}
sb.append(observablePropertyIdentifier);
fillWithSpaces(sb, UVFConstants.MAX_IDENTIFIER_LENGTH);
// Unit (optional)
String unit = getUnit(o);
if (unit != null && !unit.isEmpty()) {
unit = ensureIdentifierLength(unit, UVFConstants.MAX_IDENTIFIER_LENGTH);
sb.append(" ");
sb.append(unit);
}
fillWithSpaces(sb, 30);
// Centuries
sb.append(centuries.getStart().getCenturyOfEra() + "00 " + centuries.getEnd().getCenturyOfEra() + "00");
writeToFile(fw, sb.toString(), lineEnding);
}
Aggregations