Search in sources :

Example 6 with DirectPositionListType

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

the class GmlDecoderv321 method parseLineStringType.

private Geometry parseLineStringType(LineStringType xbLineStringType) throws DecodingException {
    int srid = -1;
    if (xbLineStringType.getSrsName() != null) {
        srid = CRSHelper.parseSrsName(xbLineStringType.getSrsName());
    }
    DirectPositionType[] xbPositions = xbLineStringType.getPosArray();
    String geomWKT;
    if (xbPositions != null && xbPositions.length > 0) {
        if (srid == -1 && xbPositions[0].getSrsName() != null && !(xbPositions[0].getSrsName().isEmpty())) {
            srid = CRSHelper.parseSrsName(xbPositions[0].getSrsName());
        }
        geomWKT = "LINESTRING" + getString4PosArray(xbLineStringType.getPosArray(), false) + "";
    } else if (xbLineStringType.getPosList() != null) {
        StringBuilder builder = new StringBuilder();
        builder.append("LINESTRING(");
        DirectPositionListType posList = xbLineStringType.getPosList();
        int dim;
        if (posList.getSrsDimension() == null) {
            dim = 2;
        } else {
            dim = posList.getSrsDimension().intValue();
        }
        if (posList.getListValue().size() % dim != 0) {
            throw new DecodingException("posList does not contain a multiple of %d coordinates", dim);
        }
        @SuppressWarnings("unchecked") Iterator<Double> iterator = posList.getListValue().iterator();
        if (iterator.hasNext()) {
            builder.append(iterator.next());
            for (int i = 1; i < dim; ++i) {
                builder.append(' ').append(iterator.next());
            }
            while (iterator.hasNext()) {
                builder.append(", ");
                builder.append(iterator.next());
                for (int i = 1; i < dim; ++i) {
                    builder.append(' ').append(iterator.next());
                }
            }
        }
        builder.append(")");
        geomWKT = builder.toString();
    } else {
        geomWKT = null;
    }
    srid = setDefaultForUnsetSrid(srid);
    if (geomWKT != null) {
        try {
            return JTSHelper.createGeometryFromWKT(geomWKT, srid);
        } catch (ParseException ex) {
            throw new DecodingException(ex);
        }
    } else {
        return JTSHelper.getGeometryFactoryForSRID(srid).createGeometryCollection(null);
    }
}
Also used : DirectPositionType(net.opengis.gml.x32.DirectPositionType) DirectPositionListType(net.opengis.gml.x32.DirectPositionListType) Iterator(java.util.Iterator) DecodingException(org.n52.svalbard.decode.exception.DecodingException) DateTimeParseException(org.n52.shetland.util.DateTimeParseException) ParseException(org.locationtech.jts.io.ParseException)

Aggregations

DirectPositionListType (net.opengis.gml.x32.DirectPositionListType)5 DirectPositionType (net.opengis.gml.x32.DirectPositionType)2 LineString (org.locationtech.jts.geom.LineString)2 MultiLineString (org.locationtech.jts.geom.MultiLineString)2 DecodingException (org.n52.svalbard.decode.exception.DecodingException)2 Coordinate (com.vividsolutions.jts.geom.Coordinate)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 DirectPositionListType (net.opengis.gml.v_3_1_1.DirectPositionListType)1 LinearRingType (net.opengis.gml.v_3_1_1.LinearRingType)1 AbstractRingPropertyType (net.opengis.gml.x32.AbstractRingPropertyType)1 AbstractRingType (net.opengis.gml.x32.AbstractRingType)1 CoordinatesType (net.opengis.gml.x32.CoordinatesType)1 LineStringDocument (net.opengis.gml.x32.LineStringDocument)1 LineStringType (net.opengis.gml.x32.LineStringType)1 LinearRingType (net.opengis.gml.x32.LinearRingType)1 SimpleMultiPointDocument (net.opengis.gml.x33.ce.SimpleMultiPointDocument)1 SimpleMultiPointType (net.opengis.gml.x33.ce.SimpleMultiPointType)1 XmlCursor (org.apache.xmlbeans.XmlCursor)1 XmlObject (org.apache.xmlbeans.XmlObject)1