Search in sources :

Example 51 with LineString

use of org.locationtech.jts.geom.LineString in project series-rest-api by 52North.

the class GeoJSONTest method testLineStringWithZCoordinate.

@Test
public void testLineStringWithZCoordinate() throws GeoJSONException {
    LineString geometry = randomLineString(CRSUtils.EPSG_WGS84);
    geometry.apply(new RandomZCoordinateFilter());
    geometry.geometryChanged();
    readWriteTest(geometry);
}
Also used : MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) Test(org.junit.jupiter.api.Test)

Example 52 with LineString

use of org.locationtech.jts.geom.LineString in project graphhopper by graphhopper.

the class GTFSFeed method getTripGeometry.

/**
 * Returns a trip geometry object (LineString) for a given trip id.
 * If the trip has a shape reference, this will be used for the geometry.
 * Otherwise, the ordered stoptimes will be used.
 *
 * @param   trip_id   trip id of desired trip geometry
 * @return          the LineString representing the trip geometry.
 * @see             LineString
 */
public LineString getTripGeometry(String trip_id) {
    CoordinateList coordinates = new CoordinateList();
    LineString ls = null;
    Trip trip = trips.get(trip_id);
    // If trip has shape_id, use it to generate geometry.
    if (trip.shape_id != null) {
        Shape shape = getShape(trip.shape_id);
        if (shape != null)
            ls = shape.geometry;
    }
    // Use the ordered stoptimes.
    if (ls == null) {
        ls = getStraightLineForStops(trip_id);
    }
    return ls;
}
Also used : LineString(org.locationtech.jts.geom.LineString) CoordinateList(org.locationtech.jts.geom.CoordinateList)

Example 53 with LineString

use of org.locationtech.jts.geom.LineString in project graphhopper by graphhopper.

the class GTFSFeed method getStraightLineForStops.

public LineString getStraightLineForStops(String trip_id) {
    CoordinateList coordinates = new CoordinateList();
    LineString ls = null;
    Trip trip = trips.get(trip_id);
    Iterable<StopTime> stopTimes;
    stopTimes = getOrderedStopTimesForTrip(trip.trip_id);
    if (Iterables.size(stopTimes) > 1) {
        for (StopTime stopTime : stopTimes) {
            Stop stop = stops.get(stopTime.stop_id);
            Double lat = stop.stop_lat;
            Double lon = stop.stop_lon;
            coordinates.add(new Coordinate(lon, lat));
        }
        ls = gf.createLineString(coordinates.toCoordinateArray());
    } else // set ls equal to null if there is only one stopTime to avoid an exception when creating linestring
    {
        ls = null;
    }
    return ls;
}
Also used : LineString(org.locationtech.jts.geom.LineString) Coordinate(org.locationtech.jts.geom.Coordinate) CoordinateList(org.locationtech.jts.geom.CoordinateList)

Example 54 with LineString

use of org.locationtech.jts.geom.LineString in project graphhopper by graphhopper.

the class AnotherAgencyIT method readWktLineString.

private LineString readWktLineString(String wkt) {
    WKTReader wktReader = new WKTReader();
    LineString expectedGeometry = null;
    try {
        expectedGeometry = (LineString) wktReader.read(wkt);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return expectedGeometry;
}
Also used : LineString(org.locationtech.jts.geom.LineString) ParseException(org.locationtech.jts.io.ParseException) WKTReader(org.locationtech.jts.io.WKTReader)

Example 55 with LineString

use of org.locationtech.jts.geom.LineString in project graphhopper by graphhopper.

the class FreeWalkIT method readWktLineString.

private LineString readWktLineString(String wkt) {
    WKTReader wktReader = new WKTReader();
    LineString expectedGeometry = null;
    try {
        expectedGeometry = (LineString) wktReader.read(wkt);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return expectedGeometry;
}
Also used : LineString(org.locationtech.jts.geom.LineString) ParseException(org.locationtech.jts.io.ParseException) WKTReader(org.locationtech.jts.io.WKTReader)

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