Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If configured, add subway station entrances from OSM to walk steps #6076

Draft
wants to merge 32 commits into
base: dev-2.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
1d19a05
Add subway station entrances to walk steps
HenrikSundell Sep 18, 2024
67f4b1b
Add entity to walk steps
HenrikSundell Oct 2, 2024
9d18269
Add more parameters to Entrance
HenrikSundell Oct 3, 2024
3b88288
Move StepEntity classes
HenrikSundell Oct 7, 2024
0a62bf8
Remove default name for subway station entrances
HenrikSundell Oct 16, 2024
528ab55
Add option to turn on osm subway entrances in osmDefaults
HenrikSundell Oct 18, 2024
3e4ae96
Merge remote-tracking branch 'otp/dev-2.x' into station-entrances
HenrikSundell Oct 19, 2024
401a405
Fix walk step generation
HenrikSundell Oct 21, 2024
438bc31
Add step entity to graphql tests
HenrikSundell Oct 23, 2024
97c2de6
Rename variables to match with graphql
HenrikSundell Oct 25, 2024
d844561
Rename variables
HenrikSundell Oct 25, 2024
02a07ea
Rename function
HenrikSundell Oct 27, 2024
5dc74dd
Fix comments
HenrikSundell Oct 28, 2024
5d55646
Remove println
HenrikSundell Oct 28, 2024
d1067c6
Remove unnecessary imports
HenrikSundell Oct 28, 2024
5c97ad1
Add accessibilty information to entrances
HenrikSundell Oct 28, 2024
e10e0a2
Use existing entrance class for walk steps
HenrikSundell Nov 7, 2024
34761fe
Fix EntranceImpl
HenrikSundell Nov 7, 2024
c84b7cf
Add id to walk step entrances
HenrikSundell Nov 8, 2024
2ea8a52
Remove old file
HenrikSundell Nov 8, 2024
39b0db3
Fix otp version
HenrikSundell Nov 8, 2024
3b6bf3f
Remove unused import
HenrikSundell Nov 8, 2024
36be3dc
Merge remote-tracking branch 'otp/dev-2.x' into station-entrances
HenrikSundell Nov 8, 2024
c9df52d
Require entranceId
HenrikSundell Nov 10, 2024
7a9a8f6
Rename methods
HenrikSundell Nov 10, 2024
c9139e3
Update dosumentation
HenrikSundell Nov 11, 2024
7b21024
Update documentation
HenrikSundell Nov 11, 2024
ce7719c
Remove redundant null check
HenrikSundell Nov 11, 2024
b737411
Add feature union to steps
HenrikSundell Nov 14, 2024
f547e07
Return feature based on relativeDirection
HenrikSundell Nov 14, 2024
18b84f0
Remove StepFeature class
HenrikSundell Nov 14, 2024
2060016
Reuse transit entrance vertex
HenrikSundell Dec 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public static ApiRelativeDirection mapRelativeDirection(RelativeDirection domain
case UTURN_RIGHT -> ApiRelativeDirection.UTURN_RIGHT;
case ENTER_STATION -> ApiRelativeDirection.ENTER_STATION;
case EXIT_STATION -> ApiRelativeDirection.EXIT_STATION;
case ENTER_OR_EXIT_STATION -> ApiRelativeDirection.ENTER_OR_EXIT_STATION;
case FOLLOW_SIGNS -> ApiRelativeDirection.FOLLOW_SIGNS;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public ApiWalkStep mapWalkStep(WalkStep domain) {
api.streetName = domain.getDirectionText().toString(locale);
api.absoluteDirection =
domain.getAbsoluteDirection().map(AbsoluteDirectionMapper::mapAbsoluteDirection).orElse(null);
api.exit = domain.getExit();
api.exit = domain.getHighwayExit();
api.stayOn = domain.isStayOn();
api.area = domain.getArea();
api.bogusName = domain.getBogusName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ public enum ApiRelativeDirection {
UTURN_RIGHT,
ENTER_STATION,
EXIT_STATION,
ENTER_OR_EXIT_STATION,
FOLLOW_SIGNS,
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.opentripplanner.apis.gtfs.datafetchers.CurrencyImpl;
import org.opentripplanner.apis.gtfs.datafetchers.DefaultFareProductImpl;
import org.opentripplanner.apis.gtfs.datafetchers.DepartureRowImpl;
import org.opentripplanner.apis.gtfs.datafetchers.EntranceImpl;
import org.opentripplanner.apis.gtfs.datafetchers.FareProductTypeResolver;
import org.opentripplanner.apis.gtfs.datafetchers.FareProductUseImpl;
import org.opentripplanner.apis.gtfs.datafetchers.FeedImpl;
Expand All @@ -58,6 +59,7 @@
import org.opentripplanner.apis.gtfs.datafetchers.RouteImpl;
import org.opentripplanner.apis.gtfs.datafetchers.RouteTypeImpl;
import org.opentripplanner.apis.gtfs.datafetchers.RoutingErrorImpl;
import org.opentripplanner.apis.gtfs.datafetchers.StepFeatureTypeResolver;
import org.opentripplanner.apis.gtfs.datafetchers.StopGeometriesImpl;
import org.opentripplanner.apis.gtfs.datafetchers.StopImpl;
import org.opentripplanner.apis.gtfs.datafetchers.StopOnRouteImpl;
Expand Down Expand Up @@ -126,6 +128,7 @@ protected static GraphQLSchema buildSchema() {
.type("StopPosition", type -> type.typeResolver(new StopPosition() {}))
.type("FareProduct", type -> type.typeResolver(new FareProductTypeResolver()))
.type("AlertEntity", type -> type.typeResolver(new AlertEntityTypeResolver()))
.type("StepFeature", type -> type.typeResolver(new StepFeatureTypeResolver()))
.type(typeWiring.build(AgencyImpl.class))
.type(typeWiring.build(AlertImpl.class))
.type(typeWiring.build(BikeParkImpl.class))
Expand Down Expand Up @@ -179,6 +182,7 @@ protected static GraphQLSchema buildSchema() {
.type(typeWiring.build(FareProductUseImpl.class))
.type(typeWiring.build(DefaultFareProductImpl.class))
.type(typeWiring.build(TripOccupancyImpl.class))
.type(typeWiring.build(EntranceImpl.class))
.build();
SchemaGenerator schemaGenerator = new SchemaGenerator();
return schemaGenerator.makeExecutableSchema(typeRegistry, runtimeWiring);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.opentripplanner.apis.gtfs.datafetchers;

import graphql.schema.DataFetcher;
import org.opentripplanner.apis.gtfs.GraphQLUtils;
import org.opentripplanner.apis.gtfs.generated.GraphQLDataFetchers;
import org.opentripplanner.apis.gtfs.generated.GraphQLTypes;
import org.opentripplanner.transit.model.site.Entrance;

public class EntranceImpl implements GraphQLDataFetchers.GraphQLEntrance {

@Override
public DataFetcher<String> code() {
return environment -> {
Entrance entrance = environment.getSource();
return entrance.getCode();
};
}

@Override
public DataFetcher<String> entranceId() {
return environment -> {
Entrance entrance = environment.getSource();
return entrance.getId().toString();
};
}

@Override
public DataFetcher<String> name() {
return environment -> {
Entrance entrance = environment.getSource();
return org.opentripplanner.framework.graphql.GraphQLUtils.getTranslation(
entrance.getName(),
environment
);
};
}

@Override
public DataFetcher<GraphQLTypes.GraphQLWheelchairBoarding> wheelchairAccessible() {
return environment -> {
Entrance entrance = environment.getSource();
return GraphQLUtils.toGraphQL(entrance.getWheelchairAccessibility());
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.opentripplanner.apis.gtfs.datafetchers;

import graphql.TypeResolutionEnvironment;
import graphql.schema.GraphQLObjectType;
import graphql.schema.GraphQLSchema;
import graphql.schema.TypeResolver;
import org.opentripplanner.transit.model.site.Entrance;

public class StepFeatureTypeResolver implements TypeResolver {

@Override
public GraphQLObjectType getType(TypeResolutionEnvironment environment) {
Object o = environment.getObject();
GraphQLSchema schema = environment.getSchema();

if (o instanceof Entrance) {
return schema.getObjectType("Entrance");
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.opentripplanner.apis.gtfs.mapping.DirectionMapper;
import org.opentripplanner.apis.gtfs.mapping.StreetNoteMapper;
import org.opentripplanner.model.plan.ElevationProfile.Step;
import org.opentripplanner.model.plan.RelativeDirection;
import org.opentripplanner.model.plan.WalkStep;
import org.opentripplanner.routing.alertpatch.TransitAlert;

Expand Down Expand Up @@ -50,7 +51,18 @@ public DataFetcher<Iterable<Step>> elevationProfile() {

@Override
public DataFetcher<String> exit() {
return environment -> getSource(environment).getExit();
return environment -> getSource(environment).getHighwayExit();
}

@Override
public DataFetcher<Object> feature() {
return environment -> {
WalkStep source = getSource(environment);
if (source.getRelativeDirection() == RelativeDirection.ENTER_OR_EXIT_STATION) {
return source.getEntrance();
}
return null;
};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,17 @@ public interface GraphQLEmissions {
public DataFetcher<org.opentripplanner.framework.model.Grams> co2();
}

/** Station entrance or exit, originating from OSM or GTFS data. */
public interface GraphQLEntrance {
public DataFetcher<String> code();

public DataFetcher<String> entranceId();

public DataFetcher<String> name();

public DataFetcher<org.opentripplanner.apis.gtfs.generated.GraphQLTypes.GraphQLWheelchairBoarding> wheelchairAccessible();
}

/** A 'medium' that a fare product applies to, for example cash, 'Oyster Card' or 'DB Navigator App'. */
public interface GraphQLFareMedium {
public DataFetcher<String> id();
Expand Down Expand Up @@ -973,6 +984,8 @@ public interface GraphQLRoutingError {
public DataFetcher<GraphQLInputField> inputField();
}

public interface GraphQLStepFeature extends TypeResolver {}

/**
* Stop can represent either a single public transport stop, where passengers can
* board and/or disembark vehicles, or a station, which contains multiple stops.
Expand Down Expand Up @@ -1426,6 +1439,8 @@ public interface GraphQLStep {

public DataFetcher<String> exit();

public DataFetcher<Object> feature();

public DataFetcher<Double> lat();

public DataFetcher<Double> lon();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3994,6 +3994,7 @@ public enum GraphQLRelativeDirection {
CONTINUE,
DEPART,
ELEVATOR,
ENTER_OR_EXIT_STATION,
ENTER_STATION,
EXIT_STATION,
FOLLOW_SIGNS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public static GraphQLRelativeDirection map(RelativeDirection relativeDirection)
case UTURN_RIGHT -> GraphQLRelativeDirection.UTURN_RIGHT;
case ENTER_STATION -> GraphQLRelativeDirection.ENTER_STATION;
case EXIT_STATION -> GraphQLRelativeDirection.EXIT_STATION;
case ENTER_OR_EXIT_STATION -> GraphQLRelativeDirection.ENTER_OR_EXIT_STATION;
case FOLLOW_SIGNS -> GraphQLRelativeDirection.FOLLOW_SIGNS;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static GraphQLObjectType create(GraphQLObjectType elevationStepType) {
.name("exit")
.description("When exiting a highway or traffic circle, the exit name/number.")
.type(Scalars.GraphQLString)
.dataFetcher(environment -> ((WalkStep) environment.getSource()).getExit())
.dataFetcher(environment -> ((WalkStep) environment.getSource()).getHighwayExit())
.build()
)
.field(
Expand Down
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 @@ -69,6 +69,7 @@ static OsmModule provideOsmModule(
osmConfiguredDataSource.dataSource(),
osmConfiguredDataSource.config().osmTagMapper(),
osmConfiguredDataSource.config().timeZone(),
osmConfiguredDataSource.config().includeOsmSubwayEntrances(),
config.osmCacheDataInMem,
issueStore
)
Expand All @@ -84,6 +85,7 @@ static OsmModule provideOsmModule(
.withStaticBikeParkAndRide(config.staticBikeParkAndRide)
.withMaxAreaNodes(config.maxAreaNodes)
.withBoardingAreaRefTags(config.boardingLocationTags)
.withIncludeOsmSubwayEntrances(config.osmDefaults.includeOsmSubwayEntrances())
.withIssueStore(issueStore)
.withStreetLimitationParameters(streetLimitationParameters)
.build();
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 @@ -70,7 +69,13 @@ public class OsmModule implements GraphBuilderModule {
this.issueStore = issueStore;
this.params = params;
this.osmdb = new OsmDatabase(issueStore);
this.vertexGenerator = new VertexGenerator(osmdb, graph, params.boardingAreaRefTags());
this.vertexGenerator =
new VertexGenerator(
osmdb,
graph,
params.boardingAreaRefTags(),
params.includeOsmSubwayEntrances()
);
this.normalizer = new SafetyValueNormalizer(graph, issueStore);
this.streetLimitationParameters = Objects.requireNonNull(streetLimitationParameters);
}
Expand Down Expand Up @@ -289,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 @@ -459,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 @@ -513,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
Loading