use of org.n52.shetland.ogc.om.StreamingValue in project arctic-sea by 52North.
the class ProfileObservation method setValue.
@Override
public void setValue(ObservationValue<?> value) {
if (value instanceof StreamingValue<?>) {
super.setValue(value);
} else if (value.getValue() instanceof RectifiedGridCoverage || value.getValue() instanceof ReferencableGridCoverage) {
super.setValue(value);
} else if (value.getValue() instanceof ProfileValue) {
ProfileValue profile = (ProfileValue) value.getValue();
RectifiedGridCoverage rectifiedGridCoverage = new RectifiedGridCoverage(getObservationID());
rectifiedGridCoverage.setUnit(value.getValue().getUnit());
rectifiedGridCoverage.setRangeParameters(getObservationConstellation().getObservablePropertyIdentifier());
List<Coordinate> coordinates = Lists.newArrayList();
int srid = 0;
for (ProfileLevel level : profile.getValue()) {
if (level.isSetLevelEnd()) {
rectifiedGridCoverage.addValue(new QuantityRangeValue(level.getLevelStart().getValue(), level.getLevelEnd().getValue(), level.getLevelStart().getUnit()), level.getSimpleValue());
} else {
rectifiedGridCoverage.addValue(level.getLevelStart(), level.getSimpleValue());
}
if (level.isSetLocation()) {
Coordinate coordinate = level.getLocation().getCoordinate();
coordinate.z = level.getLevelStart().getValue().doubleValue();
coordinates.add(coordinate);
if (srid == 0) {
srid = level.getLocation().getSRID();
}
}
}
if (CollectionHelper.isNotEmpty(coordinates)) {
setFeatureGeometry(coordinates, srid);
}
super.setValue(new SingleObservationValue<>(value.getPhenomenonTime(), rectifiedGridCoverage));
} else {
QuantityValue heightDepth = new QuantityValue(0.0);
if (isSetHeightDepthParameter()) {
heightDepth = (QuantityValue) getHeightDepthParameter().getValue();
removeParameter(getHeightDepthParameter());
}
RectifiedGridCoverage rectifiedGridCoverage = new RectifiedGridCoverage(getObservationID());
rectifiedGridCoverage.setUnit(value.getValue().getUnit());
rectifiedGridCoverage.addValue(heightDepth, value.getValue());
super.setValue(new SingleObservationValue<>(value.getPhenomenonTime(), rectifiedGridCoverage));
}
}
use of org.n52.shetland.ogc.om.StreamingValue 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.StreamingValue in project arctic-sea by 52North.
the class OmEncoderv100 method createObservationCollection.
private XmlObject createObservationCollection(ObservationStream sosObservationCollectionIterable, String resultModel) throws EncodingException {
ObservationCollectionDocument xbObservationCollectionDoc = ObservationCollectionDocument.Factory.newInstance(getXmlOptions());
ObservationCollectionType xbObservationCollection = xbObservationCollectionDoc.addNewObservationCollection();
xbObservationCollection.setId(SosConstants.OBS_COL_ID_PREFIX + new DateTime().getMillis());
if (sosObservationCollectionIterable != null) {
List<OmObservation> sosObservationCollection = new LinkedList<>();
try {
sosObservationCollectionIterable.forEachRemaining(sosObservationCollection::add);
ReferencedEnvelope sosEnvelope = getEnvelope(sosObservationCollection);
Encoder<XmlObject, ReferencedEnvelope> envEncoder = getEncoder(GmlConstants.NS_GML, sosEnvelope);
xbObservationCollection.addNewBoundedBy().addNewEnvelope().set(envEncoder.encode(sosEnvelope));
for (OmObservation sosObservation : sosObservationCollection) {
String observationType = checkObservationType(sosObservation);
if (Strings.isNullOrEmpty(resultModel) || (!Strings.isNullOrEmpty(resultModel) && observationType.equals(resultModel))) {
if (sosObservation.getValue() instanceof StreamingValue) {
StreamingValue<?> streamingValue = (StreamingValue<?>) sosObservation.getValue();
while (streamingValue.hasNext()) {
xbObservationCollection.addNewMember().set(createObservation(streamingValue.next(), null));
}
} else {
xbObservationCollection.addNewMember().set(createObservation(sosObservation, null));
}
} else {
throw new EncodingException("The requested resultModel '%s' is invalid for the resulting observations!", OMHelper.getEncodedResultModelFor(resultModel));
}
}
} catch (OwsExceptionReport owse) {
throw new EncodingException(owse);
}
} else {
ObservationPropertyType xbObservation = xbObservationCollection.addNewMember();
xbObservation.setHref(GmlConstants.NIL_INAPPLICABLE);
}
XmlHelper.makeGmlIdsUnique(xbObservationCollectionDoc.getDomNode());
N52XmlHelper.setSchemaLocationsToDocument(xbObservationCollectionDoc, Sets.newHashSet(N52XmlHelper.getSchemaLocationForSOS100(), N52XmlHelper.getSchemaLocationForOM100(), N52XmlHelper.getSchemaLocationForSA100()));
return xbObservationCollectionDoc;
}
use of org.n52.shetland.ogc.om.StreamingValue in project arctic-sea by 52North.
the class AqdEncoder method encodeGetObservationResponse.
private XmlObject encodeGetObservationResponse(GetObservationResponse response, EncodingContext ctx) throws EncodingException {
try {
FeatureCollection featureCollection = getFeatureCollection(response);
// TODO get FLOW from response
EReportingHeader eReportingHeader = getEReportingHeader(getReportObligationType(response));
featureCollection.addMember(eReportingHeader);
TimePeriod timePeriod = new TimePeriod();
TimeInstant resultTime = new TimeInstant(new DateTime(DateTimeZone.UTC));
int counter = 1;
ObservationStream observationCollection = response.getObservationCollection();
while (observationCollection.hasNext()) {
OmObservation observation = observationCollection.next();
if (observation.getValue() instanceof ObservationStream) {
ObservationStream value = (ObservationStream) observation.getValue();
if (value instanceof StreamingValue) {
value = value.merge();
}
while (value.hasNext()) {
processObservation(value.next(), timePeriod, resultTime, featureCollection, eReportingHeader, counter++);
}
} else {
processObservation(observation, timePeriod, resultTime, featureCollection, eReportingHeader, counter++);
}
}
if (!timePeriod.isEmpty()) {
eReportingHeader.setReportingPeriod(Referenceable.of((Time) timePeriod));
}
return encodeObjectToXml(GmlConstants.NS_GML_32, featureCollection, ctx.with(XmlEncoderFlags.ENCODE_NAMESPACE, OmConstants.NS_OM_2).with(XmlBeansEncodingFlags.DOCUMENT));
} catch (OwsExceptionReport ex) {
throw new EncodingException(ex);
}
}
use of org.n52.shetland.ogc.om.StreamingValue 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));
}
}
Aggregations