Skip to content

Commit

Permalink
Add subway station entrances to walk steps
Browse files Browse the repository at this point in the history
  • Loading branch information
HenrikSundell committed Sep 18, 2024
1 parent be8578f commit 1d19a05
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public DataFetcher<String> exit() {
return environment -> getSource(environment).getExit();
}

@Override
public DataFetcher<String> entrance() {
return environment -> getSource(environment).getEntrance();
}

@Override
public DataFetcher<Double> lat() {
return environment -> getSource(environment).getStartLocation().latitude();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
package org.opentripplanner.apis.gtfs.generated;

import graphql.relay.Connection;
import graphql.relay.Connection;
import graphql.relay.DefaultEdge;
import graphql.relay.Edge;
import graphql.relay.Edge;
import graphql.schema.DataFetcher;
import graphql.schema.TypeResolver;
import java.util.Currency;
Expand All @@ -24,8 +26,12 @@
import org.opentripplanner.apis.gtfs.model.FeedPublisher;
import org.opentripplanner.apis.gtfs.model.PlanPageInfo;
import org.opentripplanner.apis.gtfs.model.RideHailingProvider;
import org.opentripplanner.apis.gtfs.model.RouteTypeModel;
import org.opentripplanner.apis.gtfs.model.StopOnRouteModel;
import org.opentripplanner.apis.gtfs.model.StopOnTripModel;
import org.opentripplanner.apis.gtfs.model.StopPosition;
import org.opentripplanner.apis.gtfs.model.TripOccupancy;
import org.opentripplanner.apis.gtfs.model.UnknownModel;
import org.opentripplanner.ext.fares.model.FareRuleSet;
import org.opentripplanner.ext.ridehailing.model.RideEstimate;
import org.opentripplanner.model.StopTimesInPattern;
Expand All @@ -48,6 +54,8 @@
import org.opentripplanner.routing.graphfinder.PatternAtStop;
import org.opentripplanner.routing.graphfinder.PlaceAtDistance;
import org.opentripplanner.routing.vehicle_parking.VehicleParking;
import org.opentripplanner.routing.vehicle_parking.VehicleParking;
import org.opentripplanner.routing.vehicle_parking.VehicleParking;
import org.opentripplanner.routing.vehicle_parking.VehicleParkingSpaces;
import org.opentripplanner.routing.vehicle_parking.VehicleParkingState;
import org.opentripplanner.service.realtimevehicles.model.RealtimeVehicle;
Expand All @@ -58,6 +66,7 @@
import org.opentripplanner.service.vehiclerental.model.VehicleRentalPlace;
import org.opentripplanner.service.vehiclerental.model.VehicleRentalStation;
import org.opentripplanner.service.vehiclerental.model.VehicleRentalStationUris;
import org.opentripplanner.service.vehiclerental.model.VehicleRentalStationUris;
import org.opentripplanner.service.vehiclerental.model.VehicleRentalSystem;
import org.opentripplanner.service.vehiclerental.model.VehicleRentalVehicle;
import org.opentripplanner.transit.model.basic.Money;
Expand Down Expand Up @@ -1419,6 +1428,8 @@ public interface GraphQLStep {

public DataFetcher<Iterable<org.opentripplanner.model.plan.ElevationProfile.Step>> elevationProfile();

public DataFetcher<String> entrance();

public DataFetcher<String> exit();

public DataFetcher<Double> lat();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
package org.opentripplanner.apis.gtfs.generated;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ IntersectionVertex getVertexForOsmNode(OSMNode node, OSMWithTags way) {
iv = bv;
}

if (node.isSubwayEntrance()) {
String ref = node.getTag("ref");
if (ref != null) {
iv = vertexFactory.stationEntrance(nid, coordinate, ref);
} else {
iv = vertexFactory.stationEntrance(nid, coordinate, "MAIN_ENTRANCE");
}
}

if (iv == null) {
iv =
vertexFactory.osm(
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/opentripplanner/model/plan/WalkStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public final class WalkStep {
private final boolean walkingBike;

private final String exit;
private final String entrance;
private final ElevationProfile elevationProfile;
private final boolean stayOn;

Expand All @@ -56,6 +57,7 @@ public final class WalkStep {
I18NString directionText,
Set<StreetNote> streetNotes,
String exit,
String entrance,
ElevationProfile elevationProfile,
boolean bogusName,
boolean walkingBike,
Expand All @@ -76,6 +78,7 @@ public final class WalkStep {
this.walkingBike = walkingBike;
this.area = area;
this.exit = exit;
this.entrance = entrance;
this.elevationProfile = elevationProfile;
this.stayOn = stayOn;
this.edges = List.copyOf(Objects.requireNonNull(edges));
Expand Down Expand Up @@ -130,6 +133,13 @@ public String getExit() {
return exit;
}

/**
* When entering or exiting a public transport station, the entrance name
*/
public String getEntrance() {
return entrance;
}

/**
* Indicates whether a street changes direction at an intersection.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class WalkStepBuilder {
private RelativeDirection relativeDirection;
private ElevationProfile elevationProfile;
private String exit;
private String entrance;
private boolean stayOn = false;
/**
* Distance used for appending elevation profiles
Expand Down Expand Up @@ -74,6 +75,11 @@ public WalkStepBuilder withExit(String exit) {
return this;
}

public WalkStepBuilder withEntrance(String entrance) {
this.entrance = entrance;
return this;
}

public WalkStepBuilder withStayOn(boolean stayOn) {
this.stayOn = stayOn;
return this;
Expand Down Expand Up @@ -156,6 +162,7 @@ public WalkStep build() {
directionText,
streetNotes,
exit,
entrance,
elevationProfile,
bogusName,
walkingBike,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ public boolean isBarrier() {
);
}

/**
* Checks if this node is an subway station entrance
*
* @return true if it does
*/
public boolean isSubwayEntrance() {
return hasTag("railway") && "subway_entrance".equals(getTag("railway"));
}

/**
* Consider barrier tag in permissions. Leave the rest for the super class.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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.Vertex;
import org.opentripplanner.street.search.TraverseMode;
import org.opentripplanner.street.search.state.State;
Expand Down Expand Up @@ -258,6 +259,8 @@ private void processState(State backState, State forwardState) {

setMotorwayExit(backState);

setStationEntrance(backState);

if (createdNewStep && !modeTransition) {
// check last three steps for zag
int lastIndex = steps.size() - 1;
Expand Down Expand Up @@ -380,6 +383,21 @@ private void setMotorwayExit(State backState) {
}
}

/**
* Update the walk step with the name of the station entrance if set from OSM
*/
private void setStationEntrance(State backState) {
State entranceState = backState;
Edge entranceEdge = entranceState.getBackEdge();
while (entranceEdge instanceof FreeEdge) {
entranceState = entranceState.getBackState();
entranceEdge = entranceState.getBackEdge();
}
if (entranceState.getVertex() instanceof StationEntranceVertex) {
current.withEntrance(((StationEntranceVertex) entranceState.getVertex()).getEntranceName());
}
}

/**
* Is it possible to turn to another street from this previous state
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.opentripplanner.street.model.vertex;

public class StationEntranceVertex extends OsmVertex {

private final String entranceName;

public StationEntranceVertex(double x, double y, long nodeId, String entranceName) {
super(x, y, nodeId);
this.entranceName = entranceName;
}

public String getEntranceName() {
return entranceName;
}

public String toString() {
return "StationEntranceVertex(" + super.toString() + ")";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ public ExitVertex exit(long nid, Coordinate coordinate, String exitName) {
return addToGraph(new ExitVertex(coordinate.x, coordinate.y, nid, exitName));
}

@Nonnull
public StationEntranceVertex stationEntrance(
long nid,
Coordinate coordinate,
String entranceName
) {
return addToGraph(new StationEntranceVertex(coordinate.x, coordinate.y, nid, entranceName));
}

@Nonnull
public OsmVertex osm(
Coordinate coordinate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2628,6 +2628,8 @@ type step {
elevationProfile: [elevationProfileComponent]
"When exiting a highway or traffic circle, the exit name/number."
exit: String
"Name of entrance to a public transport station"
entrance: String
"The latitude of the start of the step."
lat: Float
"The longitude of the start of the step."
Expand Down

0 comments on commit 1d19a05

Please sign in to comment.