Skip to content

Commit

Permalink
Reuse transit entrance vertex
Browse files Browse the repository at this point in the history
  • Loading branch information
HenrikSundell committed Dec 3, 2024
1 parent 18b84f0 commit 2060016
Show file tree
Hide file tree
Showing 25 changed files with 287 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import org.opentripplanner.street.model.edge.StreetEdgeBuilder;
import org.opentripplanner.street.model.edge.StreetTransitStopLink;
import org.opentripplanner.street.model.vertex.OsmBoardingLocationVertex;
import org.opentripplanner.street.model.vertex.StreetVertex;
import org.opentripplanner.street.model.vertex.TransitStopVertex;
import org.opentripplanner.street.model.vertex.Vertex;
import org.opentripplanner.street.model.vertex.VertexFactory;
import org.opentripplanner.street.search.TraverseMode;
import org.opentripplanner.street.search.TraverseModeSet;
Expand Down Expand Up @@ -182,7 +182,7 @@ private boolean connectVertexToStop(TransitStopVertex ts, StreetIndex index) {
return false;
}

private StreetEdge linkBoardingLocationToStreetNetwork(StreetVertex from, StreetVertex to) {
private StreetEdge linkBoardingLocationToStreetNetwork(Vertex from, Vertex to) {
var line = GeometryUtils.makeLineString(List.of(from.getCoordinate(), to.getCoordinate()));
return new StreetEdgeBuilder<>()
.withFromVertex(from)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@
import org.opentripplanner.street.model.edge.StreetVehicleParkingLink;
import org.opentripplanner.street.model.edge.VehicleParkingEdge;
import org.opentripplanner.street.model.vertex.StationCentroidVertex;
import org.opentripplanner.street.model.vertex.StreetVertex;
import org.opentripplanner.street.model.vertex.TransitEntranceVertex;
import org.opentripplanner.street.model.vertex.TransitStopVertex;
import org.opentripplanner.street.model.vertex.VehicleParkingEntranceVertex;
import org.opentripplanner.street.model.vertex.Vertex;
import org.opentripplanner.street.search.TraverseMode;
import org.opentripplanner.street.search.TraverseModeSet;
import org.opentripplanner.transit.model.network.CarAccess;
import org.opentripplanner.transit.model.site.GroupStop;
import org.opentripplanner.transit.model.site.RegularStop;
import org.opentripplanner.transit.model.site.StopLocation;
Expand Down Expand Up @@ -170,10 +168,7 @@ private void linkToDriveableEdge(TransitStopVertex tStop) {
);
}

private static List<Edge> createStopLinkEdges(
TransitStopVertex vertex,
StreetVertex streetVertex
) {
private static List<Edge> createStopLinkEdges(TransitStopVertex vertex, Vertex streetVertex) {
return List.of(
StreetTransitStopLink.createStreetTransitStopLink(vertex, streetVertex),
StreetTransitStopLink.createStreetTransitStopLink(streetVertex, vertex)
Expand Down Expand Up @@ -230,6 +225,9 @@ private static void linkVehicleParkingWithLinker(
private void linkTransitEntrances(Graph graph) {
LOG.info("Linking transit entrances to graph...");
for (TransitEntranceVertex tEntrance : graph.getVerticesOfType(TransitEntranceVertex.class)) {
if (tEntrance.isConnectedToGraph()) {
continue;
}
graph
.getLinker()
.linkVertexPermanently(
Expand All @@ -252,7 +250,7 @@ private void linkTransitEntrances(Graph graph) {
}

private void linkStationCentroids(Graph graph) {
BiFunction<Vertex, StreetVertex, List<Edge>> stationAndStreetVertexLinker = (
BiFunction<Vertex, Vertex, List<Edge>> stationAndStreetVertexLinker = (
theStation,
streetVertex
) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.opentripplanner.street.model.edge.FreeEdge;
import org.opentripplanner.street.model.vertex.ElevatorOffboardVertex;
import org.opentripplanner.street.model.vertex.ElevatorOnboardVertex;
import org.opentripplanner.street.model.vertex.IntersectionVertex;
import org.opentripplanner.street.model.vertex.OsmVertex;
import org.opentripplanner.street.model.vertex.Vertex;
import org.opentripplanner.street.model.vertex.VertexFactory;
Expand Down Expand Up @@ -154,7 +153,7 @@ public void buildElevatorEdges(Graph graph) {
private static void createElevatorVertices(
Graph graph,
ArrayList<Vertex> onboardVertices,
IntersectionVertex sourceVertex,
Vertex sourceVertex,
String label,
String levelName
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
import java.util.Map;
import org.opentripplanner.osm.model.OsmWay;
import org.opentripplanner.street.model.edge.EscalatorEdge;
import org.opentripplanner.street.model.vertex.IntersectionVertex;
import org.opentripplanner.street.model.vertex.Vertex;

/**
* Contains the logic for extracting escalators out of OSM data
*/
class EscalatorProcessor {

private final Map<Long, IntersectionVertex> intersectionNodes;
private final Map<Long, Vertex> intersectionNodes;

public EscalatorProcessor(Map<Long, IntersectionVertex> intersectionNodes) {
public EscalatorProcessor(Map<Long, Vertex> intersectionNodes) {
this.intersectionNodes = intersectionNodes;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.opentripplanner.street.model.edge.StreetEdge;
import org.opentripplanner.street.model.edge.StreetEdgeBuilder;
import org.opentripplanner.street.model.vertex.BarrierVertex;
import org.opentripplanner.street.model.vertex.IntersectionVertex;
import org.opentripplanner.street.model.vertex.Vertex;
import org.opentripplanner.utils.logging.ProgressTracker;
import org.slf4j.Logger;
Expand Down Expand Up @@ -295,8 +294,8 @@ private void buildBasicGraph() {
lastLevel = level;
}

IntersectionVertex startEndpoint = null;
IntersectionVertex endEndpoint = null;
Vertex startEndpoint = null;
Vertex endEndpoint = null;

ArrayList<Coordinate> segmentCoordinates = new ArrayList<>();

Expand Down Expand Up @@ -465,8 +464,8 @@ private void applyEdgesToTurnRestrictions(
* http://wiki.openstreetmap.org/wiki/OSM_tags_for_routing#Oneway.
*/
private StreetEdgePair getEdgesForStreet(
IntersectionVertex startEndpoint,
IntersectionVertex endEndpoint,
Vertex startEndpoint,
Vertex endEndpoint,
OsmWay way,
int index,
StreetTraversalPermission permissions,
Expand Down Expand Up @@ -519,8 +518,8 @@ private StreetEdgePair getEdgesForStreet(
}

private StreetEdge getEdgeForStreet(
IntersectionVertex startEndpoint,
IntersectionVertex endEndpoint,
Vertex startEndpoint,
Vertex endEndpoint,
OsmWay way,
int index,
double length,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
import org.opentripplanner.street.model.edge.Edge;
import org.opentripplanner.street.model.edge.StreetEdge;
import org.opentripplanner.street.model.edge.VehicleParkingEdge;
import org.opentripplanner.street.model.vertex.IntersectionVertex;
import org.opentripplanner.street.model.vertex.VehicleParkingEntranceVertex;
import org.opentripplanner.street.model.vertex.Vertex;
import org.opentripplanner.street.model.vertex.VertexFactory;
import org.opentripplanner.street.search.TraverseMode;
import org.opentripplanner.transit.model.framework.FeedScopedId;
Expand All @@ -44,14 +44,14 @@ class ParkingProcessor {
private static final String VEHICLE_PARKING_OSM_FEED_ID = "OSM";
private final DataImportIssueStore issueStore;
private final OsmOpeningHoursParser osmOpeningHoursParser;
private final BiFunction<OsmNode, OsmWithTags, IntersectionVertex> getVertexForOsmNode;
private final BiFunction<OsmNode, OsmWithTags, Vertex> getVertexForOsmNode;
private final VertexFactory vertexFactory;
private final VehicleParkingHelper vehicleParkingHelper;

public ParkingProcessor(
Graph graph,
DataImportIssueStore issueStore,
BiFunction<OsmNode, OsmWithTags, IntersectionVertex> getVertexForOsmNode
BiFunction<OsmNode, OsmWithTags, Vertex> getVertexForOsmNode
) {
this.issueStore = issueStore;
this.getVertexForOsmNode = getVertexForOsmNode;
Expand Down Expand Up @@ -475,4 +475,4 @@ private List<VehicleParking.VehicleParkingEntranceCreator> createParkingEntrance
}
}

record VertexAndName(I18NString name, IntersectionVertex vertex) {}
record VertexAndName(I18NString name, Vertex vertex) {}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Map;
import java.util.Set;
import org.locationtech.jts.geom.Coordinate;
import org.opentripplanner.framework.geometry.WgsCoordinate;
import org.opentripplanner.framework.i18n.NonLocalizedString;
import org.opentripplanner.osm.model.OsmLevel;
import org.opentripplanner.osm.model.OsmNode;
Expand All @@ -15,10 +16,13 @@
import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.street.model.edge.ElevatorEdge;
import org.opentripplanner.street.model.vertex.BarrierVertex;
import org.opentripplanner.street.model.vertex.IntersectionVertex;
import org.opentripplanner.street.model.vertex.OsmBoardingLocationVertex;
import org.opentripplanner.street.model.vertex.OsmVertex;
import org.opentripplanner.street.model.vertex.Vertex;
import org.opentripplanner.street.model.vertex.VertexFactory;
import org.opentripplanner.transit.model.basic.Accessibility;
import org.opentripplanner.transit.model.framework.FeedScopedId;
import org.opentripplanner.transit.model.site.Entrance;

/**
* Tracks the generation of vertices and returns an existing instance if a vertex is encountered
Expand All @@ -28,7 +32,7 @@ class VertexGenerator {

private static final String nodeLabelFormat = "osm:node:%d";

private final Map<Long, IntersectionVertex> intersectionNodes = new HashMap<>();
private final Map<Long, Vertex> intersectionNodes = new HashMap<>();

private final HashMap<Long, Map<OsmLevel, OsmVertex>> multiLevelNodes = new HashMap<>();
private final OsmDatabase osmdb;
Expand Down Expand Up @@ -58,11 +62,11 @@ public VertexGenerator(
* @return vertex The graph vertex. This is not always an OSM vertex; it can also be a
* {@link OsmBoardingLocationVertex}
*/
IntersectionVertex getVertexForOsmNode(OsmNode node, OsmWithTags way) {
Vertex getVertexForOsmNode(OsmNode node, OsmWithTags way) {
// If the node should be decomposed to multiple levels,
// use the numeric level because it is unique, the human level may not be (although
// it will likely lead to some head-scratching if it is not).
IntersectionVertex iv = null;
Vertex iv = null;
if (node.isMultiLevel()) {
// make a separate node for every level
return recordLevel(node, way);
Expand Down Expand Up @@ -106,7 +110,18 @@ IntersectionVertex getVertexForOsmNode(OsmNode node, OsmWithTags way) {
String ref = node.getTag("ref");

boolean accessible = node.isTag("wheelchair", "yes");
iv = vertexFactory.stationEntrance(nid, coordinate, ref, accessible);

FeedScopedId id = new FeedScopedId("osm", Long.toString(nid));
Entrance entrance = Entrance
.of(id)
.withCoordinate(new WgsCoordinate(coordinate))
.withCode(ref)
.withWheelchairAccessibility(
accessible ? Accessibility.POSSIBLE : Accessibility.NOT_POSSIBLE
)
.build();

iv = vertexFactory.transitEntrance(entrance);
}

if (iv == null) {
Expand Down Expand Up @@ -161,7 +176,7 @@ void initIntersectionNodes() {
/**
* Track OSM nodes that will become graph vertices because they appear in multiple OSM ways
*/
Map<Long, IntersectionVertex> intersectionNodes() {
Map<Long, Vertex> intersectionNodes() {
return intersectionNodes;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public void buildWithVisibility(AreaGroup group) {
// or those linked to ways
HashSet<OsmNode> visibilityNodes = new HashSet<>();
HashSet<NodeEdge> alreadyAddedEdges = new HashSet<>();
HashSet<IntersectionVertex> platformLinkingVertices = new HashSet<>();
HashSet<Vertex> platformLinkingVertices = new HashSet<>();
// we need to accumulate visibility points from all contained areas
// inside this ring, but only for shared nodes; we don't care about
// convexity, which we'll handle for the grouped area only.
Expand Down Expand Up @@ -340,7 +340,7 @@ public void buildWithVisibility(AreaGroup group) {
continue;
}
i = (int) Math.floor(sum_i);
IntersectionVertex startEndpoint = vertexBuilder.getVertexForOsmNode(nodeI, areaEntity);
Vertex startEndpoint = vertexBuilder.getVertexForOsmNode(nodeI, areaEntity);
if (startingNodes.contains(nodeI)) {
startingVertices.add(startEndpoint);
}
Expand All @@ -355,7 +355,7 @@ public void buildWithVisibility(AreaGroup group) {
NodeEdge edge = new NodeEdge(nodeI, nodeJ);
if (alreadyAddedEdges.contains(edge)) continue;

IntersectionVertex endEndpoint = vertexBuilder.getVertexForOsmNode(nodeJ, areaEntity);
Vertex endEndpoint = vertexBuilder.getVertexForOsmNode(nodeJ, areaEntity);

Coordinate[] coordinates = new Coordinate[] {
startEndpoint.getCoordinate(),
Expand Down Expand Up @@ -463,15 +463,15 @@ private Set<AreaEdge> createEdgesForRingSegment(
return Set.of();
}
alreadyAddedEdges.add(nodeEdge);
IntersectionVertex startEndpoint = vertexBuilder.getVertexForOsmNode(node, area.parent);
IntersectionVertex endEndpoint = vertexBuilder.getVertexForOsmNode(nextNode, area.parent);
Vertex startEndpoint = vertexBuilder.getVertexForOsmNode(node, area.parent);
Vertex endEndpoint = vertexBuilder.getVertexForOsmNode(nextNode, area.parent);

return createSegments(startEndpoint, endEndpoint, List.of(area), edgeList);
}

private Set<AreaEdge> createSegments(
IntersectionVertex startEndpoint,
IntersectionVertex endEndpoint,
Vertex startEndpoint,
Vertex endEndpoint,
Collection<Area> areas,
AreaEdgeList edgeList
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,10 @@
import org.opentripplanner.street.model.edge.StreetEdge;
import org.opentripplanner.street.model.edge.StreetTransitEntranceLink;
import org.opentripplanner.street.model.vertex.ExitVertex;
import org.opentripplanner.street.model.vertex.StationEntranceVertex;
import org.opentripplanner.street.model.vertex.TransitEntranceVertex;
import org.opentripplanner.street.model.vertex.Vertex;
import org.opentripplanner.street.search.TraverseMode;
import org.opentripplanner.street.search.state.State;
import org.opentripplanner.transit.model.basic.Accessibility;
import org.opentripplanner.transit.model.framework.FeedScopedId;
import org.opentripplanner.transit.model.site.Entrance;

/**
* Process a list of states into a list of walking/driving instructions for a street leg.
Expand Down Expand Up @@ -179,7 +176,7 @@ private void processState(State backState, State forwardState) {
if (edge instanceof ElevatorAlightEdge) {
addStep(createElevatorWalkStep(backState, forwardState, edge));
return;
} else if (backState.getVertex() instanceof StationEntranceVertex) {
} else if (backState.getVertex() instanceof TransitEntranceVertex) {
addStep(createStationEntranceWalkStep(backState, forwardState, edge));
return;
} else if (edge instanceof PathwayEdge pwe && pwe.signpostedAs().isPresent()) {
Expand Down Expand Up @@ -533,20 +530,9 @@ private WalkStepBuilder createStationEntranceWalkStep(
// since the doors might be between or inside stations.
step.withRelativeDirection(RelativeDirection.ENTER_OR_EXIT_STATION);

StationEntranceVertex vertex = (StationEntranceVertex) backState.getVertex();
TransitEntranceVertex vertex = (TransitEntranceVertex) backState.getVertex();

FeedScopedId entranceId = new FeedScopedId("osm", vertex.getId());

Entrance entrance = Entrance
.of(entranceId)
.withCode(vertex.getCode())
.withCoordinate(new WgsCoordinate(vertex.getCoordinate()))
.withWheelchairAccessibility(
vertex.isAccessible() ? Accessibility.POSSIBLE : Accessibility.NOT_POSSIBLE
)
.build();

step.withEntrance(entrance);
step.withEntrance(vertex.getEntrance());
return step;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@
import org.opentripplanner.framework.geometry.GeometryUtils;
import org.opentripplanner.street.model.StreetTraversalPermission;
import org.opentripplanner.street.model.edge.StreetEdge;
import org.opentripplanner.street.model.vertex.IntersectionVertex;
import org.opentripplanner.street.model.vertex.Vertex;
import org.opentripplanner.transit.model.site.AreaStop;
import org.opentripplanner.transit.service.SiteRepository;

class FlexLocationAdder {

static void addFlexLocations(
StreetEdge edge,
IntersectionVertex v0,
SiteRepository siteRepository
) {
static void addFlexLocations(StreetEdge edge, Vertex v0, SiteRepository siteRepository) {
if (edge.getPermission().allows(StreetTraversalPermission.PEDESTRIAN_AND_CAR)) {
Point p = GeometryUtils.getGeometryFactory().createPoint(v0.getCoordinate());
Envelope env = p.getEnvelopeInternal();
Expand Down
Loading

0 comments on commit 2060016

Please sign in to comment.