Search in sources :

Example 36 with LineString

use of org.locationtech.jts.geom.LineString in project yyl_example by Relucent.

the class JtsGeometryExample2 method equalsGeo.

/**
 * 两个几何对象是否是重叠的
 * @return 是否是重叠的
 * @throws ParseException
 */
public static boolean equalsGeo() throws ParseException {
    WKTReader reader = new WKTReader(GEOMETRY_FACTORY);
    LineString geometry1 = (LineString) reader.read("LINESTRING(0 0, 2 0, 5 0)");
    LineString geometry2 = (LineString) reader.read("LINESTRING(5 0, 0 0)");
    // true
    return geometry1.equals(geometry2);
}
Also used : LineString(org.locationtech.jts.geom.LineString) WKTReader(org.locationtech.jts.io.WKTReader)

Example 37 with LineString

use of org.locationtech.jts.geom.LineString in project yyl_example by Relucent.

the class JtsGeometryExample1 method createMLine.

/**
 * create multiLine
 * @return 多线
 */
public static MultiLineString createMLine() {
    Coordinate[] coords1 = new Coordinate[] { new Coordinate(2, 2), new Coordinate(2, 2) };
    LineString line1 = GEOMETRY_FACTORY.createLineString(coords1);
    Coordinate[] coords2 = new Coordinate[] { new Coordinate(2, 2), new Coordinate(2, 2) };
    LineString line2 = GEOMETRY_FACTORY.createLineString(coords2);
    LineString[] lineStrings = new LineString[2];
    lineStrings[0] = line1;
    lineStrings[1] = line2;
    MultiLineString ms = GEOMETRY_FACTORY.createMultiLineString(lineStrings);
    return ms;
}
Also used : MultiLineString(org.locationtech.jts.geom.MultiLineString) Coordinate(org.locationtech.jts.geom.Coordinate) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString)

Example 38 with LineString

use of org.locationtech.jts.geom.LineString in project jena by apache.

the class GeometryReverse method reverseGeometry.

/**
 * Reverses coordinate order of the supplied geometry and produces a new
 * geometry.
 *
 * @param geometry
 * @return Geometry in x,y coordinate order.
 */
public static Geometry reverseGeometry(Geometry geometry) {
    if (geometry.isEmpty()) {
        return geometry.copy();
    }
    GeometryFactory factory = geometry.getFactory();
    Geometry finalGeometry;
    Coordinate[] coordinates;
    String type = geometry.getGeometryType();
    switch(type) {
        case "LineString":
            coordinates = getReversedCoordinates(geometry);
            finalGeometry = factory.createLineString(coordinates);
            break;
        case "LinearRing":
            coordinates = getReversedCoordinates(geometry);
            finalGeometry = factory.createLinearRing(coordinates);
            break;
        case "MultiPoint":
            coordinates = getReversedCoordinates(geometry);
            finalGeometry = factory.createMultiPointFromCoords(coordinates);
            break;
        case "Polygon":
            finalGeometry = reversePolygon(geometry, factory);
            break;
        case "Point":
            coordinates = getReversedCoordinates(geometry);
            finalGeometry = factory.createPoint(coordinates[0]);
            break;
        case "MultiPolygon":
            Polygon[] polygons = unpackPolygons((GeometryCollection) geometry);
            finalGeometry = factory.createMultiPolygon(polygons);
            break;
        case "MultiLineString":
            LineString[] lineString = unpackLineStrings((GeometryCollection) geometry);
            finalGeometry = factory.createMultiLineString(lineString);
            break;
        case "GeometryCollection":
            Geometry[] geometries = unpackGeometryCollection((GeometryCollection) geometry);
            finalGeometry = factory.createGeometryCollection(geometries);
            break;
        default:
            finalGeometry = geometry;
            break;
    }
    return finalGeometry;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate) LineString(org.locationtech.jts.geom.LineString) LineString(org.locationtech.jts.geom.LineString) Polygon(org.locationtech.jts.geom.Polygon)

Example 39 with LineString

use of org.locationtech.jts.geom.LineString 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 40 with LineString

use of org.locationtech.jts.geom.LineString in project jena by apache.

the class WKTWriter method expand.

private static String expand(final Geometry geometry, final CoordinateSequenceDimensions dimensions) {
    String wktString = "";
    String dimensionString = CoordinateSequenceDimensions.convertDimensions(dimensions);
    switch(geometry.getGeometryType()) {
        case "Point":
            Point point = (Point) geometry;
            wktString = buildWKT("POINT", point.getCoordinateSequence(), dimensionString);
            break;
        case "LineString":
        case "LinearRing":
            LineString lineString = (LineString) geometry;
            wktString = buildWKT("LINESTRING", lineString.getCoordinateSequence(), dimensionString);
            break;
        case "Polygon":
            Polygon polygon = (Polygon) geometry;
            wktString = buildPolygon(polygon, true, dimensionString);
            break;
        case "MultiPoint":
            MultiPoint multiPoint = (MultiPoint) geometry;
            wktString = buildMultiPoint(multiPoint, dimensionString);
            break;
        case "MultiLineString":
            MultiLineString multiLineString = (MultiLineString) geometry;
            wktString = buildMultiLineString(multiLineString, dimensionString);
            break;
        case "MultiPolygon":
            MultiPolygon multiPolygon = (MultiPolygon) geometry;
            wktString = buildMultiPolygon(multiPolygon, dimensionString);
            break;
        case "GeometryCollection":
            GeometryCollection geometryCollection = (GeometryCollection) geometry;
            wktString = buildGeometryCollection(geometryCollection, dimensions);
            break;
    }
    return wktString;
}
Also used : MultiPoint(org.locationtech.jts.geom.MultiPoint) GeometryCollection(org.locationtech.jts.geom.GeometryCollection) MultiLineString(org.locationtech.jts.geom.MultiLineString) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint) Polygon(org.locationtech.jts.geom.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon)

Aggregations

LineString (org.locationtech.jts.geom.LineString)120 MultiLineString (org.locationtech.jts.geom.MultiLineString)48 Coordinate (org.locationtech.jts.geom.Coordinate)38 Geometry (org.locationtech.jts.geom.Geometry)35 Point (org.locationtech.jts.geom.Point)32 Test (org.junit.Test)24 Polygon (org.locationtech.jts.geom.Polygon)21 MultiPoint (org.locationtech.jts.geom.MultiPoint)19 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)14 WKTReader (org.locationtech.jts.io.WKTReader)13 ArrayList (java.util.ArrayList)12 CustomCoordinateSequence (org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence)12 HashMap (java.util.HashMap)10 DimensionInfo (org.apache.jena.geosparql.implementation.DimensionInfo)9 GeometryWrapper (org.apache.jena.geosparql.implementation.GeometryWrapper)9 ParseException (org.locationtech.jts.io.ParseException)9 DefaultGeometryProperty (eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty)8 GeometryNotSupportedException (eu.esdihumboldt.hale.io.gml.geometry.GeometryNotSupportedException)7 MultiPolygon (org.locationtech.jts.geom.MultiPolygon)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)6