Search in sources :

Example 16 with AbstractFeature

use of org.n52.shetland.ogc.gml.AbstractFeature in project arctic-sea by 52North.

the class GmlEncoderv311 method encode.

@Override
public XmlObject encode(Object element, EncodingContext ctx) throws EncodingException {
    XmlObject encodedObject = null;
    if (element instanceof Time) {
        encodedObject = createTime((Time) element, ctx);
    } else if (element instanceof Geometry) {
        encodedObject = createPosition((Geometry) element, ctx.get(XmlBeansEncodingFlags.GMLID));
    } else if (element instanceof CategoryValue) {
        encodedObject = createReferenceTypeForCategroyValue((CategoryValue) element);
    } else if (element instanceof org.n52.shetland.ogc.gml.ReferenceType) {
        encodedObject = createReferencType((org.n52.shetland.ogc.gml.ReferenceType) element);
    } else if (element instanceof CodeWithAuthority) {
        encodedObject = createCodeWithAuthorityType((CodeWithAuthority) element);
    } else if (element instanceof QuantityValue) {
        encodedObject = createMeasureType((QuantityValue) element);
    } else if (element instanceof org.n52.shetland.ogc.gml.CodeType) {
        encodedObject = createCodeType((org.n52.shetland.ogc.gml.CodeType) element);
    } else if (element instanceof AbstractFeature) {
        encodedObject = createFeature((AbstractFeature) element);
    } else if (element instanceof ReferencedEnvelope) {
        encodedObject = createEnvelope((ReferencedEnvelope) element);
    } else if (element instanceof EnvelopeOrGeometry) {
        EnvelopeOrGeometry geom = (EnvelopeOrGeometry) element;
        if (geom.getGeometry().isPresent()) {
            encodedObject = createPosition(geom.getGeometry().get(), ctx.get(XmlBeansEncodingFlags.GMLID));
        } else if (geom.getEnvelope().isPresent()) {
            encodedObject = createEnvelope(geom.getEnvelope().get());
        } else {
            throw new UnsupportedEncoderInputException(this, element);
        }
    } else if (element instanceof GenericMetaData) {
        encodedObject = createGenericMetaData((GenericMetaData) element, ctx);
    } else {
        throw new UnsupportedEncoderInputException(this, element);
    }
    XmlHelper.validateDocument(encodedObject, EncodingException::new);
    return encodedObject;
}
Also used : GenericMetaData(org.n52.shetland.ogc.gml.GenericMetaData) EncodingException(org.n52.svalbard.encode.exception.EncodingException) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) Time(org.n52.shetland.ogc.gml.time.Time) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException) Geometry(org.locationtech.jts.geom.Geometry) EnvelopeOrGeometry(org.n52.shetland.util.EnvelopeOrGeometry) ReferencedEnvelope(org.n52.shetland.util.ReferencedEnvelope) EnvelopeOrGeometry(org.n52.shetland.util.EnvelopeOrGeometry) QuantityValue(org.n52.shetland.ogc.om.values.QuantityValue) CategoryValue(org.n52.shetland.ogc.om.values.CategoryValue) CodeType(net.opengis.gml.CodeType) XmlObject(org.apache.xmlbeans.XmlObject) CodeWithAuthority(org.n52.shetland.ogc.gml.CodeWithAuthority)

Example 17 with AbstractFeature

use of org.n52.shetland.ogc.gml.AbstractFeature 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 18 with AbstractFeature

use of org.n52.shetland.ogc.gml.AbstractFeature 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 19 with AbstractFeature

use of org.n52.shetland.ogc.gml.AbstractFeature in project arctic-sea by 52North.

the class GmlEncoderv321 method createFeature.

private XmlObject createFeature(AbstractFeature feature, EncodingContext ctx) throws EncodingException {
    FeaturePropertyType featurePropertyType = FeaturePropertyType.Factory.newInstance(getXmlOptions());
    if (isNotSamplingFeature(feature) || ctx.has(XmlBeansEncodingFlags.REFERENCED)) {
        featurePropertyType.setHref(feature.getIdentifierCodeWithAuthority().getValue());
        return featurePropertyType;
    } else {
        AbstractSamplingFeature samplingFeature = (AbstractSamplingFeature) feature;
        if (samplingFeature.isSetGmlID()) {
            featurePropertyType.setHref("#" + samplingFeature.getGmlId());
            return featurePropertyType;
        } else {
            if (ctx.has(XmlBeansEncodingFlags.ENCODE) && !ctx.getBoolean(XmlBeansEncodingFlags.ENCODE) || !samplingFeature.isEncode()) {
                featurePropertyType.setHref(feature.getIdentifierCodeWithAuthority().getValue());
                if (feature instanceof SamplingFeature && samplingFeature.isSetName()) {
                    featurePropertyType.setTitle(samplingFeature.getFirstName().getValue());
                }
                return featurePropertyType;
            }
            if (!samplingFeature.isSetGeometry()) {
                featurePropertyType.setHref(samplingFeature.getIdentifierCodeWithAuthority().getValue());
                if (samplingFeature.isSetName()) {
                    featurePropertyType.setTitle(samplingFeature.getFirstName().getValue());
                }
                return featurePropertyType;
            }
            if (samplingFeature.isSetUrl()) {
                featurePropertyType.setHref(samplingFeature.getUrl());
                if (samplingFeature.isSetName()) {
                    featurePropertyType.setTitle(samplingFeature.getFirstName().getValue());
                }
                return featurePropertyType;
            } else {
                String namespace = ctx.getString(XmlEncoderFlags.ENCODE_NAMESPACE).orElseGet(() -> OMHelper.getNamespaceForFeatureType(samplingFeature.getFeatureType()));
                XmlObject encodedXmlObject = encodeObjectToXml(namespace, samplingFeature);
                if (encodedXmlObject != null) {
                    return encodedXmlObject;
                } else {
                    if (feature.isSetXml()) {
                        try {
                            // XmlDescription? <-- XmlCursor
                            return XmlObject.Factory.parse(feature.getXml());
                        } catch (XmlException xmle) {
                            throw new EncodingException("Error while encoding featurePropertyType!", xmle);
                        }
                    } else {
                        featurePropertyType.setHref(feature.getIdentifierCodeWithAuthority().getValue());
                        if (samplingFeature.isSetName()) {
                            featurePropertyType.setTitle(feature.getFirstName().getValue());
                        }
                        return featurePropertyType;
                    }
                }
            }
        }
    }
}
Also used : AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) EncodingException(org.n52.svalbard.encode.exception.EncodingException) XmlException(org.apache.xmlbeans.XmlException) AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) SamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature) XmlObject(org.apache.xmlbeans.XmlObject) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) FeaturePropertyType(net.opengis.gml.x32.FeaturePropertyType)

Example 20 with AbstractFeature

use of org.n52.shetland.ogc.gml.AbstractFeature 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)

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