Search in sources :

Example 1 with FeatureCollectionDocument2

use of net.opengis.gml.FeatureCollectionDocument2 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)

Aggregations

SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 QName (javax.xml.namespace.QName)1 AbstractFeatureCollectionType (net.opengis.gml.AbstractFeatureCollectionType)1 FeatureCollectionDocument2 (net.opengis.gml.FeatureCollectionDocument2)1 XmlCursor (org.apache.xmlbeans.XmlCursor)1 XmlObject (org.apache.xmlbeans.XmlObject)1 LineString (org.locationtech.jts.geom.LineString)1 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)1 SamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature)1