Search in sources :

Example 6 with PackedCoordinateSequence

use of org.opentripplanner.common.geometry.PackedCoordinateSequence in project OpenTripPlanner by opentripplanner.

the class TripPattern method makeGeometry.

/**
 * Generates a geometry for the full pattern.
 * This is done by concatenating the shapes of all the constituent hops.
 * It could probably just come from the full shapes.txt entry for the trips in the route, but given all the details
 * in how the individual hop geometries are constructed we just recombine them here.
 */
public void makeGeometry() {
    CoordinateArrayListSequence coordinates = new CoordinateArrayListSequence();
    if (patternHops != null && patternHops.length > 0) {
        for (int i = 0; i < patternHops.length; i++) {
            LineString geometry = patternHops[i].getGeometry();
            if (geometry != null) {
                if (coordinates.size() == 0) {
                    coordinates.extend(geometry.getCoordinates());
                } else {
                    // Avoid duplicate coords at stops
                    coordinates.extend(geometry.getCoordinates(), 1);
                }
            }
        }
        // The CoordinateArrayListSequence is easy to append to, but is not serializable.
        // It might be possible to just mark it serializable, but it is not particularly compact either.
        // So we convert it to a packed coordinate sequence, since that is serializable and smaller.
        // FIXME It seems like we could simply accumulate the coordinates into an array instead of using the CoordinateArrayListSequence.
        PackedCoordinateSequence packedCoords = new PackedCoordinateSequence.Double(coordinates.toCoordinateArray(), 2);
        this.geometry = GeometryUtils.getGeometryFactory().createLineString(packedCoords);
    }
}
Also used : CoordinateArrayListSequence(org.opentripplanner.api.resource.CoordinateArrayListSequence) LineString(com.vividsolutions.jts.geom.LineString) PackedCoordinateSequence(org.opentripplanner.common.geometry.PackedCoordinateSequence)

Aggregations

PackedCoordinateSequence (org.opentripplanner.common.geometry.PackedCoordinateSequence)6 Coordinate (com.vividsolutions.jts.geom.Coordinate)4 LineString (com.vividsolutions.jts.geom.LineString)3 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)2 ElevationFlattened (org.opentripplanner.graph_builder.annotation.ElevationFlattened)2 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)2 State (org.opentripplanner.routing.core.State)2 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)2 StreetWithElevationEdge (org.opentripplanner.routing.edgetype.StreetWithElevationEdge)2 Edge (org.opentripplanner.routing.graph.Edge)2 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)2 TripDescriptor (com.google.transit.realtime.GtfsRealtime.TripDescriptor)1 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)1 StopTimeEvent (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeEvent)1 StopTimeUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate)1 Geometry (com.vividsolutions.jts.geom.Geometry)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 CalendarServiceImpl (org.onebusaway.gtfs.impl.calendar.CalendarServiceImpl)1