Search in sources :

Example 66 with CustomCoordinateSequence

use of org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence in project jena by apache.

the class GMLWriter method buildLineString.

private static Element buildLineString(final CoordinateSequence coordSeq, final String srsName) {
    CustomCoordinateSequence coordSequence = (CustomCoordinateSequence) coordSeq;
    Element gmlRoot = new Element("LineString", GML_NAMESPACE);
    gmlRoot.setAttribute("srsName", srsName);
    if (coordSequence.size() > 0) {
        Element posList = new Element("posList", GML_NAMESPACE);
        posList.addContent(convertToGMLText(coordSequence));
        gmlRoot.addContent(posList);
    }
    return gmlRoot;
}
Also used : Element(org.jdom2.Element) CustomCoordinateSequence(org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence)

Example 67 with CustomCoordinateSequence

use of org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence in project jena by apache.

the class WKTReader method buildGeometry.

private Geometry buildGeometry(String geometryType, String coordinates) throws DatatypeFormatException {
    Geometry geo;
    try {
        switch(geometryType) {
            case "point":
                CustomCoordinateSequence pointSequence = new CustomCoordinateSequence(dims, clean(coordinates));
                geo = GEOMETRY_FACTORY.createPoint(pointSequence);
                break;
            case "linestring":
                CustomCoordinateSequence lineSequence = new CustomCoordinateSequence(dims, clean(coordinates));
                geo = GEOMETRY_FACTORY.createLineString(lineSequence);
                break;
            case "linearring":
                CustomCoordinateSequence linearSequence = new CustomCoordinateSequence(dims, clean(coordinates));
                geo = GEOMETRY_FACTORY.createLinearRing(linearSequence);
                break;
            case "polygon":
                geo = buildPolygon(coordinates);
                break;
            case "multipoint":
                CustomCoordinateSequence multiPointSequence = new CustomCoordinateSequence(dims, clean(coordinates));
                geo = GEOMETRY_FACTORY.createMultiPoint(multiPointSequence);
                break;
            case "multilinestring":
                geo = buildMultiLineString(coordinates);
                break;
            case "multipolygon":
                geo = buildMultiPolygon(coordinates);
                break;
            case "geometrycollection":
                geo = buildGeometryCollection(coordinates);
                break;
            default:
                throw new DatatypeFormatException("Geometry type not supported: " + geometryType);
        }
    } catch (ArrayIndexOutOfBoundsException ex) {
        throw new DatatypeFormatException("Build WKT Geometry Exception - Type: " + geometryType + ", Coordinates: " + coordinates + ". " + ex.getMessage());
    }
    return geo;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) DatatypeFormatException(org.apache.jena.datatypes.DatatypeFormatException) CustomCoordinateSequence(org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence)

Example 68 with CustomCoordinateSequence

use of org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence in project jena by apache.

the class WKTWriter method buildMultiPoint.

private static String buildMultiPoint(final MultiPoint multiPoint, final String dimensionString) {
    StringBuilder sb = new StringBuilder("MULTIPOINT");
    if (!multiPoint.isEmpty()) {
        sb.append(dimensionString);
        sb.append("(");
        // Find first point
        Point point = (Point) multiPoint.getGeometryN(0);
        CustomCoordinateSequence coordSequence = (CustomCoordinateSequence) point.getCoordinateSequence();
        sb.append(buildWKT("", coordSequence));
        // Encode remaining points
        int geomCount = multiPoint.getNumGeometries();
        for (int i = 1; i < geomCount; i++) {
            sb.append(", ");
            point = (Point) multiPoint.getGeometryN(i);
            coordSequence = (CustomCoordinateSequence) point.getCoordinateSequence();
            sb.append(buildWKT("", coordSequence));
        }
        sb.append(")");
    } else {
        sb.append(" EMPTY");
    }
    return sb.toString();
}
Also used : Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint) CustomCoordinateSequence(org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint)

Example 69 with CustomCoordinateSequence

use of org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence in project jena by apache.

the class WKTWriter method buildPolygon.

private static String buildPolygon(final Polygon polygon, final boolean isIncludeGeometryType, final String dimensionString) {
    StringBuilder sb = new StringBuilder();
    if (isIncludeGeometryType) {
        sb.append("POLYGON");
    }
    if (!polygon.isEmpty()) {
        if (isIncludeGeometryType) {
            sb.append(dimensionString);
        }
        sb.append("(");
        // Find exterior shell
        LineString lineString = polygon.getExteriorRing();
        CustomCoordinateSequence coordSequence = (CustomCoordinateSequence) lineString.getCoordinateSequence();
        sb.append(convertToWKTText(coordSequence));
        // Find inner holes
        int interiorRings = polygon.getNumInteriorRing();
        for (int i = 0; i < interiorRings; i++) {
            sb.append(", ");
            LineString innerLineString = polygon.getInteriorRingN(i);
            CustomCoordinateSequence innerCoordSequence = (CustomCoordinateSequence) innerLineString.getCoordinateSequence();
            sb.append(convertToWKTText(innerCoordSequence));
        }
        sb.append(")");
    } else {
        sb.append(" EMPTY");
    }
    return sb.toString();
}
Also used : MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) CustomCoordinateSequence(org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint)

Example 70 with CustomCoordinateSequence

use of org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence in project jena by apache.

the class WKTWriter method buildMultiLineString.

private static String buildMultiLineString(final MultiLineString multiLineString, final String dimensionString) {
    StringBuilder sb = new StringBuilder("MULTILINESTRING");
    if (!multiLineString.isEmpty()) {
        sb.append(dimensionString);
        sb.append("(");
        // Find first linestring
        LineString lineString = (LineString) multiLineString.getGeometryN(0);
        CustomCoordinateSequence coordSequence = (CustomCoordinateSequence) lineString.getCoordinateSequence();
        sb.append(buildWKT("", coordSequence));
        // Encode remaining points
        int geomCount = multiLineString.getNumGeometries();
        for (int i = 1; i < geomCount; i++) {
            sb.append(", ");
            lineString = (LineString) multiLineString.getGeometryN(i);
            coordSequence = (CustomCoordinateSequence) lineString.getCoordinateSequence();
            sb.append(buildWKT("", coordSequence));
        }
        sb.append(")");
    } else {
        sb.append(" EMPTY");
    }
    return sb.toString();
}
Also used : MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) CustomCoordinateSequence(org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint)

Aggregations

CustomCoordinateSequence (org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence)72 Geometry (org.locationtech.jts.geom.Geometry)49 Test (org.junit.Test)48 LineString (org.locationtech.jts.geom.LineString)44 DimensionInfo (org.apache.jena.geosparql.implementation.DimensionInfo)39 GeometryWrapper (org.apache.jena.geosparql.implementation.GeometryWrapper)39 LinearRing (org.locationtech.jts.geom.LinearRing)10 Polygon (org.locationtech.jts.geom.Polygon)8 Element (org.jdom2.Element)4 MultiLineString (org.locationtech.jts.geom.MultiLineString)3 MultiPoint (org.locationtech.jts.geom.MultiPoint)3 Point (org.locationtech.jts.geom.Point)3 DatatypeFormatException (org.apache.jena.datatypes.DatatypeFormatException)2 ArrayList (java.util.ArrayList)1 Coordinate (org.locationtech.jts.geom.Coordinate)1 CoordinateXY (org.locationtech.jts.geom.CoordinateXY)1