Search in sources :

Example 1 with CustomCoordinateSequence

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

the class GMLReader method buildLinearRing.

private static LinearRing buildLinearRing(Element gmlElement, CoordinateSequenceDimensions dims) {
    int srsDimension = CoordinateSequenceDimensions.convertToInt(dims);
    String posList = extractPosList(gmlElement, srsDimension);
    CustomCoordinateSequence sequence = new CustomCoordinateSequence(dims, posList);
    LinearRing linearRing = GEOMETRY_FACTORY.createLinearRing(sequence);
    return linearRing;
}
Also used : CustomCoordinateSequence(org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence)

Example 2 with CustomCoordinateSequence

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

the class WKTReader method buildPolygon.

private Polygon buildPolygon(String coordinates) {
    Polygon polygon;
    String[] splitCoordinates = splitCoordinates(coordinates);
    if (splitCoordinates.length == 1) {
        // Polygon without holes.
        CustomCoordinateSequence shellSequence = new CustomCoordinateSequence(dims, clean(coordinates));
        polygon = GEOMETRY_FACTORY.createPolygon(shellSequence);
    } else {
        // Polygon with holes
        String shellCoordinates = splitCoordinates[0];
        CustomCoordinateSequence shellSequence = new CustomCoordinateSequence(dims, clean(shellCoordinates));
        LinearRing shellLinearRing = GEOMETRY_FACTORY.createLinearRing(shellSequence);
        String[] splitHoleCoordinates = Arrays.copyOfRange(splitCoordinates, 1, splitCoordinates.length);
        LinearRing[] holesLinearRing = splitLinearRings(dims, splitHoleCoordinates);
        polygon = GEOMETRY_FACTORY.createPolygon(shellLinearRing, holesLinearRing);
    }
    return polygon;
}
Also used : LineString(org.locationtech.jts.geom.LineString) Polygon(org.locationtech.jts.geom.Polygon) CustomCoordinateSequence(org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence) LinearRing(org.locationtech.jts.geom.LinearRing)

Example 3 with CustomCoordinateSequence

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

the class WKTReader method splitLineStrings.

private LineString[] splitLineStrings(String[] splitCoordinates) {
    LineString[] lineStrings = new LineString[splitCoordinates.length];
    for (int i = 0; i < splitCoordinates.length; i++) {
        CustomCoordinateSequence sequence = new CustomCoordinateSequence(dims, clean(splitCoordinates[i]));
        LineString lineString = GEOMETRY_FACTORY.createLineString(sequence);
        lineStrings[i] = lineString;
    }
    return lineStrings;
}
Also used : LineString(org.locationtech.jts.geom.LineString) CustomCoordinateSequence(org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence)

Example 4 with CustomCoordinateSequence

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

the class WKTReader method splitLinearRings.

private LinearRing[] splitLinearRings(CoordinateSequenceDimensions dims, String[] splitCoordinates) {
    LinearRing[] linearRings = new LinearRing[splitCoordinates.length];
    for (int i = 0; i < splitCoordinates.length; i++) {
        CustomCoordinateSequence sequence = new CustomCoordinateSequence(dims, clean(splitCoordinates[i]));
        LinearRing linearRing = GEOMETRY_FACTORY.createLinearRing(sequence);
        linearRings[i] = linearRing;
    }
    return linearRings;
}
Also used : LinearRing(org.locationtech.jts.geom.LinearRing) CustomCoordinateSequence(org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence)

Example 5 with CustomCoordinateSequence

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

the class GMLWriter method buildPolygon.

private static Element buildPolygon(final Polygon polygon, final String srsName) {
    Element gmlRoot = new Element(polygon.getGeometryType(), GML_NAMESPACE);
    gmlRoot.setAttribute("srsName", srsName);
    if (!polygon.isEmpty()) {
        LineString lineString = polygon.getExteriorRing();
        CustomCoordinateSequence coordSequence = (CustomCoordinateSequence) lineString.getCoordinateSequence();
        // Find exterior shell
        Element exterior = new Element("exterior", GML_NAMESPACE);
        Element exteriorLinearRing = new Element("LinearRing", GML_NAMESPACE);
        Element exteriorPosList = new Element("posList", GML_NAMESPACE);
        exteriorPosList.addContent(convertToGMLText(coordSequence));
        exteriorLinearRing.addContent(exteriorPosList);
        exterior.addContent(exteriorLinearRing);
        gmlRoot.addContent(exterior);
        // Find inner holes
        int interiorRings = polygon.getNumInteriorRing();
        for (int i = 0; i < interiorRings; i++) {
            // flush all content
            Element interior = new Element("interior", GML_NAMESPACE);
            Element interiorLinearRing = new Element("LinearRing", GML_NAMESPACE);
            Element innerPosList = new Element("posList", GML_NAMESPACE);
            LineString innerLineString = polygon.getInteriorRingN(i);
            CustomCoordinateSequence innerCoordSequence = (CustomCoordinateSequence) innerLineString.getCoordinateSequence();
            innerPosList.addContent(convertToGMLText(innerCoordSequence));
            interiorLinearRing.addContent(innerPosList);
            interior.addContent(interiorLinearRing);
            gmlRoot.addContent(interior);
        }
    } else {
    // Do nothing to the GML
    }
    return gmlRoot;
}
Also used : Element(org.jdom2.Element) CustomCoordinateSequence(org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence)

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