use of org.n52.shetland.ogc.om.values.Value in project arctic-sea by 52North.
the class GmlDecoderv311 method parseTimePosition.
private TimeInstant parseTimePosition(TimePositionType xbTimePosition) throws DecodingException {
TimeInstant ti = new TimeInstant();
String timeString = xbTimePosition.getStringValue();
if (timeString != null && !timeString.isEmpty()) {
try {
// TODO better differnetiate between ISO8601 and an
// indeterminate value
DateTime dateTime = DateTimeHelper.parseIsoString2DateTime(timeString);
ti.setValue(dateTime);
ti.setRequestedTimeLength(DateTimeHelper.getTimeLengthBeforeTimeZone(timeString));
} catch (DateTimeParseException ex) {
ti.setIndeterminateValue(new IndeterminateValue(timeString));
}
}
if (xbTimePosition.getIndeterminatePosition() != null) {
ti.setIndeterminateValue(new IndeterminateValue(xbTimePosition.getIndeterminatePosition().toString()));
}
return ti;
}
use of org.n52.shetland.ogc.om.values.Value in project arctic-sea by 52North.
the class AbstractCoverageEncoder method encodeValueList.
/**
* Encode value list of {@link RangeSetType} from {@link DiscreteCoverage}
*
* @param rst
* The {@link RangeSetType} to encode value list for
* @param discreteCoverage
* The {@link DiscreteCoverage} with the value list
* @throws EncodingException
* If an error occurs
*/
protected void encodeValueList(RangeSetType rst, DiscreteCoverage<?> discreteCoverage) throws EncodingException {
List<?> list = getList(discreteCoverage);
Value<?> value = discreteCoverage.getRangeSet().iterator().next();
if (value instanceof BooleanValue) {
BooleanListDocument bld = BooleanListDocument.Factory.newInstance(getXmlOptions());
bld.setBooleanList(list);
rst.set(bld);
} else if (value instanceof CategoryValue || value instanceof TextValue) {
DataBlockType dbt = rst.addNewDataBlock();
dbt.addNewRangeParameters().setHref(discreteCoverage.getRangeParameters());
CoordinatesType ct = dbt.addNewTupleList();
ct.setCs(",");
ct.setStringValue(Joiner.on(",").join(list));
} else if (value instanceof CountValue) {
CountListDocument cld = CountListDocument.Factory.newInstance(getXmlOptions());
cld.setCountList(list);
rst.set(cld);
} else if (value instanceof QuantityValue) {
QuantityListDocument qld = QuantityListDocument.Factory.newInstance(getXmlOptions());
MeasureOrNilReasonListType monrlt = qld.addNewQuantityList();
if (discreteCoverage.isSetUnit()) {
monrlt.setUom(discreteCoverage.getUnit());
} else if (value.isSetUnit()) {
monrlt.setUom(value.getUnit());
}
monrlt.setListValue(list);
rst.set(qld);
}
}
use of org.n52.shetland.ogc.om.values.Value in project arctic-sea by 52North.
the class OgcDecoderv100 method parseTemporalOperatorType.
/**
* parses a single temporal filter of the requests and returns SOS temporal filter
*
* @param xbBinaryTemporalOp XmlObject representing the temporal filter
*
* @return Returns SOS representation of temporal filter
*
* @throws DecodingException if parsing of the element failed
*/
private Object parseTemporalOperatorType(BinaryTemporalOpType xbBinaryTemporalOp) throws DecodingException {
TemporalFilter temporalFilter = new TemporalFilter();
// FIXME local workaround against SOSHelper check value reference
String valueRef = "phenomenonTime";
try {
NodeList nodes = xbBinaryTemporalOp.getDomNode().getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
if (nodes.item(i).getNamespaceURI() != null && !nodes.item(i).getLocalName().equals(FilterConstants.EN_VALUE_REFERENCE)) {
// GML decoder will return TimeInstant or TimePriod
Object timeObject = decodeXmlElement(XmlObject.Factory.parse(nodes.item(i)));
if (timeObject instanceof PropertyNameType) {
PropertyNameType propType = (PropertyNameType) timeObject;
// TODO here apply logic for ogc property
// om:samplingTime etc
// valueRef = propType.getDomNode().getNodeValue();
}
if (timeObject instanceof Time) {
TimeOperator operator;
Time time = (Time) timeObject;
String localName = XmlHelper.getLocalName(xbBinaryTemporalOp);
// change to SOS 1.0. TMDuring kind of
if (localName.equals(TimeOperator.TM_During.name()) && time instanceof TimePeriod) {
operator = TimeOperator.TM_During;
} else if (localName.equals(TimeOperator.TM_Equals.name()) && time instanceof TimeInstant) {
operator = TimeOperator.TM_Equals;
} else if (localName.equals(TimeOperator.TM_After.name()) && time instanceof TimeInstant) {
operator = TimeOperator.TM_After;
} else if (localName.equals(TimeOperator.TM_Before.name()) && time instanceof TimeInstant) {
operator = TimeOperator.TM_Before;
} else {
throw unsupportedTemporalFilterOperand();
}
temporalFilter.setOperator(operator);
temporalFilter.setTime(time);
// actually it should be eg om:samplingTime
temporalFilter.setValueReference(valueRef);
break;
}
}
}
} catch (XmlException xmle) {
throw new DecodingException("Error while parsing temporal filter!", xmle);
}
return temporalFilter;
}
use of org.n52.shetland.ogc.om.values.Value in project arctic-sea by 52North.
the class Iso19139GmdEncoder method encodeEXVerticalExtent.
private XmlObject encodeEXVerticalExtent(EXVerticalExtent exVerticalExtent, EncodingContext context) throws EncodingException {
EXVerticalExtentType exvet = EXVerticalExtentType.Factory.newInstance();
if (exVerticalExtent.isSetId()) {
exvet.setId(exVerticalExtent.getId());
}
if (exVerticalExtent.isSetUuid()) {
exvet.setUuid(exVerticalExtent.getUuid());
}
// min value
Nillable<Double> minNillable = exVerticalExtent.getMinimumValue();
RealPropertyType rptMinValue = exvet.addNewMinimumValue();
if (minNillable.isPresent()) {
rptMinValue.setReal(minNillable.get());
} else {
rptMinValue.setNil();
if (minNillable.hasReason()) {
rptMinValue.setNilReason(minNillable.getNilReason().get());
} else {
rptMinValue.setNilReason(Nillable.missing().get());
}
}
// max value
Nillable<Double> maxNillable = exVerticalExtent.getMaximumValue();
RealPropertyType rptMinMaxValue = exvet.addNewMaximumValue();
if (maxNillable.isPresent()) {
rptMinMaxValue.setReal(maxNillable.get());
} else {
rptMinMaxValue.setNil();
if (maxNillable.hasReason()) {
rptMinMaxValue.setNilReason(maxNillable.getNilReason().get());
} else {
rptMinMaxValue.setNilReason(Nillable.missing().get());
}
}
// verticalCRS
SCCRSPropertyType sccrspt = exvet.addNewVerticalCRS();
Referenceable<ScCRS> verticalCRS = exVerticalExtent.getVerticalCRS();
if (verticalCRS.isReference()) {
Reference reference = verticalCRS.getReference();
reference.getActuate().map(Actuate::toString).map(ActuateType.Enum::forString).ifPresent(sccrspt::setActuate);
reference.getArcrole().ifPresent(sccrspt::setArcrole);
reference.getHref().map(URI::toString).ifPresent(sccrspt::setHref);
reference.getRole().ifPresent(sccrspt::setRole);
reference.getShow().map(Show::toString).map(ShowType.Enum::forString).ifPresent(sccrspt::setShow);
reference.getTitle().ifPresent(sccrspt::setTitle);
reference.getType().map(Type::toString).map(TypeType.Enum::forString).ifPresent(sccrspt::setType);
} else {
if (verticalCRS.isInstance()) {
Nillable<ScCRS> nillable = verticalCRS.getInstance();
if (nillable.isPresent()) {
XmlObject xml = encodeObjectToXml(GmlConstants.NS_GML_32, nillable.get().getAbstractCrs());
if (xml != null && xml instanceof AbstractCRSType) {
final XmlObject substituteElement = XmlHelper.substituteElement(sccrspt.addNewAbstractCRS(), xml);
substituteElement.set(xml);
} else {
sccrspt.setNil();
sccrspt.setNilReason(Nillable.missing().get());
}
} else {
sccrspt.setNil();
if (nillable.hasReason()) {
sccrspt.setNilReason(nillable.getNilReason().get());
} else {
sccrspt.setNilReason(Nillable.missing().get());
}
}
}
}
if (context.has(XmlBeansEncodingFlags.PROPERTY_TYPE)) {
EXVerticalExtentPropertyType exvept = EXVerticalExtentPropertyType.Factory.newInstance(getXmlOptions());
exvept.setEXVerticalExtent(exvet);
return exvept;
} else if (context.has(XmlBeansEncodingFlags.DOCUMENT)) {
EXVerticalExtentDocument exved = EXVerticalExtentDocument.Factory.newInstance(getXmlOptions());
exved.setEXVerticalExtent(exvet);
return exved;
}
return exvet;
}
use of org.n52.shetland.ogc.om.values.Value 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);
}
}
Aggregations