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 9 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 @@ -58,6 +58,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.StepEntityTypeResolver;
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 @@ -124,6 +125,7 @@ protected static GraphQLSchema buildSchema() {
.type("Node", type -> type.typeResolver(new NodeTypeResolver()))
.type("PlaceInterface", type -> type.typeResolver(new PlaceInterfaceTypeResolver()))
.type("StopPosition", type -> type.typeResolver(new StopPosition() {}))
.type("StepEntity", type -> type.typeResolver(new StepEntityTypeResolver()))
.type("FareProduct", type -> type.typeResolver(new FareProductTypeResolver()))
.type("AlertEntity", type -> type.typeResolver(new AlertEntityTypeResolver()))
.type(typeWiring.build(AgencyImpl.class))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.opentripplanner.apis.gtfs.datafetchers;

import graphql.TypeResolutionEnvironment;
import graphql.schema.GraphQLObjectType;
import graphql.schema.GraphQLSchema;
import graphql.schema.TypeResolver;
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.UnknownModel;
import org.opentripplanner.model.plan.Entrance;
import org.opentripplanner.transit.model.network.Route;
import org.opentripplanner.transit.model.network.TripPattern;
import org.opentripplanner.transit.model.organization.Agency;
import org.opentripplanner.transit.model.site.RegularStop;
import org.opentripplanner.transit.model.timetable.Trip;
HenrikSundell marked this conversation as resolved.
Show resolved Hide resolved

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

@Override
public DataFetcher<Object> entity() {
return environment -> getSource(environment).getEntity();
}

@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 @@ -25,8 +27,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 @@ -49,6 +55,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 @@ -59,6 +67,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 @@ -357,6 +366,15 @@ public interface GraphQLEmissions {
public DataFetcher<org.opentripplanner.framework.model.Grams> co2();
}

/** Station entrance/exit */
public interface GraphQLEntrance {
public DataFetcher<String> code();

public DataFetcher<String> gtfsId();

public DataFetcher<String> name();
}

/** 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 +991,9 @@ public interface GraphQLRoutingError {
public DataFetcher<GraphQLInputField> inputField();
}

/** Entity to a step */
public interface GraphQLStepEntity 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 @@ -1424,6 +1445,8 @@ public interface GraphQLStep {

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

public DataFetcher<Object> entity();

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 @@ -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,15 @@ IntersectionVertex getVertexForOsmNode(OsmNode node, OsmWithTags way) {
iv = bv;
}

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

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.getIncludeOsmSubwayEntrances()
);
}

@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 getIncludeOsmSubwayEntrances() {
Copy link
Member

Choose a reason for hiding this comment

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

This could probably be just named 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
@@ -0,0 +1,18 @@
package org.opentripplanner.model.plan;

public final class Entrance extends StepEntity {

private final String code;
private final String gtfsId;
private final String name;

public Entrance(String code, String gtfsId, String name) {
this.code = code;
this.gtfsId = gtfsId;
this.name = name;
}

public static Entrance withCode(String code) {
return new Entrance(code, null, null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.opentripplanner.model.plan;

public abstract class StepEntity {}
Copy link
Member

Choose a reason for hiding this comment

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

We could discuss in a dev meeting if this is the best approach.

Loading