Search in sources :

Example 1 with FeatureCollection

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

the class FeatureOfInterestEncoder method encodeFeatureCollection.

private JsonNode encodeFeatureCollection(AbstractFeature t) throws EncodingException {
    FeatureCollection featureCollection = (FeatureCollection) t;
    ArrayNode a = nodeFactory().arrayNode();
    for (AbstractFeature af : featureCollection) {
        a.add(encodeObjectToJson(af));
    }
    return a;
}
Also used : FeatureCollection(org.n52.shetland.ogc.om.features.FeatureCollection) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 2 with FeatureCollection

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

the class GmlEncoderv311 method createFeature.

private XmlObject createFeature(AbstractFeature sosAbstractFeature) throws EncodingException {
    if (sosAbstractFeature instanceof SamplingFeature) {
        SamplingFeature sampFeat = (SamplingFeature) sosAbstractFeature;
        if (sosAbstractFeature.isSetGmlID()) {
            FeaturePropertyType featureProperty = FeaturePropertyType.Factory.newInstance(getXmlOptions());
            featureProperty.setHref("#" + sosAbstractFeature.getGmlId());
            return featureProperty;
        } else {
            if (!sampFeat.isSetGeometry()) {
                FeaturePropertyType featureProperty = FeaturePropertyType.Factory.newInstance(getXmlOptions());
                featureProperty.setHref(sosAbstractFeature.getIdentifierCodeWithAuthority().getValue());
                if (sampFeat.isSetName()) {
                    featureProperty.setTitle(sampFeat.getFirstName().getValue());
                }
                return featureProperty;
            }
            StringBuilder builder = new StringBuilder();
            builder.append("sf_");
            builder.append(JavaHelper.generateID(sosAbstractFeature.getIdentifierCodeWithAuthority().getValue()));
            sosAbstractFeature.setGmlId(builder.toString());
            Encoder<XmlObject, SamplingFeature> encoder = getEncoder(SfConstants.NS_SA, sampFeat);
            return encoder.encode(sampFeat);
        }
    } else if (sosAbstractFeature instanceof FeatureCollection) {
        return createFeatureCollection((FeatureCollection) sosAbstractFeature);
    }
    throw new UnsupportedEncoderInputException(this, sosAbstractFeature);
}
Also used : FeatureCollection(org.n52.shetland.ogc.om.features.FeatureCollection) SamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature) XmlObject(org.apache.xmlbeans.XmlObject) FeaturePropertyType(net.opengis.gml.FeaturePropertyType) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)

Example 3 with FeatureCollection

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

the class GmlEncoderv311 method createFeatureCollection.

@SuppressFBWarnings("NP_NULL_ON_SOME_PATH")
private XmlObject createFeatureCollection(FeatureCollection sosFeatureCollection) throws EncodingException {
    Map<String, AbstractFeature> members = sosFeatureCollection.getMembers();
    XmlObject xmlObject = null;
    if (sosFeatureCollection.isSetMembers()) {
        if (members.size() == 1) {
            for (Entry<String, AbstractFeature> entry : members.entrySet()) {
                String member = entry.getKey();
                if (members.get(member) instanceof SamplingFeature) {
                    return createFeature((SamplingFeature) members.get(member));
                } else {
                    throw missingFeatureEncoder();
                }
            }
        } else {
            FeatureCollectionDocument2 xbFeatureColllectionDoc = FeatureCollectionDocument2.Factory.newInstance(getXmlOptions());
            AbstractFeatureCollectionType xbFeatCol = xbFeatureColllectionDoc.addNewFeatureCollection();
            StringBuilder builder = new StringBuilder();
            builder.append("sfc_");
            builder.append(JavaHelper.generateID(Long.toString(System.currentTimeMillis())));
            xbFeatCol.setId(builder.toString());
            for (Entry<String, AbstractFeature> entry : members.entrySet()) {
                String member = entry.getKey();
                if (members.get(member) instanceof SamplingFeature) {
                    XmlObject xmlFeature = createFeature((SamplingFeature) members.get(member));
                    xbFeatCol.addNewFeatureMember().set(xmlFeature);
                } else {
                    throw missingFeatureEncoder();
                }
            }
            xmlObject = xbFeatureColllectionDoc;
        }
    } else {
        FeatureCollectionDocument2 xbFeatColDoc = FeatureCollectionDocument2.Factory.newInstance(getXmlOptions());
        xbFeatColDoc.addNewFeatureCollection();
        xmlObject = xbFeatColDoc;
    }
    XmlCursor cursor = xmlObject.newCursor();
    boolean isAFC = cursor.toChild(new QName(GmlConstants.NS_GML, GmlConstants.EN_ABSTRACT_FEATURE_COLLECTION));
    if (isAFC) {
        cursor.setName(new QName(GmlConstants.NS_GML, GmlConstants.EN_FEATURE_COLLECTION));
    }
    cursor.dispose();
    return xmlObject;
}
Also used : FeatureCollectionDocument2(net.opengis.gml.FeatureCollectionDocument2) QName(javax.xml.namespace.QName) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) XmlObject(org.apache.xmlbeans.XmlObject) SamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature) LineString(org.locationtech.jts.geom.LineString) AbstractFeatureCollectionType(net.opengis.gml.AbstractFeatureCollectionType) XmlCursor(org.apache.xmlbeans.XmlCursor) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 4 with FeatureCollection

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

the class GmlEncoderv321 method createFeatureCollection.

private XmlObject createFeatureCollection(FeatureCollection element, EncodingContext ctx) throws EncodingException {
    FeatureCollectionDocument featureCollectionDoc = FeatureCollectionDocument.Factory.newInstance(getXmlOptions());
    FeatureCollectionType featureCollection = featureCollectionDoc.addNewFeatureCollection();
    featureCollection.setId(element.getGmlId());
    EncodingContext context = ctx.with(XmlBeansEncodingFlags.PROPERTY_TYPE).without(XmlBeansEncodingFlags.DOCUMENT);
    if (element.isSetMembers()) {
        for (AbstractFeature abstractFeature : element.getMembers().values()) {
            featureCollection.addNewFeatureMember().set(createFeaturePropertyType(abstractFeature, context));
        }
    }
    if (ctx.has(XmlBeansEncodingFlags.DOCUMENT)) {
        return featureCollectionDoc;
    }
    FeaturePropertyType featurePropertyType = FeaturePropertyType.Factory.newInstance(getXmlOptions());
    featurePropertyType.addNewAbstractFeature().set(featureCollection);
    return XmlHelper.substituteElement(featurePropertyType.getAbstractFeature(), featurePropertyType);
// return featureCollection;
}
Also used : FeatureCollectionType(net.opengis.gml.x32.FeatureCollectionType) FeatureCollectionDocument(net.opengis.gml.x32.FeatureCollectionDocument) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) FeaturePropertyType(net.opengis.gml.x32.FeaturePropertyType)

Example 5 with FeatureCollection

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

the class AqdEncoder method encodeGetObservationResponse.

private XmlObject encodeGetObservationResponse(GetObservationResponse response, EncodingContext ctx) throws EncodingException {
    try {
        FeatureCollection featureCollection = getFeatureCollection(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;
        ObservationStream observationCollection = response.getObservationCollection();
        while (observationCollection.hasNext()) {
            OmObservation observation = observationCollection.next();
            if (observation.getValue() instanceof ObservationStream) {
                ObservationStream value = (ObservationStream) observation.getValue();
                if (value instanceof StreamingValue) {
                    value = value.merge();
                }
                while (value.hasNext()) {
                    processObservation(value.next(), timePeriod, resultTime, featureCollection, eReportingHeader, counter++);
                }
            } else {
                processObservation(observation, timePeriod, resultTime, featureCollection, eReportingHeader, counter++);
            }
        }
        if (!timePeriod.isEmpty()) {
            eReportingHeader.setReportingPeriod(Referenceable.of((Time) timePeriod));
        }
        return encodeObjectToXml(GmlConstants.NS_GML_32, featureCollection, ctx.with(XmlEncoderFlags.ENCODE_NAMESPACE, OmConstants.NS_OM_2).with(XmlBeansEncodingFlags.DOCUMENT));
    } catch (OwsExceptionReport ex) {
        throw new EncodingException(ex);
    }
}
Also used : FeatureCollection(org.n52.shetland.ogc.om.features.FeatureCollection) ObservationStream(org.n52.shetland.ogc.om.ObservationStream) StreamingValue(org.n52.shetland.ogc.om.StreamingValue) EncodingException(org.n52.svalbard.encode.exception.EncodingException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) AbstractEReportingHeader(org.n52.shetland.aqd.AbstractEReportingHeader) 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)

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