use of org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature in project arctic-sea by 52North.
the class OmEncoderv20Test method shouldEncodeFeatureInObservationTemplate.
@Test
public void shouldEncodeFeatureInObservationTemplate() throws EncodingException, InvalidSridException, ParseException, XmlException, IOException {
//
SamplingFeature featureOfInterest = new SamplingFeature(new CodeWithAuthority(featureIdentifier));
featureOfInterest.setIdentifier(featureIdentifier);
featureOfInterest.setName(new CodeType(featureName));
featureOfInterest.setFeatureType(SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_POINT);
featureOfInterest.setGeometry(JTSHelper.createGeometryFromWKT("POINT (30 10)", 4326));
//
SensorML procedure = new SensorML();
procedure.setIdentifier(procedureIdentifier);
//
OmObservationConstellation observationTemplate = new OmObservationConstellation();
observationTemplate.setObservationType(OmConstants.OBS_TYPE_MEASUREMENT);
observationTemplate.setObservableProperty(new OmObservableProperty(observedProperty));
observationTemplate.setProcedure(procedure);
observationTemplate.setFeatureOfInterest(featureOfInterest);
//
OMObservationType omObservation = (OMObservationType) omEncoderv20.encode(observationTemplate);
//
Assert.assertThat(omObservation.getType().getHref(), Is.is(OmConstants.OBS_TYPE_MEASUREMENT));
Assert.assertThat(omObservation.getPhenomenonTime().isNil(), Is.is(false));
Assert.assertThat(omObservation.getPhenomenonTime().isSetNilReason(), Is.is(true));
Assert.assertThat(omObservation.getPhenomenonTime().getNilReason(), Is.is("template"));
Assert.assertThat(omObservation.getResultTime().isNil(), Is.is(false));
Assert.assertThat(omObservation.getResultTime().isSetNilReason(), Is.is(true));
Assert.assertThat(omObservation.getResultTime().getNilReason(), Is.is("template"));
Assert.assertThat(omObservation.getProcedure().isNil(), Is.is(false));
Assert.assertThat(omObservation.getProcedure().getHref(), Is.is(procedureIdentifier));
Assert.assertThat(omObservation.getObservedProperty().isNil(), Is.is(false));
Assert.assertThat(omObservation.getObservedProperty().getHref(), Is.is(observedProperty));
Assert.assertThat(omObservation.getFeatureOfInterest(), Matchers.notNullValue());
XmlObject xmlObject = XmlObject.Factory.parse(omObservation.getFeatureOfInterest().newInputStream());
Assert.assertThat(xmlObject, Matchers.instanceOf(SFSamplingFeatureDocument.class));
SFSamplingFeatureType feature = ((SFSamplingFeatureDocument) xmlObject).getSFSamplingFeature();
Assert.assertThat(feature.getIdentifier().getStringValue(), Is.is(featureIdentifier));
Assert.assertThat(feature.getNameArray().length, Is.is(1));
Assert.assertThat(feature.getNameArray(0).getStringValue(), Is.is(featureName));
}
use of org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature 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.features.samplingFeatures.SamplingFeature in project arctic-sea by 52North.
the class TrajectoryObservationTypeEncoderTest method createObservation.
private OmObservation createObservation() throws DecodingException, XmlException, IOException {
DateTime now = new DateTime(DateTimeZone.UTC);
TimeInstant resultTime = new TimeInstant(now);
TrajectoryObservation observation = new TrajectoryObservation();
observation.setObservationID("123");
OmObservationConstellation observationConstellation = new OmObservationConstellation();
observationConstellation.setFeatureOfInterest(new SamplingFeature(new CodeWithAuthority("feature", CODE_SPACE)));
OmObservableProperty observableProperty = new OmObservableProperty(OBSERVABLE_PROPERTY);
observationConstellation.setObservableProperty(observableProperty);
observationConstellation.addOffering(OFFERING);
Process procedure = createProcessFromFile();
observationConstellation.setProcedure(procedure);
observation.setObservationConstellation(observationConstellation);
observation.setResultTime(resultTime);
return observation;
}
use of org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature in project arctic-sea by 52North.
the class SamplingEncoderv20 method createFeature.
protected XmlObject createFeature(final AbstractFeature absFeature) throws EncodingException {
if (absFeature instanceof AbstractSamplingFeature) {
final AbstractSamplingFeature sampFeat = (AbstractSamplingFeature) absFeature;
final SFSpatialSamplingFeatureDocument xbSampFeatDoc = SFSpatialSamplingFeatureDocument.Factory.newInstance(getXmlOptions());
if (sampFeat.isSetXml()) {
try {
final XmlObject feature = XmlObject.Factory.parse(sampFeat.getXml(), getXmlOptions());
if (XmlHelper.getNamespace(feature).equals(SfConstants.NS_SAMS)) {
XmlHelper.updateGmlIDs(feature.getDomNode().getFirstChild(), absFeature.getGmlId(), null);
if (feature instanceof SFSpatialSamplingFeatureType) {
xbSampFeatDoc.setSFSpatialSamplingFeature((SFSpatialSamplingFeatureType) feature);
encodeShape(xbSampFeatDoc.getSFSpatialSamplingFeature().getShape(), sampFeat);
addNameDescription(xbSampFeatDoc.getSFSpatialSamplingFeature(), sampFeat);
return xbSampFeatDoc;
}
encodeShape(((SFSpatialSamplingFeatureDocument) feature).getSFSpatialSamplingFeature().getShape(), sampFeat);
addNameDescription(((SFSpatialSamplingFeatureDocument) feature).getSFSpatialSamplingFeature(), sampFeat);
sampFeat.wasEncoded();
return feature;
} else {
return encodeObjectToXml(XmlHelper.getNamespace(feature), absFeature);
}
} catch (final XmlException xmle) {
throw new EncodingException("Error while encoding GetFeatureOfInterest response, invalid samplingFeature description!", xmle);
}
}
final SFSpatialSamplingFeatureType xbSampFeature = xbSampFeatDoc.addNewSFSpatialSamplingFeature();
// TODO: CHECK for all fields set gml:id
addId(xbSampFeature, sampFeat);
addIdentifier(xbSampFeature, sampFeat);
// set type
addFeatureType(xbSampFeature, sampFeat);
// set type
addNameDescription(xbSampFeature, sampFeat);
setMetaDataProperty(xbSampFeature, sampFeat);
// set sampledFeatures
// TODO: CHECK
addSampledFeatures(xbSampFeature, sampFeat);
addParameter(xbSampFeature, sampFeat);
// set position
encodeShape(xbSampFeature.addNewShape(), sampFeat);
sampFeat.wasEncoded();
return xbSampFeatDoc;
}
throw new UnsupportedEncoderInputException(this, absFeature);
}
Aggregations