use of org.n52.shetland.ogc.gml.AbstractFeature in project arctic-sea by 52North.
the class OmEncoderv20Test method createComplexObservation.
protected OmObservation createComplexObservation() {
DateTime now = new DateTime(DateTimeZone.UTC);
TimeInstant resultTime = new TimeInstant(now);
TimeInstant phenomenonTime = new TimeInstant(now);
TimePeriod validTime = new TimePeriod(now.minusMinutes(5), now.plusMinutes(5));
OmObservation observation = new OmObservation();
OmObservationConstellation observationConstellation = new OmObservationConstellation();
observationConstellation.setFeatureOfInterest(new SamplingFeature(new CodeWithAuthority("feature", CODE_SPACE)));
OmCompositePhenomenon observableProperty = new OmCompositePhenomenon(PARENT_OBSERVABLE_PROPERTY);
observableProperty.addPhenomenonComponent(new OmObservableProperty(CHILD_OBSERVABLE_PROPERTY_1));
observableProperty.addPhenomenonComponent(new OmObservableProperty(CHILD_OBSERVABLE_PROPERTY_2));
observableProperty.addPhenomenonComponent(new OmObservableProperty(CHILD_OBSERVABLE_PROPERTY_3));
observableProperty.addPhenomenonComponent(new OmObservableProperty(CHILD_OBSERVABLE_PROPERTY_4));
observationConstellation.setObservableProperty(observableProperty);
observationConstellation.setObservationType(OmConstants.OBS_TYPE_COMPLEX_OBSERVATION);
observationConstellation.addOffering(OFFERING);
AbstractFeature procedure = new SosProcedureDescriptionUnknownType(PROCEDURE);
// procedure.setIdentifier(new CodeWithAuthority(PROCEDURE, CODE_SPACE));
observationConstellation.setProcedure(procedure);
observation.setObservationConstellation(observationConstellation);
observation.setParameter(null);
observation.setResultTime(resultTime);
observation.setTokenSeparator(TOKEN_SEPERATOR);
observation.setTupleSeparator(TUPLE_SEPERATOR);
observation.setValidTime(validTime);
ComplexValue complexValue = new ComplexValue();
SweDataRecord sweDataRecord = new SweDataRecord();
SweQuantity sweQuantity = new SweQuantity();
sweQuantity.setDefinition(CHILD_OBSERVABLE_PROPERTY_1);
sweQuantity.setUom("unit");
sweQuantity.setValue(42.0);
sweDataRecord.addField(new SweField(CHILD_OBSERVABLE_PROPERTY_1_NAME, sweQuantity));
SweBoolean sweBoolean = new SweBoolean();
sweBoolean.setValue(Boolean.TRUE);
sweBoolean.setDefinition(CHILD_OBSERVABLE_PROPERTY_2);
sweDataRecord.addField(new SweField(CHILD_OBSERVABLE_PROPERTY_2_NAME, sweBoolean));
SweCount sweCount = new SweCount();
sweCount.setDefinition(CHILD_OBSERVABLE_PROPERTY_3);
sweCount.setValue(42);
sweDataRecord.addField(new SweField(CHILD_OBSERVABLE_PROPERTY_3_NAME, sweCount));
SweText sweText = new SweText();
sweText.setDefinition(CHILD_OBSERVABLE_PROPERTY_4);
sweText.setValue("42");
sweDataRecord.addField(new SweField(CHILD_OBSERVABLE_PROPERTY_4_NAME, sweText));
SweCategory sweCategory = new SweCategory();
sweCategory.setDefinition(CHILD_OBSERVABLE_PROPERTY_5);
sweCategory.setCodeSpace(CODE_SPACE);
sweCategory.setValue("52");
sweDataRecord.addField(new SweField(CHILD_OBSERVABLE_PROPERTY_5_NAME, sweCategory));
complexValue.setValue(sweDataRecord);
observation.setValue(new SingleObservationValue<>(phenomenonTime, complexValue));
return observation;
}
use of org.n52.shetland.ogc.gml.AbstractFeature in project arctic-sea by 52North.
the class GetFeatureOfInterestResponseDecoderTest method testMultiCurve.
@Test
public void testMultiCurve() throws XmlException, IOException, DecodingException {
try {
XmlObject xml = XmlObject.Factory.parse(getClass().getResourceAsStream("/GetFeatureOfInterestResponse.xml"));
DecoderKey decoderKey = CodingHelper.getDecoderKey(xml);
System.out.println(decoderKey);
Decoder<GetFeatureOfInterestResponse, XmlObject> decoder = decoderRepository.getDecoder(decoderKey);
GetFeatureOfInterestResponse response = decoder.decode(xml);
assertThat(response, is(notNullValue()));
assertThat(response.getAbstractFeature(), is(instanceOf(FeatureCollection.class)));
FeatureCollection abstractFeature = (FeatureCollection) response.getAbstractFeature();
assertThat(abstractFeature.getMembers().size(), is(266));
System.out.println("feature: " + response.getAbstractFeature());
} catch (Throwable t) {
t.printStackTrace(System.out);
throw t;
}
}
use of org.n52.shetland.ogc.gml.AbstractFeature in project arctic-sea by 52North.
the class AqdGetObservationResponseXmlStreamWriter method writeFeatureCollectionDoc.
private void writeFeatureCollectionDoc() throws XMLStreamException, EncodingException {
start(GmlConstants.QN_FEATURE_COLLECTION_32);
addNamespaces();
addSchemaLocations();
FeatureCollection featureCollection = getElement();
addGmlId(featureCollection.getGmlId());
TimeInstant resultTime = new TimeInstant(new DateTime(DateTimeZone.UTC));
for (AbstractFeature abstractFeature : featureCollection.getMembers().values()) {
long start = System.currentTimeMillis();
Encoder<XmlObject, AbstractFeature> encoder = getEncoder(abstractFeature);
if (abstractFeature instanceof OmObservation) {
OmObservation observation = (OmObservation) abstractFeature;
if (observation.getValue() instanceof ObservationStream) {
try {
// start the timer task to write blank strings to avoid
// connection closing
startTimer();
ObservationStream mergeObservation = ((ObservationStream) observation.getValue()).merge();
LOGGER.debug("Observation processing requires {} ms", System.currentTimeMillis() - start);
int count = 0;
while (mergeObservation.hasNext()) {
OmObservation omObservation = mergeObservation.next();
if (abstractFeature.isSetGmlID()) {
if (count == 0) {
omObservation.setGmlId(abstractFeature.getGmlId());
} else {
omObservation.setGmlId(abstractFeature.getGmlId() + "_" + count);
}
count++;
}
omObservation.setResultTime(resultTime);
String xmlTextObservation = prepareObservation(omObservation, encoder);
// stop the timer task
stopTimer();
writeMember(xmlTextObservation);
}
} catch (OwsExceptionReport ex) {
throw new EncodingException(ex);
}
} else {
if (encoder instanceof XmlStreamWriter) {
encoder.encode(abstractFeature, getContext());
} else {
writeMember(abstractFeature, encoder);
}
}
} else {
writeMember(abstractFeature, encoder);
}
LOGGER.debug("Writing member requires {} ms", System.currentTimeMillis() - start);
}
end(GmlConstants.QN_FEATURE_COLLECTION_32);
}
use of org.n52.shetland.ogc.gml.AbstractFeature in project arctic-sea by 52North.
the class GetFeatureOfInterestXmlStreamWriter method writeGetFeatureOfInterestResponseDoc.
private void writeGetFeatureOfInterestResponseDoc() throws XMLStreamException, EncodingException {
start(Sos2StreamingConstants.QN_GET_FEATURE_OF_INTEREST_RESPONSE);
namespace(W3CConstants.NS_XLINK_PREFIX, W3CConstants.NS_XLINK);
namespace(Sos2Constants.NS_SOS_PREFIX, Sos2Constants.NS_SOS_20);
// write schemaLocation
schemaLocation(getSchemaLocation());
AbstractFeature feature = getElement().getAbstractFeature();
if (feature instanceof FeatureCollection) {
for (AbstractFeature f : (FeatureCollection) feature) {
writeFeatureMember(f);
}
} else if (feature instanceof AbstractSamplingFeature) {
writeFeatureMember(feature);
}
end(Sos2StreamingConstants.QN_GET_FEATURE_OF_INTEREST_RESPONSE);
}
use of org.n52.shetland.ogc.gml.AbstractFeature in project arctic-sea by 52North.
the class UpdateSensorRequestDecoder method parseProcedureDesciption.
private SosProcedureDescription<?> parseProcedureDesciption(String xml, String pdf) throws DecodingException {
try {
final XmlObject xb = XmlObject.Factory.parse(xml);
Decoder<?, XmlObject> decoder = getDecoder(new XmlNamespaceDecoderKey(pdf, xb.getClass()));
if (decoder == null) {
throw new DecodingException(JSONConstants.PROCEDURE_DESCRIPTION_FORMAT, "The requested %s is not supported!", JSONConstants.PROCEDURE_DESCRIPTION_FORMAT);
}
Object decode = decoder.decode(xb);
if (decode instanceof SosProcedureDescription<?>) {
return (SosProcedureDescription<?>) decode;
} else if (decode instanceof AbstractFeature) {
return new SosProcedureDescription<AbstractFeature>((AbstractFeature) decode);
} else {
throw new DecodingException("The decoded element {} is not of type {}!", decode.getClass().getName(), AbstractFeature.class.getName());
}
} catch (XmlException xmle) {
throw new DecodingException("Error while parsing procedure description of InsertSensor request!", xmle);
}
}
Aggregations