Search in sources :

Example 6 with FeatureCollection

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

the class AqdGetObservationResponseEncoder method create.

@Override
protected XmlObject create(GetObservationResponse response) throws EncodingException {
    try {
        FeatureCollection featureCollection = createFeatureCollection(response);
        // TODO get FLOW from response
        EReportingHeader eReportingHeader = getEReportingHeader(getReportObligationType(response));
        featureCollection.addMember(eReportingHeader);
        TimePeriod timePeriod = new TimePeriod();
        TimeInstant resultTime = new TimeInstant(new DateTime(DateTimeZone.UTC));
        int counter = 1;
        while (response.getObservationCollection().hasNext()) {
            OmObservation observation = response.getObservationCollection().next();
            processObservation(observation, timePeriod, resultTime, featureCollection, eReportingHeader, counter++);
        }
        if (!timePeriod.isEmpty()) {
            eReportingHeader.setReportingPeriod(Referenceable.of((Time) timePeriod));
        }
        EncodingContext ctx = EncodingContext.empty().with(XmlEncoderFlags.ENCODE_NAMESPACE, OmConstants.NS_OM_2).with(XmlBeansEncodingFlags.DOCUMENT);
        return encodeGml(ctx, featureCollection);
    } catch (OwsExceptionReport ex) {
        throw new EncodingException(ex);
    }
}
Also used : FeatureCollection(org.n52.shetland.ogc.om.features.FeatureCollection) EncodingException(org.n52.svalbard.encode.exception.EncodingException) EReportingHeader(org.n52.shetland.aqd.EReportingHeader) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) OmObservation(org.n52.shetland.ogc.om.OmObservation) Time(org.n52.shetland.ogc.gml.time.Time) DateTime(org.joda.time.DateTime) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant) DateTime(org.joda.time.DateTime)

Example 7 with FeatureCollection

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

the class AqdGetObservationResponseEncoder method addToFeatureCollectionAndGetTimePeriod.

private TimePeriod addToFeatureCollectionAndGetTimePeriod(FeatureCollection featureCollection, GetObservationResponse response, EReportingHeader eReportingHeader) throws OwsExceptionReport {
    TimeInstant resultTime = new TimeInstant(new DateTime(DateTimeZone.UTC));
    TimePeriod timePeriod = new TimePeriod();
    int counter = 1;
    while (response.getObservationCollection().hasNext()) {
        OmObservation observation = response.getObservationCollection().next();
        processObservation(observation, timePeriod, resultTime, featureCollection, eReportingHeader, counter++);
    }
    return timePeriod;
}
Also used : TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) OmObservation(org.n52.shetland.ogc.om.OmObservation) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant) DateTime(org.joda.time.DateTime)

Example 8 with FeatureCollection

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

the class AqdGetObservationResponseEncoder method create.

@Override
protected void create(GetObservationResponse response, OutputStream outputStream, EncodingContext ctx) throws EncodingException {
    FeatureCollection featureCollection = createFeatureCollection(response);
    EReportingHeader eReportingHeader;
    TimePeriod timePeriod;
    try {
        eReportingHeader = getEReportingHeader(getReportObligationType(response));
        featureCollection.addMember(eReportingHeader);
        timePeriod = addToFeatureCollectionAndGetTimePeriod(featureCollection, response, eReportingHeader);
    } catch (OwsExceptionReport ex) {
        throw new EncodingException(ex);
    }
    if (!timePeriod.isEmpty()) {
        eReportingHeader.setReportingPeriod(Referenceable.of((Time) timePeriod));
    }
    try {
        EncodingContext context = ctx.with(EncoderFlags.ENCODER_REPOSITORY, getEncoderRepository()).with(XmlEncoderFlags.XML_OPTIONS, (Supplier<XmlOptions>) this::getXmlOptions).with(XmlEncoderFlags.ENCODE_NAMESPACE, OmConstants.NS_OM_2).with(XmlBeansEncodingFlags.DOCUMENT);
        new AqdGetObservationResponseXmlStreamWriter(context, outputStream, featureCollection).write();
    } catch (XMLStreamException xmlse) {
        throw new EncodingException("Error while writing element to stream!", xmlse);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) FeatureCollection(org.n52.shetland.ogc.om.features.FeatureCollection) EncodingException(org.n52.svalbard.encode.exception.EncodingException) EReportingHeader(org.n52.shetland.aqd.EReportingHeader) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) AqdGetObservationResponseXmlStreamWriter(org.n52.svalbard.write.AqdGetObservationResponseXmlStreamWriter) Time(org.n52.shetland.ogc.gml.time.Time) DateTime(org.joda.time.DateTime) Supplier(java.util.function.Supplier) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport)

Example 9 with FeatureCollection

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

the class SamplingEncoderv100 method createFeature.

private XmlObject createFeature(AbstractFeature absFeature) throws EncodingException {
    if (absFeature instanceof AbstractSamplingFeature) {
        AbstractSamplingFeature sampFeat = (AbstractSamplingFeature) absFeature;
        if (sampFeat.getFeatureType().equals(SfConstants.FT_SAMPLINGPOINT) || sampFeat.getFeatureType().equals(SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_POINT) || sampFeat.getGeometry() instanceof Point) {
            SamplingPointDocument xbSamplingPointDoc = SamplingPointDocument.Factory.newInstance(getXmlOptions());
            SamplingPointType xbSamplingPoint = xbSamplingPointDoc.addNewSamplingPoint();
            addValuesToFeature(xbSamplingPoint, sampFeat);
            XmlObject xbGeomety = getEncodedGeometry(sampFeat.getGeometry(), absFeature.getGmlId());
            xbSamplingPoint.addNewPosition().addNewPoint().set(xbGeomety);
            sampFeat.wasEncoded();
            return xbSamplingPointDoc;
        } else if (sampFeat.getFeatureType().equals(SfConstants.FT_SAMPLINGCURVE) || sampFeat.getFeatureType().equals(SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_CURVE) || sampFeat.getGeometry() instanceof LineString) {
            SamplingCurveDocument xbSamplingCurveDoc = SamplingCurveDocument.Factory.newInstance(getXmlOptions());
            SamplingCurveType xbSamplingCurve = xbSamplingCurveDoc.addNewSamplingCurve();
            addValuesToFeature(xbSamplingCurve, sampFeat);
            XmlObject xbGeomety = getEncodedGeometry(sampFeat.getGeometry(), absFeature.getGmlId());
            xbSamplingCurve.addNewShape().addNewCurve().set(xbGeomety);
            sampFeat.wasEncoded();
            return xbSamplingCurveDoc;
        } else if (sampFeat.getFeatureType().equals(SfConstants.FT_SAMPLINGSURFACE) || sampFeat.getFeatureType().equals(SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_SURFACE) || sampFeat.getGeometry() instanceof Polygon) {
            SamplingSurfaceDocument xbSamplingSurfaceDoc = SamplingSurfaceDocument.Factory.newInstance(getXmlOptions());
            SamplingSurfaceType xbSamplingSurface = xbSamplingSurfaceDoc.addNewSamplingSurface();
            addValuesToFeature(xbSamplingSurface, sampFeat);
            XmlObject xbGeomety = getEncodedGeometry(sampFeat.getGeometry(), absFeature.getGmlId());
            xbSamplingSurface.addNewShape().addNewSurface().set(xbGeomety);
            sampFeat.wasEncoded();
            return xbSamplingSurfaceDoc;
        }
    } else if (absFeature instanceof FeatureCollection) {
        createFeatureCollection((FeatureCollection) absFeature);
    }
    throw new UnsupportedEncoderInputException(this, absFeature);
}
Also used : SamplingSurfaceType(net.opengis.sampling.x10.SamplingSurfaceType) AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) Point(org.locationtech.jts.geom.Point) SamplingCurveDocument(net.opengis.sampling.x10.SamplingCurveDocument) SamplingCurveType(net.opengis.sampling.x10.SamplingCurveType) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException) SamplingPointDocument(net.opengis.sampling.x10.SamplingPointDocument) LineString(org.locationtech.jts.geom.LineString) FeatureCollection(org.n52.shetland.ogc.om.features.FeatureCollection) SamplingPointType(net.opengis.sampling.x10.SamplingPointType) XmlObject(org.apache.xmlbeans.XmlObject) SamplingSurfaceDocument(net.opengis.sampling.x10.SamplingSurfaceDocument) Polygon(org.locationtech.jts.geom.Polygon)

Example 10 with FeatureCollection

use of org.n52.shetland.ogc.om.features.FeatureCollection 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)

Aggregations

FeatureCollection (org.n52.shetland.ogc.om.features.FeatureCollection)14 DateTime (org.joda.time.DateTime)8 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)8 XmlObject (org.apache.xmlbeans.XmlObject)7 OmObservation (org.n52.shetland.ogc.om.OmObservation)6 EncodingException (org.n52.svalbard.encode.exception.EncodingException)5 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)4 TimePeriod (org.n52.shetland.ogc.gml.time.TimePeriod)4 SamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature)4 OwsExceptionReport (org.n52.shetland.ogc.ows.exception.OwsExceptionReport)4 EReportingHeader (org.n52.shetland.aqd.EReportingHeader)3 CodeWithAuthority (org.n52.shetland.ogc.gml.CodeWithAuthority)3 Time (org.n52.shetland.ogc.gml.time.Time)3 AbstractSamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature)3 UnsupportedEncoderInputException (org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)3 FeaturePropertyType (net.opengis.gml.x32.FeaturePropertyType)2 Test (org.junit.Test)2 LineString (org.locationtech.jts.geom.LineString)2 ObservationStream (org.n52.shetland.ogc.om.ObservationStream)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1