Search in sources :

Example 1 with OmObservableProperty

use of org.n52.shetland.ogc.om.OmObservableProperty in project arctic-sea by 52North.

the class OmEncoderv100 method addValuesToObservation.

private List<OmObservableProperty> addValuesToObservation(ObservationType xbObs, OmObservation sosObservation, EncodingContext additionalValues) throws EncodingException {
    xbObs.setId(OBSERVATION_ID_PREFIX + Long.toString(System.currentTimeMillis()));
    if (!sosObservation.isSetObservationID()) {
        sosObservation.setObservationID(xbObs.getId().replace(OBSERVATION_ID_PREFIX, ""));
    }
    String observationID = sosObservation.getObservationID();
    // set samplingTime
    Time samplingTime = sosObservation.getPhenomenonTime();
    if (samplingTime.getGmlId() == null) {
        samplingTime.setGmlId(OmConstants.PHENOMENON_TIME_NAME + "_" + observationID);
    }
    addSamplingTime(xbObs, samplingTime);
    // set resultTime
    addResultTime(xbObs, sosObservation);
    // set procedure
    xbObs.addNewProcedure().setHref(sosObservation.getObservationConstellation().getProcedure().getIdentifier());
    // set observedProperty (phenomenon)
    List<OmObservableProperty> phenComponents = null;
    if (sosObservation.getObservationConstellation().getObservableProperty() instanceof OmObservableProperty) {
        xbObs.addNewObservedProperty().setHref(sosObservation.getObservationConstellation().getObservableProperty().getIdentifier());
        phenComponents = new ArrayList<>(1);
        phenComponents.add((OmObservableProperty) sosObservation.getObservationConstellation().getObservableProperty());
    } else if (sosObservation.getObservationConstellation().getObservableProperty() instanceof OmCompositePhenomenon) {
        OmCompositePhenomenon compPhen = (OmCompositePhenomenon) sosObservation.getObservationConstellation().getObservableProperty();
        xbObs.addNewObservedProperty().setHref(compPhen.getIdentifier());
        phenComponents = compPhen.getPhenomenonComponents();
    }
    // set feature
    addFeatureOfInterest(xbObs, sosObservation.getObservationConstellation().getFeatureOfInterest());
    return phenComponents;
}
Also used : OmCompositePhenomenon(org.n52.shetland.ogc.om.OmCompositePhenomenon) Time(org.n52.shetland.ogc.gml.time.Time) DateTime(org.joda.time.DateTime) XmlString(org.apache.xmlbeans.XmlString) OmObservableProperty(org.n52.shetland.ogc.om.OmObservableProperty)

Example 2 with OmObservableProperty

use of org.n52.shetland.ogc.om.OmObservableProperty in project arctic-sea by 52North.

the class OmEncoderv100 method createOmObservation.

private XmlObject createOmObservation(OmObservation sosObservation, EncodingContext additionalValues) throws EncodingException {
    ObservationDocument xbObservationDoc = ObservationDocument.Factory.newInstance(getXmlOptions());
    ObservationType xbObs = xbObservationDoc.addNewObservation();
    List<OmObservableProperty> phenComponents = addValuesToObservation(xbObs, sosObservation, additionalValues);
    addResultToObservation(xbObs.addNewResult(), sosObservation, phenComponents);
    return xbObservationDoc;
}
Also used : TruthObservationType(net.opengis.om.x10.TruthObservationType) ObservationType(net.opengis.om.x10.ObservationType) CategoryObservationType(net.opengis.om.x10.CategoryObservationType) CountObservationType(net.opengis.om.x10.CountObservationType) GeometryObservationType(net.opengis.om.x10.GeometryObservationType) GeometryObservationDocument(net.opengis.om.x10.GeometryObservationDocument) CountObservationDocument(net.opengis.om.x10.CountObservationDocument) TruthObservationDocument(net.opengis.om.x10.TruthObservationDocument) ObservationDocument(net.opengis.om.x10.ObservationDocument) CategoryObservationDocument(net.opengis.om.x10.CategoryObservationDocument) OmObservableProperty(org.n52.shetland.ogc.om.OmObservableProperty)

Example 3 with OmObservableProperty

use of org.n52.shetland.ogc.om.OmObservableProperty in project arctic-sea by 52North.

the class WmlTVPEncoderv20 method createMeasurementTimeseries.

/**
 * Create a XML MeasurementTimeseries object from SOS observation for
 * om:result
 *
 * @param sosObservation
 *            SOS observation
 *
 * @return XML MeasurementTimeseries object
 *
 * @throws CodedException
 *             if the encoding fails
 */
private XmlObject createMeasurementTimeseries(OmObservation sosObservation) throws OwsExceptionReport {
    MeasurementTimeseriesDocument measurementTimeseriesDoc = MeasurementTimeseriesDocument.Factory.newInstance();
    MeasurementTimeseriesType measurementTimeseries = measurementTimeseriesDoc.addNewMeasurementTimeseries();
    measurementTimeseries.setId(TIMESERIES_ID_PREFIX + sosObservation.getObservationID());
    // Default value
    TimeseriesMetadata timeseriesMetadata = new MeasurementTimeseriesMetadata().setCumulative(false);
    if (sosObservation.isSetValue() && sosObservation.getValue().isSetValue() && sosObservation.getValue().getValue().getClass().isAssignableFrom(TVPValue.class) && sosObservation.getObservationConstellation().isSetMetadata() && sosObservation.getObservationConstellation().getMetadata().isSetTimeseriesMetadata()) {
        timeseriesMetadata = sosObservation.getObservationConstellation().getMetadata().getTimeseriesmetadata();
    }
    addTimeseriesMetadata(measurementTimeseries, sosObservation.getPhenomenonTime().getGmlId(), timeseriesMetadata);
    TVPDefaultMetadataPropertyType xbMetaComponent = measurementTimeseries.addNewDefaultPointMetadata();
    DefaultTVPMeasurementMetadataDocument xbDefMeasureMetaComponent = DefaultTVPMeasurementMetadataDocument.Factory.newInstance();
    TVPMeasurementMetadataType defaultTVPMeasurementMetadata = xbDefMeasureMetaComponent.addNewDefaultTVPMeasurementMetadata();
    // Default value
    InterpolationType interpolationType = InterpolationType.Continuous;
    if (sosObservation.isSetValue() && sosObservation.getValue().isSetValue() && sosObservation.getObservationConstellation().isSetDefaultPointMetadata() && sosObservation.getObservationConstellation().getDefaultPointMetadata().isSetDefaultTVPMeasurementMetadata() && sosObservation.getObservationConstellation().getDefaultPointMetadata().getDefaultTVPMeasurementMetadata().isSetInterpolationType()) {
        interpolationType = sosObservation.getObservationConstellation().getDefaultPointMetadata().getDefaultTVPMeasurementMetadata().getInterpolationtype();
    }
    defaultTVPMeasurementMetadata.addNewInterpolationType().setHref(interpolationType.getIdentifier());
    xbDefMeasureMetaComponent.getDefaultTVPMeasurementMetadata().getInterpolationType().setTitle(interpolationType.getTitle());
    String unit = addValues(measurementTimeseries, sosObservation.getValue());
    // set uom
    if (unit != null && !unit.isEmpty()) {
        defaultTVPMeasurementMetadata.addNewUom().setCode(unit);
    } else {
        OmObservableProperty observableProperty = (OmObservableProperty) sosObservation.getObservationConstellation().getObservableProperty();
        if (observableProperty.isSetUnit()) {
            defaultTVPMeasurementMetadata.addNewUom().setCode(observableProperty.getUnit());
        }
    }
    xbMetaComponent.set(xbDefMeasureMetaComponent);
    return measurementTimeseriesDoc;
}
Also used : TimeseriesMetadata(org.n52.shetland.ogc.om.series.wml.TimeseriesMetadata) MeasurementTimeseriesMetadata(org.n52.shetland.ogc.om.series.wml.MeasurementTimeseriesMetadata) MeasurementTimeseriesType(net.opengis.waterml.x20.MeasurementTimeseriesType) TVPValue(org.n52.shetland.ogc.om.values.TVPValue) TVPDefaultMetadataPropertyType(net.opengis.waterml.x20.TVPDefaultMetadataPropertyType) MeasurementTimeseriesMetadata(org.n52.shetland.ogc.om.series.wml.MeasurementTimeseriesMetadata) TVPMeasurementMetadataType(net.opengis.waterml.x20.TVPMeasurementMetadataType) DefaultTVPMeasurementMetadataDocument(net.opengis.waterml.x20.DefaultTVPMeasurementMetadataDocument) InterpolationType(org.n52.shetland.ogc.om.series.wml.WaterMLConstants.InterpolationType) MeasurementTimeseriesDocument(net.opengis.waterml.x20.MeasurementTimeseriesDocument) OmObservableProperty(org.n52.shetland.ogc.om.OmObservableProperty)

Example 4 with OmObservableProperty

use of org.n52.shetland.ogc.om.OmObservableProperty in project arctic-sea by 52North.

the class InsertResultTemplateRequestEncoderTest method setup.

@Before
public void setup() throws InvalidSridException, ParseException {
    SensorML procedure = new SensorML();
    procedure.setIdentifier(procedureIdentifier);
    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));
    observationTemplate = new OmObservationConstellation();
    observationTemplate.addOffering(offering);
    observationTemplate.setObservationType(OmConstants.OBS_TYPE_MEASUREMENT);
    observationTemplate.setProcedure(procedure);
    observationTemplate.setObservableProperty(new OmObservableProperty(observedProperty));
    observationTemplate.setFeatureOfInterest(featureOfInterest);
    SweTextEncoding textEncoding = new SweTextEncoding();
    textEncoding.setBlockSeparator(blockSeparator);
    textEncoding.setTokenSeparator(tokenSeparator);
    SweDataRecord resultStructure = new SweDataRecord();
    SweTime sweTime = new SweTime();
    sweTime.setDefinition(field1Definition);
    sweTime.setUom(field1Uom);
    resultStructure.addField(new SweField(field1Name, sweTime));
    request = new InsertResultTemplateRequest(SosConstants.SOS, Sos2Constants.SERVICEVERSION, Sos2Constants.Operations.InsertResultTemplate.name());
    request.setResultEncoding(new SosResultEncoding(textEncoding));
    request.setResultStructure(new SosResultStructure(resultStructure));
    request.setIdentifier(templateIdentifier);
    request.setObservationTemplate(observationTemplate);
    Supplier<XmlOptions> xmlOptions = () -> new XmlOptions();
    encoder = new InsertResultTemplateRequestEncoder();
    encoder.setXmlOptions(xmlOptions);
    OmEncoderv20 omEncoder = new OmEncoderv20();
    omEncoder.setXmlOptions(xmlOptions);
    SamplingEncoderv20 samsEncoder = new SamplingEncoderv20();
    samsEncoder.setXmlOptions(xmlOptions);
    GmlEncoderv321 gml32Encoder = new GmlEncoderv321();
    gml32Encoder.setXmlOptions(xmlOptions);
    SweCommonEncoderv20 sweEncoderv20 = new SweCommonEncoderv20();
    sweEncoderv20.setXmlOptions(xmlOptions);
    EncoderRepository encoderRepository = new EncoderRepository();
    encoderRepository.setEncoders(Arrays.asList(encoder, omEncoder, samsEncoder, gml32Encoder, sweEncoderv20));
    encoderRepository.init();
    encoderRepository.getEncoders().stream().forEach(e -> ((AbstractDelegatingEncoder<?, ?>) e).setEncoderRepository(encoderRepository));
}
Also used : SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) XmlOptions(org.apache.xmlbeans.XmlOptions) SamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature) OmObservationConstellation(org.n52.shetland.ogc.om.OmObservationConstellation) SensorML(org.n52.shetland.ogc.sensorML.SensorML) SosResultEncoding(org.n52.shetland.ogc.sos.SosResultEncoding) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) SweField(org.n52.shetland.ogc.swe.SweField) CodeType(org.n52.shetland.ogc.gml.CodeType) SweTextEncoding(org.n52.shetland.ogc.swe.encoding.SweTextEncoding) CodeWithAuthority(org.n52.shetland.ogc.gml.CodeWithAuthority) OmObservableProperty(org.n52.shetland.ogc.om.OmObservableProperty) SosResultStructure(org.n52.shetland.ogc.sos.SosResultStructure) InsertResultTemplateRequest(org.n52.shetland.ogc.sos.request.InsertResultTemplateRequest) Before(org.junit.Before)

Example 5 with OmObservableProperty

use of org.n52.shetland.ogc.om.OmObservableProperty in project arctic-sea by 52North.

the class OmEncoderv20Test method shouldEncodeObservationTypeInObservationTemplate.

@Test
public void shouldEncodeObservationTypeInObservationTemplate() throws EncodingException {
    OmObservationConstellation observationTemplate = new OmObservationConstellation();
    String observationType = OmConstants.OBS_TYPE_MEASUREMENT;
    observationTemplate.setObservationType(observationType);
    observationTemplate.setObservableProperty(new OmObservableProperty(observedProperty));
    OMObservationType encodedObservationTemplate = (OMObservationType) omEncoderv20.encode(observationTemplate);
    Assert.assertThat(encodedObservationTemplate.getType().getHref(), Is.is(observationType));
}
Also used : OMObservationType(net.opengis.om.x20.OMObservationType) Matchers.containsString(org.hamcrest.Matchers.containsString) OmObservationConstellation(org.n52.shetland.ogc.om.OmObservationConstellation) OmObservableProperty(org.n52.shetland.ogc.om.OmObservableProperty) Test(org.junit.Test)

Aggregations

OmObservableProperty (org.n52.shetland.ogc.om.OmObservableProperty)14 OmObservationConstellation (org.n52.shetland.ogc.om.OmObservationConstellation)8 CodeWithAuthority (org.n52.shetland.ogc.gml.CodeWithAuthority)5 SamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature)5 OMObservationType (net.opengis.om.x20.OMObservationType)4 Test (org.junit.Test)4 TVPValue (org.n52.shetland.ogc.om.values.TVPValue)4 Matchers.containsString (org.hamcrest.Matchers.containsString)3 DateTime (org.joda.time.DateTime)3 CodeType (org.n52.shetland.ogc.gml.CodeType)3 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)3 MultiObservationValues (org.n52.shetland.ogc.om.MultiObservationValues)3 OmObservation (org.n52.shetland.ogc.om.OmObservation)3 TimeValuePair (org.n52.shetland.ogc.om.TimeValuePair)3 MeasureOrNilReasonListType (net.opengis.gml.x32.MeasureOrNilReasonListType)2 QuantityListDocument (net.opengis.gml.x32.QuantityListDocument)2 DefaultTVPMeasurementMetadataDocument (net.opengis.waterml.x20.DefaultTVPMeasurementMetadataDocument)2 MeasurementTimeseriesDocument (net.opengis.waterml.x20.MeasurementTimeseriesDocument)2 MeasurementTimeseriesType (net.opengis.waterml.x20.MeasurementTimeseriesType)2 TVPDefaultMetadataPropertyType (net.opengis.waterml.x20.TVPDefaultMetadataPropertyType)2