Search in sources :

Example 1 with CoordinateArrayListSequence

use of org.opentripplanner.api.resource.CoordinateArrayListSequence in project OpenTripPlanner by opentripplanner.

the class NearbyStopFinder method stopAtDistanceForState.

/**
 * Given a State at a TransitStop, bundle the TransitStop together with information about how far away it is
 * and the geometry of the path leading up to the given State.
 *
 * TODO this should probably be merged with similar classes in Profile routing.
 */
public static StopAtDistance stopAtDistanceForState(State state) {
    double distance = 0.0;
    GraphPath graphPath = new GraphPath(state, false);
    CoordinateArrayListSequence coordinates = new CoordinateArrayListSequence();
    List<Edge> edges = new ArrayList<>();
    for (Edge edge : graphPath.edges) {
        if (edge instanceof StreetEdge) {
            LineString geometry = edge.getGeometry();
            if (geometry != null) {
                if (coordinates.size() == 0) {
                    coordinates.extend(geometry.getCoordinates());
                } else {
                    coordinates.extend(geometry.getCoordinates(), 1);
                }
            }
            distance += edge.getDistance();
        }
        edges.add(edge);
    }
    if (coordinates.size() < 2) {
        // Otherwise the walk step generator breaks.
        ArrayList<Coordinate> coordinateList = new ArrayList<Coordinate>(2);
        coordinateList.add(graphPath.states.get(1).getVertex().getCoordinate());
        State lastState = graphPath.states.getLast().getBackState();
        coordinateList.add(lastState.getVertex().getCoordinate());
        coordinates = new CoordinateArrayListSequence(coordinateList);
    }
    StopAtDistance sd = new StopAtDistance((TransitStop) state.getVertex(), distance);
    sd.geom = geometryFactory.createLineString(new PackedCoordinateSequence.Double(coordinates.toCoordinateArray()));
    sd.edges = edges;
    return sd;
}
Also used : GraphPath(org.opentripplanner.routing.spt.GraphPath) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) CoordinateArrayListSequence(org.opentripplanner.api.resource.CoordinateArrayListSequence) LineString(com.vividsolutions.jts.geom.LineString) Coordinate(com.vividsolutions.jts.geom.Coordinate) State(org.opentripplanner.routing.core.State) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge)

Example 2 with CoordinateArrayListSequence

use of org.opentripplanner.api.resource.CoordinateArrayListSequence 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

LineString (com.vividsolutions.jts.geom.LineString)2 CoordinateArrayListSequence (org.opentripplanner.api.resource.CoordinateArrayListSequence)2 Coordinate (com.vividsolutions.jts.geom.Coordinate)1 PackedCoordinateSequence (org.opentripplanner.common.geometry.PackedCoordinateSequence)1 State (org.opentripplanner.routing.core.State)1 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)1 Edge (org.opentripplanner.routing.graph.Edge)1 GraphPath (org.opentripplanner.routing.spt.GraphPath)1