Search in sources :

Example 26 with AbstractFeature

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;
}
Also used : SweQuantity(org.n52.shetland.ogc.swe.simpleType.SweQuantity) ComplexValue(org.n52.shetland.ogc.om.values.ComplexValue) SweText(org.n52.shetland.ogc.swe.simpleType.SweText) OmCompositePhenomenon(org.n52.shetland.ogc.om.OmCompositePhenomenon) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) OmObservation(org.n52.shetland.ogc.om.OmObservation) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) SamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature) SweCount(org.n52.shetland.ogc.swe.simpleType.SweCount) OmObservationConstellation(org.n52.shetland.ogc.om.OmObservationConstellation) DateTime(org.joda.time.DateTime) SweBoolean(org.n52.shetland.ogc.swe.simpleType.SweBoolean) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) SweField(org.n52.shetland.ogc.swe.SweField) SosProcedureDescriptionUnknownType(org.n52.shetland.ogc.sos.SosProcedureDescriptionUnknownType) SweCategory(org.n52.shetland.ogc.swe.simpleType.SweCategory) CodeWithAuthority(org.n52.shetland.ogc.gml.CodeWithAuthority) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant) OmObservableProperty(org.n52.shetland.ogc.om.OmObservableProperty)

Example 27 with AbstractFeature

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;
    }
}
Also used : GetFeatureOfInterestResponse(org.n52.shetland.ogc.sos.response.GetFeatureOfInterestResponse) FeatureCollection(org.n52.shetland.ogc.om.features.FeatureCollection) XmlObject(org.apache.xmlbeans.XmlObject) Test(org.junit.Test)

Example 28 with AbstractFeature

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);
}
Also used : EncodingException(org.n52.svalbard.encode.exception.EncodingException) OmObservation(org.n52.shetland.ogc.om.OmObservation) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) DateTime(org.joda.time.DateTime) FeatureCollection(org.n52.shetland.ogc.om.features.FeatureCollection) ObservationStream(org.n52.shetland.ogc.om.ObservationStream) XmlObject(org.apache.xmlbeans.XmlObject) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant)

Example 29 with AbstractFeature

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);
}
Also used : AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) FeatureCollection(org.n52.shetland.ogc.om.features.FeatureCollection) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature)

Example 30 with AbstractFeature

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);
    }
}
Also used : XmlNamespaceDecoderKey(org.n52.svalbard.decode.XmlNamespaceDecoderKey) XmlException(org.apache.xmlbeans.XmlException) SosProcedureDescription(org.n52.shetland.ogc.sos.SosProcedureDescription) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) XmlObject(org.apache.xmlbeans.XmlObject) DecodingException(org.n52.svalbard.decode.exception.DecodingException) XmlObject(org.apache.xmlbeans.XmlObject)

Aggregations

AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)33 XmlObject (org.apache.xmlbeans.XmlObject)23 XmlException (org.apache.xmlbeans.XmlException)10 AbstractSamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature)10 FeatureCollection (org.n52.shetland.ogc.om.features.FeatureCollection)9 SamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature)9 OmObservation (org.n52.shetland.ogc.om.OmObservation)8 OmObservationConstellation (org.n52.shetland.ogc.om.OmObservationConstellation)8 DecodingException (org.n52.svalbard.decode.exception.DecodingException)8 UnsupportedEncoderInputException (org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)8 Test (org.junit.Test)6 LineString (org.locationtech.jts.geom.LineString)6 CodeWithAuthority (org.n52.shetland.ogc.gml.CodeWithAuthority)6 EncodingException (org.n52.svalbard.encode.exception.EncodingException)6 FeaturePropertyType (net.opengis.gml.x32.FeaturePropertyType)4 CodeType (org.n52.shetland.ogc.gml.CodeType)4 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)4 SosProcedureDescription (org.n52.shetland.ogc.sos.SosProcedureDescription)4 DateTime (org.joda.time.DateTime)3 Time (org.n52.shetland.ogc.gml.time.Time)3