Search in sources :

Example 71 with XmlCursor

use of org.apache.xmlbeans.XmlCursor in project arctic-sea by 52North.

the class FesDecoderv20 method parseSpatialFilterType.

/**
 * Parses the spatial filter of a request.
 *
 * @param xbSpatialOpsType
 *            XmlBean representing the feature of interest parameter of the
 *            request
 * @return Returns SpatialFilter created from the passed foi request
 *         parameter
 *
 * @throws DecodingException
 *             * if creation of the SpatialFilter failed
 */
private SpatialFilter parseSpatialFilterType(SpatialOpsType xbSpatialOpsType) throws DecodingException {
    SpatialFilter spatialFilter = new SpatialFilter();
    try {
        if (xbSpatialOpsType instanceof BBOXType) {
            spatialFilter.setOperator(FilterConstants.SpatialOperator.BBOX);
            BBOXType xbBBOX = (BBOXType) xbSpatialOpsType;
            if (isValueReferenceExpression(xbBBOX.getExpression())) {
                spatialFilter.setValueReference(parseValueReference(xbBBOX.getExpression()));
            }
            XmlCursor geometryCursor = xbSpatialOpsType.newCursor();
            if (geometryCursor.toChild(GmlConstants.QN_ENVELOPE_32)) {
                Object sosGeometry = decodeXmlObject(Factory.parse(geometryCursor.getDomNode()));
                if (sosGeometry instanceof Geometry) {
                    spatialFilter.setGeometry((Geometry) sosGeometry);
                } else if (sosGeometry instanceof ReferencedEnvelope) {
                    spatialFilter.setGeometry((ReferencedEnvelope) sosGeometry);
                } else {
                    throw new UnsupportedDecoderXmlInputException(this, xbSpatialOpsType);
                }
            } else {
                throw new DecodingException(Sos2Constants.GetObservationParams.spatialFilter, "The requested spatial filter operand is not supported by this SOS!");
            }
            geometryCursor.dispose();
        } else {
            throw new DecodingException(Sos2Constants.GetObservationParams.spatialFilter, "The requested spatial filter is not supported by this SOS!");
        }
    } catch (XmlException xmle) {
        throw new DecodingException("Error while parsing spatial filter!", xmle);
    }
    return spatialFilter;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) ReferencedEnvelope(org.n52.shetland.util.ReferencedEnvelope) BBOXType(net.opengis.fes.x20.BBOXType) XmlException(org.apache.xmlbeans.XmlException) SpatialFilter(org.n52.shetland.ogc.filter.SpatialFilter) XmlObject(org.apache.xmlbeans.XmlObject) UnsupportedDecoderXmlInputException(org.n52.svalbard.decode.exception.UnsupportedDecoderXmlInputException) DecodingException(org.n52.svalbard.decode.exception.DecodingException) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 72 with XmlCursor

use of org.apache.xmlbeans.XmlCursor in project arctic-sea by 52North.

the class OgcDecoderv100 method parseSpatialOperatorType.

private Object parseSpatialOperatorType(BinarySpatialOpType xbSpatialOpsType) throws DecodingException {
    SpatialFilter spatialFilter = new SpatialFilter();
    try {
        if (xbSpatialOpsType instanceof BBOXTypeImpl) {
            spatialFilter.setOperator(FilterConstants.SpatialOperator.BBOX);
            BBOXTypeImpl xbBBOX = (BBOXTypeImpl) xbSpatialOpsType;
            spatialFilter.setOperator(FilterConstants.SpatialOperator.BBOX);
            XmlCursor geometryCursor = xbBBOX.newCursor();
            if (geometryCursor.toChild(GmlConstants.QN_ENVELOPE)) {
                Object sosGeometry = decodeXmlElement(XmlObject.Factory.parse(geometryCursor.getDomNode()));
                if (sosGeometry instanceof Geometry) {
                    spatialFilter.setGeometry((Geometry) sosGeometry);
                }
            } else {
                throw unsupportedSpatialFilter();
            }
            geometryCursor.dispose();
        } else {
            throw unsupportedSpatialFilter();
        }
    } catch (XmlException xmle) {
        throw errorParsingSpatialFilter(xmle);
    }
    return spatialFilter;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) XmlException(org.apache.xmlbeans.XmlException) SpatialFilter(org.n52.shetland.ogc.filter.SpatialFilter) XmlObject(org.apache.xmlbeans.XmlObject) BBOXTypeImpl(net.opengis.ogc.impl.BBOXTypeImpl) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 73 with XmlCursor

use of org.apache.xmlbeans.XmlCursor 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 74 with XmlCursor

use of org.apache.xmlbeans.XmlCursor in project arctic-sea by 52North.

the class GmlEncoderv311 method createPolygonFromJtsGeometry.

/**
 * Creates a XML Polygon from a SOS Polygon.
 *
 * @param jtsPolygon
 *            SOS Polygon
 * @param xbPolType
 *            XML Polygon
 */
private void createPolygonFromJtsGeometry(Polygon jtsPolygon, PolygonType xbPolType) {
    List<?> jtsPolygons = PolygonExtracter.getPolygons(jtsPolygon);
    for (int i = 0; i < jtsPolygons.size(); i++) {
        Polygon pol = (Polygon) jtsPolygons.get(i);
        AbstractRingPropertyType xbArpt = xbPolType.addNewExterior();
        AbstractRingType xbArt = xbArpt.addNewRing();
        LinearRingType xbLrt = LinearRingType.Factory.newInstance(getXmlOptions());
        // Exterior ring
        LineString ring = pol.getExteriorRing();
        String coords = JTSHelper.getCoordinatesString(ring);
        DirectPositionListType xbPosList = xbLrt.addNewPosList();
        xbPosList.setSrsName(getSrsName(jtsPolygon));
        // switch coordinates
        xbPosList.setStringValue(coords);
        xbArt.set(xbLrt);
        // Rename element name for output
        XmlCursor cursor = xbArpt.newCursor();
        if (cursor.toChild(GmlConstants.QN_ABSTRACT_RING)) {
            cursor.setName(GmlConstants.QN_LINEAR_RING);
        }
        // Interior ring
        int numberOfInteriorRings = pol.getNumInteriorRing();
        for (int ringNumber = 0; ringNumber < numberOfInteriorRings; ringNumber++) {
            xbArpt = xbPolType.addNewInterior();
            xbArt = xbArpt.addNewRing();
            xbLrt = LinearRingType.Factory.newInstance(getXmlOptions());
            ring = pol.getInteriorRingN(ringNumber);
            xbPosList = xbLrt.addNewPosList();
            xbPosList.setSrsName(getSrsName(jtsPolygon));
            xbPosList.setStringValue(JTSHelper.getCoordinatesString(ring));
            xbArt.set(xbLrt);
            // Rename element name for output
            cursor = xbArpt.newCursor();
            if (cursor.toChild(GmlConstants.QN_ABSTRACT_RING)) {
                cursor.setName(GmlConstants.QN_LINEAR_RING);
            }
        }
    }
}
Also used : AbstractRingType(net.opengis.gml.AbstractRingType) LineString(org.locationtech.jts.geom.LineString) AbstractRingPropertyType(net.opengis.gml.AbstractRingPropertyType) LinearRingType(net.opengis.gml.LinearRingType) DirectPositionListType(net.opengis.gml.DirectPositionListType) LineString(org.locationtech.jts.geom.LineString) Polygon(org.locationtech.jts.geom.Polygon) Point(org.locationtech.jts.geom.Point) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 75 with XmlCursor

use of org.apache.xmlbeans.XmlCursor in project arctic-sea by 52North.

the class GmlEncoderv321 method createPolygonFromJtsGeometry.

/**
 * Creates a XML Polygon from a SOS Polygon.
 *
 * @param jtsPolygon
 *            SOS Polygon
 * @param xbPolType
 *            XML Polygon
 */
private void createPolygonFromJtsGeometry(Polygon jtsPolygon, PolygonType xbPolType) {
    List<?> jtsPolygons = PolygonExtracter.getPolygons(jtsPolygon);
    String srsName = getSrsName(jtsPolygon);
    for (int i = 0; i < jtsPolygons.size(); i++) {
        Polygon pol = (Polygon) jtsPolygons.get(i);
        AbstractRingPropertyType xbArpt = xbPolType.addNewExterior();
        AbstractRingType xbArt = xbArpt.addNewAbstractRing();
        LinearRingType xbLrt = LinearRingType.Factory.newInstance();
        // Exterior ring
        LineString ring = pol.getExteriorRing();
        DirectPositionListType xbPosList = xbLrt.addNewPosList();
        xbPosList.setSrsName(srsName);
        xbPosList.setStringValue(JTSHelper.getCoordinatesString(ring));
        xbArt.set(xbLrt);
        // Rename element name for output
        XmlCursor cursor = xbArpt.newCursor();
        if (cursor.toChild(GmlConstants.QN_ABSTRACT_RING_32)) {
            cursor.setName(GmlConstants.QN_LINEAR_RING_32);
        }
        // Interior ring
        int numberOfInteriorRings = pol.getNumInteriorRing();
        for (int ringNumber = 0; ringNumber < numberOfInteriorRings; ringNumber++) {
            xbArpt = xbPolType.addNewInterior();
            xbArt = xbArpt.addNewAbstractRing();
            xbLrt = LinearRingType.Factory.newInstance();
            ring = pol.getInteriorRingN(ringNumber);
            xbPosList = xbLrt.addNewPosList();
            xbPosList.setSrsName(srsName);
            xbPosList.setStringValue(JTSHelper.getCoordinatesString(ring));
            xbArt.set(xbLrt);
            // Rename element name for output
            cursor = xbArpt.newCursor();
            if (cursor.toChild(GmlConstants.QN_ABSTRACT_RING_32)) {
                cursor.setName(GmlConstants.QN_LINEAR_RING_32);
            }
        }
    }
}
Also used : AbstractRingType(net.opengis.gml.x32.AbstractRingType) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) AbstractRingPropertyType(net.opengis.gml.x32.AbstractRingPropertyType) LinearRingType(net.opengis.gml.x32.LinearRingType) DirectPositionListType(net.opengis.gml.x32.DirectPositionListType) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) Polygon(org.locationtech.jts.geom.Polygon) MultiPoint(org.locationtech.jts.geom.MultiPoint) Point(org.locationtech.jts.geom.Point) XmlCursor(org.apache.xmlbeans.XmlCursor)

Aggregations

XmlCursor (org.apache.xmlbeans.XmlCursor)160 XmlObject (org.apache.xmlbeans.XmlObject)68 QName (javax.xml.namespace.QName)21 XmlException (org.apache.xmlbeans.XmlException)16 TokenType (org.apache.xmlbeans.XmlCursor.TokenType)14 CTTbl (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl)14 CTP (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP)10 ArrayList (java.util.ArrayList)9 POSIXApplicationType (org.ggf.schemas.jsdl.x2005.x11.jsdlPosix.POSIXApplicationType)8 HPCProfileApplicationType (org.ggf.schemas.jsdl.x2006.x07.jsdlHpcpa.HPCProfileApplicationType)8 SPMDApplicationType (org.ogf.schemas.jsdl.x2007.x02.jsdlSpmd.SPMDApplicationType)8 IOException (java.io.IOException)5 POIXMLException (org.apache.poi.POIXMLException)5 InputStream (java.io.InputStream)4 DrawPaint (org.apache.poi.sl.draw.DrawPaint)3 ArrayType (org.dmg.pmml.ArrayType)3 ApplicationType (org.ggf.schemas.jsdl.x2005.x11.jsdl.ApplicationType)3 LineString (org.locationtech.jts.geom.LineString)3 CTRow (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow)3 CTSdtBlock (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock)3