Search in sources :

Example 1 with CoordinateList

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

use of org.locationtech.jts.geom.CoordinateList 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)

Aggregations

CoordinateList (org.locationtech.jts.geom.CoordinateList)2 LineString (org.locationtech.jts.geom.LineString)2 Coordinate (org.locationtech.jts.geom.Coordinate)1