Search in sources :

Example 26 with SamplingFeature

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));
}
Also used : SFSamplingFeatureType(net.opengis.sampling.x20.SFSamplingFeatureType) OMObservationType(net.opengis.om.x20.OMObservationType) CodeType(org.n52.shetland.ogc.gml.CodeType) SFSamplingFeatureDocument(net.opengis.sampling.x20.SFSamplingFeatureDocument) SamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature) XmlObject(org.apache.xmlbeans.XmlObject) CodeWithAuthority(org.n52.shetland.ogc.gml.CodeWithAuthority) OmObservationConstellation(org.n52.shetland.ogc.om.OmObservationConstellation) SensorML(org.n52.shetland.ogc.sensorML.SensorML) OmObservableProperty(org.n52.shetland.ogc.om.OmObservableProperty) Test(org.junit.Test)

Example 27 with SamplingFeature

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;
}
Also used : SingleObservationValue(org.n52.shetland.ogc.om.SingleObservationValue) BooleanValue(org.n52.shetland.ogc.om.values.BooleanValue) GeometryObservationDocument(net.opengis.om.x10.GeometryObservationDocument) LoggerFactory(org.slf4j.LoggerFactory) SosConstants(org.n52.shetland.ogc.sos.SosConstants) QuantityValue(org.n52.shetland.ogc.om.values.QuantityValue) Time(org.n52.shetland.ogc.gml.time.Time) MultiObservationValues(org.n52.shetland.ogc.om.MultiObservationValues) MeasurementDocument(net.opengis.om.x10.MeasurementDocument) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant) TruthObservationType(net.opengis.om.x10.TruthObservationType) Map(java.util.Map) ObservationStream(org.n52.shetland.ogc.om.ObservationStream) OmObservableProperty(org.n52.shetland.ogc.om.OmObservableProperty) BigInteger(java.math.BigInteger) MeasurementType(net.opengis.om.x10.MeasurementType) ObservationCollectionDocument(net.opengis.om.x10.ObservationCollectionDocument) EncodingException(org.n52.svalbard.encode.exception.EncodingException) N52XmlHelper(org.n52.svalbard.util.N52XmlHelper) ImmutableSet(com.google.common.collect.ImmutableSet) XmlBoolean(org.apache.xmlbeans.XmlBoolean) XmlInteger(org.apache.xmlbeans.XmlInteger) Set(java.util.Set) CountValue(org.n52.shetland.ogc.om.values.CountValue) ObservationPropertyType(net.opengis.om.x10.ObservationPropertyType) GetObservationByIdResponse(org.n52.shetland.ogc.sos.response.GetObservationByIdResponse) Sets(com.google.common.collect.Sets) List(java.util.List) CountObservationDocument(net.opengis.om.x10.CountObservationDocument) GmlConstants(org.n52.shetland.ogc.gml.GmlConstants) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) SchemaLocation(org.n52.shetland.w3c.SchemaLocation) GeometryValue(org.n52.shetland.ogc.om.values.GeometryValue) CategoryValue(org.n52.shetland.ogc.om.values.CategoryValue) CollectionHelper(org.n52.shetland.util.CollectionHelper) ObservationType(net.opengis.om.x10.ObservationType) SweHelper(org.n52.svalbard.util.SweHelper) SupportedType(org.n52.shetland.ogc.SupportedType) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) Joiner(com.google.common.base.Joiner) GetObservationResponse(org.n52.shetland.ogc.sos.response.GetObservationResponse) OmConstants(org.n52.shetland.ogc.om.OmConstants) CategoryObservationType(net.opengis.om.x10.CategoryObservationType) StreamingValue(org.n52.shetland.ogc.om.StreamingValue) XmlHelper(org.n52.svalbard.util.XmlHelper) MediaType(org.n52.janmayen.http.MediaType) ReferencedEnvelope(org.n52.shetland.util.ReferencedEnvelope) OmObservation(org.n52.shetland.ogc.om.OmObservation) GmlHelper(org.n52.svalbard.util.GmlHelper) ObservationCollectionType(net.opengis.om.x10.ObservationCollectionType) ArrayList(java.util.ArrayList) TruthObservationDocument(net.opengis.om.x10.TruthObservationDocument) Inject(javax.inject.Inject) SamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature) Strings(com.google.common.base.Strings) ObservationDocument(net.opengis.om.x10.ObservationDocument) OmCompositePhenomenon(org.n52.shetland.ogc.om.OmCompositePhenomenon) OMHelper(org.n52.shetland.util.OMHelper) SweConstants(org.n52.shetland.ogc.swe.SweConstants) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException) XmlObject(org.apache.xmlbeans.XmlObject) TextValue(org.n52.shetland.ogc.om.values.TextValue) LinkedList(java.util.LinkedList) CountObservationType(net.opengis.om.x10.CountObservationType) Sos2Constants(org.n52.shetland.ogc.sos.Sos2Constants) Logger(org.slf4j.Logger) DateTime(org.joda.time.DateTime) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport) GeometryObservationType(net.opengis.om.x10.GeometryObservationType) Sos1Constants(org.n52.shetland.ogc.sos.Sos1Constants) SweDataArray(org.n52.shetland.ogc.swe.SweDataArray) XmlString(org.apache.xmlbeans.XmlString) CodingHelper(org.n52.svalbard.util.CodingHelper) CategoryObservationDocument(net.opengis.om.x10.CategoryObservationDocument) Collections(java.util.Collections) ReferencedEnvelope(org.n52.shetland.util.ReferencedEnvelope) SamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature)

Example 28 with SamplingFeature

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;
}
Also used : TrajectoryObservation(org.n52.shetland.inspire.omso.TrajectoryObservation) SamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature) Process(org.n52.shetland.inspire.ompr.Process) CodeWithAuthority(org.n52.shetland.ogc.gml.CodeWithAuthority) OmObservationConstellation(org.n52.shetland.ogc.om.OmObservationConstellation) DateTime(org.joda.time.DateTime) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant) OmObservableProperty(org.n52.shetland.ogc.om.OmObservableProperty)

Example 29 with SamplingFeature

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);
}
Also used : SFSpatialSamplingFeatureDocument(net.opengis.samplingSpatial.x20.SFSpatialSamplingFeatureDocument) AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) EncodingException(org.n52.svalbard.encode.exception.EncodingException) XmlException(org.apache.xmlbeans.XmlException) XmlObject(org.apache.xmlbeans.XmlObject) SFSpatialSamplingFeatureType(net.opengis.samplingSpatial.x20.SFSpatialSamplingFeatureType) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)

Aggregations

SamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature)25 CodeWithAuthority (org.n52.shetland.ogc.gml.CodeWithAuthority)17 XmlObject (org.apache.xmlbeans.XmlObject)11 Test (org.junit.Test)10 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)8 CodeType (org.n52.shetland.ogc.gml.CodeType)8 OmObservationConstellation (org.n52.shetland.ogc.om.OmObservationConstellation)7 AbstractSamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature)7 SamplingFeatureComplex (org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeatureComplex)7 XmlException (org.apache.xmlbeans.XmlException)6 OmObservableProperty (org.n52.shetland.ogc.om.OmObservableProperty)6 EncodingException (org.n52.svalbard.encode.exception.EncodingException)5 ArrayList (java.util.ArrayList)4 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)4 DateTime (org.joda.time.DateTime)3 LineString (org.locationtech.jts.geom.LineString)3 OmObservation (org.n52.shetland.ogc.om.OmObservation)3 FeatureCollection (org.n52.shetland.ogc.om.features.FeatureCollection)3 UnsupportedEncoderInputException (org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)3 FeaturePropertyType (net.opengis.gml.x32.FeaturePropertyType)2