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 23 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 @@ -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 Down Expand Up @@ -179,6 +180,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,47 @@
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() != null ? entrance.getId().toString() : null;
HenrikSundell marked this conversation as resolved.
Show resolved Hide resolved
};
}

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import org.opentripplanner.framework.graphql.GraphQLUtils and just use GraphQLUtils.getTranslation. Also, you can mark the input parameter in the getTranslation method as nullable and just pass in the entrance's name to the method as it does the null checks.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for the full path is that org.opentripplanner.apis.gtfs.GraphQLUtils is already imported.

}

@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
Expand Up @@ -53,6 +53,11 @@ public DataFetcher<String> exit() {
return environment -> getSource(environment).getExit();
}

@Override
public DataFetcher<Object> 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
Expand Up @@ -357,6 +357,17 @@ public interface GraphQLEmissions {
public DataFetcher<org.opentripplanner.framework.model.Grams> co2();
}

/** Station entrance or exit. */
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 @@ -1424,6 +1435,8 @@ public interface GraphQLStep {

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

public DataFetcher<Object> entrance();

public DataFetcher<String> exit();

public DataFetcher<Double> lat();
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 @@ -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 @@ -70,7 +70,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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class OsmModuleBuilder {
private boolean platformEntriesLinking = false;
private boolean staticParkAndRide = false;
private boolean staticBikeParkAndRide = false;
private boolean includeOsmSubwayEntrances = false;
private int maxAreaNodes;
private StreetLimitationParameters streetLimitationParameters = new StreetLimitationParameters();

Expand Down Expand Up @@ -72,6 +73,11 @@ public OsmModuleBuilder withMaxAreaNodes(int maxAreaNodes) {
return this;
}

public OsmModuleBuilder withIncludeOsmSubwayEntrances(boolean includeOsmSubwayEntrances) {
this.includeOsmSubwayEntrances = includeOsmSubwayEntrances;
return this;
}

public OsmModuleBuilder withStreetLimitationParameters(StreetLimitationParameters parameters) {
this.streetLimitationParameters = parameters;
return this;
Expand All @@ -90,7 +96,8 @@ public OsmModule build() {
areaVisibility,
platformEntriesLinking,
staticParkAndRide,
staticBikeParkAndRide
staticBikeParkAndRide,
includeOsmSubwayEntrances
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,19 @@ class VertexGenerator {
private final HashMap<Long, Map<OsmLevel, OsmVertex>> multiLevelNodes = new HashMap<>();
private final OsmDatabase osmdb;
private final Set<String> boardingAreaRefTags;
private final Boolean includeOsmSubwayEntrances;
private final VertexFactory vertexFactory;

public VertexGenerator(OsmDatabase osmdb, Graph graph, Set<String> boardingAreaRefTags) {
public VertexGenerator(
OsmDatabase osmdb,
Graph graph,
Set<String> boardingAreaRefTags,
boolean includeOsmSubwayEntrances
) {
this.osmdb = osmdb;
this.vertexFactory = new VertexFactory(graph);
this.boardingAreaRefTags = boardingAreaRefTags;
this.includeOsmSubwayEntrances = includeOsmSubwayEntrances;
}

/**
Expand Down Expand Up @@ -95,6 +102,13 @@ IntersectionVertex getVertexForOsmNode(OsmNode node, OsmWithTags way) {
iv = bv;
}

if (includeOsmSubwayEntrances && node.isSubwayEntrance()) {
String ref = node.getTag("ref");

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

if (iv == null) {
iv =
vertexFactory.osm(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,28 @@
* Example: {@code "osm" : [ {source: "file:///path/to/otp/norway.pbf"} ] }
*
*/
public record OsmExtractParameters(URI source, OsmTagMapperSource osmTagMapper, ZoneId timeZone)
public record OsmExtractParameters(
URI source,
OsmTagMapperSource osmTagMapper,
ZoneId timeZone,
boolean includeOsmSubwayEntrances
)
implements DataSourceConfig {
public static final OsmTagMapperSource DEFAULT_OSM_TAG_MAPPER = OsmTagMapperSource.DEFAULT;

public static final ZoneId DEFAULT_TIME_ZONE = null;

public static final boolean DEFAULT_INCLUDE_OSM_SUBWAY_ENTRANCES = false;

public static final OsmExtractParameters DEFAULT = new OsmExtractParametersBuilder().build();

OsmExtractParameters(OsmExtractParametersBuilder builder) {
this(builder.getSource(), builder.getOsmTagMapper(), builder.getTimeZone());
this(
builder.getSource(),
builder.getOsmTagMapper(),
builder.getTimeZone(),
builder.includeOsmSubwayEntrances()
);
}

@Override
Expand All @@ -37,6 +49,11 @@ public ZoneId timeZone() {
return timeZone;
}

@Nullable
public boolean includeOsmSubwayEntrances() {
return includeOsmSubwayEntrances;
}

public OsmExtractParametersBuilder copyOf() {
return new OsmExtractParametersBuilder(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@ public class OsmExtractParametersBuilder {
*/
private ZoneId timeZone;

private boolean includeOsmSubwayEntrances;

public OsmExtractParametersBuilder() {
this.osmTagMapper = OsmExtractParameters.DEFAULT_OSM_TAG_MAPPER;
this.timeZone = OsmExtractParameters.DEFAULT_TIME_ZONE;
this.includeOsmSubwayEntrances = OsmExtractParameters.DEFAULT_INCLUDE_OSM_SUBWAY_ENTRANCES;
}

public OsmExtractParametersBuilder(OsmExtractParameters original) {
this.osmTagMapper = original.osmTagMapper();
this.timeZone = original.timeZone();
this.includeOsmSubwayEntrances = original.includeOsmSubwayEntrances();
}

public OsmExtractParametersBuilder withSource(URI source) {
Expand All @@ -49,6 +53,13 @@ public OsmExtractParametersBuilder withTimeZone(ZoneId timeZone) {
return this;
}

public OsmExtractParametersBuilder withIncludeOsmSubwayEntrances(
boolean includeOsmSubwayEntrances
) {
this.includeOsmSubwayEntrances = includeOsmSubwayEntrances;
return this;
}

public URI getSource() {
return source;
}
Expand All @@ -61,6 +72,10 @@ public ZoneId getTimeZone() {
return timeZone;
}

public boolean includeOsmSubwayEntrances() {
return includeOsmSubwayEntrances;
}

public OsmExtractParameters build() {
return new OsmExtractParameters(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @param platformEntriesLinking Whether platform entries should be linked
* @param staticParkAndRide Whether we should create car P+R stations from OSM data.
* @param staticBikeParkAndRide Whether we should create bike P+R stations from OSM data.
* @param includeOsmSubwayEntrances Whether we should create subway entrances from OSM data.
*/
public record OsmProcessingParameters(
Set<String> boardingAreaRefTags,
Expand All @@ -21,7 +22,8 @@ public record OsmProcessingParameters(
boolean areaVisibility,
boolean platformEntriesLinking,
boolean staticParkAndRide,
boolean staticBikeParkAndRide
boolean staticBikeParkAndRide,
boolean includeOsmSubwayEntrances
) {
public OsmProcessingParameters {
boardingAreaRefTags = Set.copyOf(Objects.requireNonNull(boardingAreaRefTags));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public enum RelativeDirection {
UTURN_RIGHT,
ENTER_STATION,
EXIT_STATION,
ENTER_OR_EXIT_STATION,
FOLLOW_SIGNS;

public static RelativeDirection calculate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.opentripplanner.framework.i18n.I18NString;
import org.opentripplanner.street.model.edge.Edge;
import org.opentripplanner.street.model.note.StreetNote;
import org.opentripplanner.transit.model.site.Entrance;
import org.opentripplanner.utils.lang.DoubleUtils;
import org.opentripplanner.utils.tostring.ToStringBuilder;

Expand Down Expand Up @@ -44,6 +45,7 @@ public final class WalkStep {
private final boolean walkingBike;

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

Expand All @@ -56,6 +58,7 @@ public final class WalkStep {
I18NString directionText,
Set<StreetNote> streetNotes,
String exit,
Entrance entrance,
ElevationProfile elevationProfile,
boolean bogusName,
boolean walkingBike,
Expand All @@ -76,6 +79,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 +134,13 @@ public String getExit() {
return exit;
}

/**
* Get information about building entrance or exit.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should say "subway stations's entrance" instead of building here. Also since there is already getExit here, maybe rename this and the highway exit rename methods so it's really clear that one is for highways, and the other is for stations.

*/
public Entrance getEntrance() {
return entrance;
}

Copy link
Member

@t2gran t2gran Oct 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to se a diagram with boxes - forget about the class design for a moment and just draw the things we want to add in the future (next 1- 2 years). Then we can discuss how to group them and map the relationship.

Return an Object is no-go, and so is Entrance extends StepEntity.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I drew some sort of a process diagram with boxes together with @HenrikSundell.

entity-diagram

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this method should probably still return StepEntity instead of Object but I think the step impl must return an Object for the entity which is then handled by StepEntityTypeResolver. It's possible that instead of doing the instanceof checks that are currently done to return correct schema types, we could cast the object to a StepEntity and then check if entrance field is non-null, or escalator field is non-null etc., but I'm not sure how much cleaner that solution is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just quickly tested and seems like it's possible to define a class that is used for an union from GraphQL (through codegen configuration). So with this current setup where the different entity types would have a shared base class, you could use that for the union. However, if they don't, then you need to return an Object from the stepImpl#entity() method.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New diagram
step-elements

/**
* Indicates whether a street changes direction at an intersection.
*/
Expand Down
Loading