Search in sources :

Example 1 with DirectPositionListType

use of net.opengis.gml.DirectPositionListType in project arctic-sea by 52North.

the class GmlEncoderv311 method createLineStringFromJtsGeometry.

/**
 * Creates a XML LineString from a SOS LineString.
 *
 * @param jtsLineString
 *            SOS LineString
 * @param xbLst
 *            XML LinetSring
 */
private void createLineStringFromJtsGeometry(LineString jtsLineString, LineStringType xbLst) {
    DirectPositionListType xbPosList = xbLst.addNewPosList();
    xbPosList.setSrsName(getSrsName(jtsLineString));
    xbPosList.setStringValue(JTSHelper.getCoordinatesString(jtsLineString));
}
Also used : DirectPositionListType(net.opengis.gml.DirectPositionListType)

Example 2 with DirectPositionListType

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

Aggregations

DirectPositionListType (net.opengis.gml.DirectPositionListType)2 AbstractRingPropertyType (net.opengis.gml.AbstractRingPropertyType)1 AbstractRingType (net.opengis.gml.AbstractRingType)1 LinearRingType (net.opengis.gml.LinearRingType)1 XmlCursor (org.apache.xmlbeans.XmlCursor)1 LineString (org.locationtech.jts.geom.LineString)1 Point (org.locationtech.jts.geom.Point)1 Polygon (org.locationtech.jts.geom.Polygon)1