Search in sources :

Example 6 with ParseException

use of org.locationtech.jts.io.ParseException 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)

Example 7 with ParseException

use of org.locationtech.jts.io.ParseException in project arctic-sea by 52North.

the class GmlDecoderv321 method parsePolygonType.

private Geometry parsePolygonType(PolygonType xbPolygonType) throws DecodingException {
    int srid = -1;
    if (xbPolygonType.getSrsName() != null) {
        srid = CRSHelper.parseSrsName(xbPolygonType.getSrsName());
    }
    String exteriorCoordString = null;
    StringBuilder geomWKT = new StringBuilder();
    StringBuilder interiorCoordString = new StringBuilder();
    AbstractRingPropertyType xbExterior = xbPolygonType.getExterior();
    if (xbExterior != null) {
        AbstractRingType xbExteriorRing = xbExterior.getAbstractRing();
        if (xbExteriorRing instanceof LinearRingType) {
            LinearRingType xbLinearRing = (LinearRingType) xbExteriorRing;
            exteriorCoordString = getCoordString4LinearRing(xbLinearRing);
        } else {
            throw new DecodingException("The Polygon must contain the following elements <gml:exterior><gml:LinearRing><gml:posList>!");
        }
    }
    AbstractRingPropertyType[] xbInterior = xbPolygonType.getInteriorArray();
    if (xbInterior != null && xbInterior.length != 0) {
        for (AbstractRingPropertyType xbInteriorRing : xbInterior) {
            if (xbInteriorRing.getAbstractRing() instanceof LinearRingType) {
                interiorCoordString.append(", ").append(getCoordString4LinearRing((LinearRingType) xbInteriorRing.getAbstractRing()));
            }
        }
    }
    geomWKT.append("POLYGON(");
    geomWKT.append(exteriorCoordString);
    geomWKT.append(interiorCoordString);
    geomWKT.append(")");
    srid = setDefaultForUnsetSrid(srid);
    try {
        return JTSHelper.createGeometryFromWKT(geomWKT.toString(), srid);
    } catch (ParseException ex) {
        throw new DecodingException(ex);
    }
}
Also used : AbstractRingType(net.opengis.gml.x32.AbstractRingType) AbstractRingPropertyType(net.opengis.gml.x32.AbstractRingPropertyType) LinearRingType(net.opengis.gml.x32.LinearRingType) DecodingException(org.n52.svalbard.decode.exception.DecodingException) DateTimeParseException(org.n52.shetland.util.DateTimeParseException) ParseException(org.locationtech.jts.io.ParseException)

Example 8 with ParseException

use of org.locationtech.jts.io.ParseException in project arctic-sea by 52North.

the class GmlDecoderv321 method parsePointType.

private Geometry parsePointType(PointType xbPointType) throws DecodingException {
    String geomWKT = null;
    int srid = -1;
    if (xbPointType.getSrsName() != null) {
        srid = CRSHelper.parseSrsName(xbPointType.getSrsName());
    }
    if (xbPointType.getPos() != null) {
        DirectPositionType xbPos = xbPointType.getPos();
        if (srid == -1 && xbPos.getSrsName() != null) {
            srid = CRSHelper.parseSrsName(xbPos.getSrsName());
        }
        String directPosition = getString4Pos(xbPos);
        geomWKT = "POINT(" + directPosition + ")";
    } else if (xbPointType.getCoordinates() != null) {
        CoordinatesType xbCoords = xbPointType.getCoordinates();
        String directPosition = getString4Coordinates(xbCoords);
        geomWKT = "POINT" + directPosition;
    } else {
        throw new DecodingException("For geometry type 'gml:Point' only element " + "'gml:pos' and 'gml:coordinates' are allowed " + "in the feature of interest parameter!");
    }
    srid = setDefaultForUnsetSrid(srid);
    try {
        return JTSHelper.createGeometryFromWKT(geomWKT, srid);
    } catch (ParseException ex) {
        throw new DecodingException(ex);
    }
}
Also used : DirectPositionType(net.opengis.gml.x32.DirectPositionType) DecodingException(org.n52.svalbard.decode.exception.DecodingException) DateTimeParseException(org.n52.shetland.util.DateTimeParseException) ParseException(org.locationtech.jts.io.ParseException) CoordinatesType(net.opengis.gml.x32.CoordinatesType)

Aggregations

ParseException (org.locationtech.jts.io.ParseException)8 DateTimeParseException (org.n52.shetland.util.DateTimeParseException)5 DecodingException (org.n52.svalbard.decode.exception.DecodingException)5 WKTReader (org.locationtech.jts.io.WKTReader)3 DirectPositionType (net.opengis.gml.x32.DirectPositionType)2 Geometry (org.locationtech.jts.geom.Geometry)2 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)2 PrecisionModel (org.locationtech.jts.geom.PrecisionModel)2 SQLException (java.sql.SQLException)1 Iterator (java.util.Iterator)1 CoordinatesType (net.opengis.gml.CoordinatesType)1 DirectPositionType (net.opengis.gml.DirectPositionType)1 EnvelopeType (net.opengis.gml.EnvelopeType)1 AbstractRingPropertyType (net.opengis.gml.x32.AbstractRingPropertyType)1 AbstractRingType (net.opengis.gml.x32.AbstractRingType)1 CoordinatesType (net.opengis.gml.x32.CoordinatesType)1 DirectPositionListType (net.opengis.gml.x32.DirectPositionListType)1 LinearRingType (net.opengis.gml.x32.LinearRingType)1 ValueGeometry (org.h2.value.ValueGeometry)1