From d40d0b3acceaa3bd117cb8dc10d3f4518f04dce2 Mon Sep 17 00:00:00 2001 From: Michael Tsang Date: Thu, 19 Dec 2024 10:55:34 +0000 Subject: [PATCH] use a service to store platform data --- .../apis/vectortiles/DebugStyleSpec.java | 2 - .../module/OsmBoardingLocationsModule.java | 28 +++++++------- .../graph_builder/module/osm/OsmModule.java | 37 +++++++------------ .../osminfo/OsmInfoGraphBuildRepository.java | 10 ++--- .../osminfo/OsmInfoGraphBuildService.java | 9 +++-- .../DefaultOsmInfoGraphBuildRepository.java | 16 ++++---- .../DefaultOsmInfoGraphBuildService.java | 6 +-- .../osminfo/model/OsmWayReferences.java | 26 ------------- .../service/osminfo/model/Platform.java | 8 ++++ .../street/model/edge/LinearPlatform.java | 9 ----- .../street/model/edge/LinearPlatformEdge.java | 11 ------ .../model/edge/LinearPlatformEdgeBuilder.java | 20 ---------- .../apis/vectortiles/style.json | 4 -- 13 files changed, 57 insertions(+), 129 deletions(-) delete mode 100644 application/src/main/java/org/opentripplanner/service/osminfo/model/OsmWayReferences.java create mode 100644 application/src/main/java/org/opentripplanner/service/osminfo/model/Platform.java delete mode 100644 application/src/main/java/org/opentripplanner/street/model/edge/LinearPlatform.java delete mode 100644 application/src/main/java/org/opentripplanner/street/model/edge/LinearPlatformEdge.java delete mode 100644 application/src/main/java/org/opentripplanner/street/model/edge/LinearPlatformEdgeBuilder.java diff --git a/application/src/main/java/org/opentripplanner/apis/vectortiles/DebugStyleSpec.java b/application/src/main/java/org/opentripplanner/apis/vectortiles/DebugStyleSpec.java index 9d55d36f301..7070f8b486e 100644 --- a/application/src/main/java/org/opentripplanner/apis/vectortiles/DebugStyleSpec.java +++ b/application/src/main/java/org/opentripplanner/apis/vectortiles/DebugStyleSpec.java @@ -20,7 +20,6 @@ import org.opentripplanner.street.model.edge.Edge; import org.opentripplanner.street.model.edge.ElevatorHopEdge; import org.opentripplanner.street.model.edge.EscalatorEdge; -import org.opentripplanner.street.model.edge.LinearPlatformEdge; import org.opentripplanner.street.model.edge.PathwayEdge; import org.opentripplanner.street.model.edge.StreetEdge; import org.opentripplanner.street.model.edge.StreetStationCentroidLink; @@ -81,7 +80,6 @@ public class DebugStyleSpec { private static final Class[] EDGES_TO_DISPLAY = new Class[] { StreetEdge.class, AreaEdge.class, - LinearPlatformEdge.class, EscalatorEdge.class, PathwayEdge.class, ElevatorHopEdge.class, diff --git a/application/src/main/java/org/opentripplanner/graph_builder/module/OsmBoardingLocationsModule.java b/application/src/main/java/org/opentripplanner/graph_builder/module/OsmBoardingLocationsModule.java index 0664b442f8a..7e2ba334f2f 100644 --- a/application/src/main/java/org/opentripplanner/graph_builder/module/OsmBoardingLocationsModule.java +++ b/application/src/main/java/org/opentripplanner/graph_builder/module/OsmBoardingLocationsModule.java @@ -2,9 +2,9 @@ import jakarta.inject.Inject; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.List; -import java.util.Set; import java.util.stream.Collectors; import javax.annotation.Nullable; import org.locationtech.jts.geom.Coordinate; @@ -18,12 +18,11 @@ import org.opentripplanner.routing.linking.LinkingDirection; import org.opentripplanner.routing.linking.VertexLinker; import org.opentripplanner.service.osminfo.OsmInfoGraphBuildService; +import org.opentripplanner.service.osminfo.model.Platform; import org.opentripplanner.street.model.StreetTraversalPermission; import org.opentripplanner.street.model.edge.AreaEdge; import org.opentripplanner.street.model.edge.BoardingLocationToStopLink; import org.opentripplanner.street.model.edge.Edge; -import org.opentripplanner.street.model.edge.LinearPlatform; -import org.opentripplanner.street.model.edge.LinearPlatformEdge; import org.opentripplanner.street.model.edge.NamedArea; import org.opentripplanner.street.model.edge.StreetEdge; import org.opentripplanner.street.model.edge.StreetEdgeBuilder; @@ -149,25 +148,24 @@ private boolean connectVertexToStop(TransitStopVertex ts, StreetIndex index) { // if the boarding location is a non-area way we are finding the vertex representing the // center of the way, splitting if needed - var nearbyLinearPlatformEdges = new HashMap>(); + var nearbyEdges = new HashMap>(); for (var edge : index.getEdgesForEnvelope(envelope)) { - if (edge instanceof LinearPlatformEdge platformEdge) { - var platform = platformEdge.platform; + osmInfoGraphBuildService.findPlatform(edge).ifPresent(platform -> { if (matchesReference(stop, platform.references())) { - if (!nearbyLinearPlatformEdges.containsKey(platform)) { - var list = new ArrayList(); - list.add(platformEdge); - nearbyLinearPlatformEdges.put(platform, list); + if (!nearbyEdges.containsKey(platform)) { + var list = new ArrayList(); + list.add(edge); + nearbyEdges.put(platform, list); } else { - nearbyLinearPlatformEdges.get(platform).add(platformEdge); + nearbyEdges.get(platform).add(edge); } } - } + }); } - for (var platformEdgeList : nearbyLinearPlatformEdges.entrySet()) { - LinearPlatform platform = platformEdgeList.getKey(); + for (var platformEdgeList : nearbyEdges.entrySet()) { + Platform platform = platformEdgeList.getKey(); var name = platform.name(); var label = "platform-centroid/%s".formatted(stop.getId().toString()); var centroid = platform.geometry().getCentroid(); @@ -269,7 +267,7 @@ private void linkBoardingLocationToStop( ); } - private boolean matchesReference(StationElement stop, Set references) { + private boolean matchesReference(StationElement stop, Collection references) { var stopCode = stop.getCode(); var stopId = stop.getId().getId(); diff --git a/application/src/main/java/org/opentripplanner/graph_builder/module/osm/OsmModule.java b/application/src/main/java/org/opentripplanner/graph_builder/module/osm/OsmModule.java index d25d2c83d6c..673611f367f 100644 --- a/application/src/main/java/org/opentripplanner/graph_builder/module/osm/OsmModule.java +++ b/application/src/main/java/org/opentripplanner/graph_builder/module/osm/OsmModule.java @@ -27,13 +27,11 @@ import org.opentripplanner.routing.graph.Graph; import org.opentripplanner.routing.util.ElevationUtils; import org.opentripplanner.service.osminfo.OsmInfoGraphBuildRepository; -import org.opentripplanner.service.osminfo.model.OsmWayReferences; +import org.opentripplanner.service.osminfo.model.Platform; import org.opentripplanner.service.vehicleparking.VehicleParkingRepository; import org.opentripplanner.service.vehicleparking.model.VehicleParking; import org.opentripplanner.street.model.StreetLimitationParameters; import org.opentripplanner.street.model.StreetTraversalPermission; -import org.opentripplanner.street.model.edge.LinearPlatform; -import org.opentripplanner.street.model.edge.LinearPlatformEdgeBuilder; import org.opentripplanner.street.model.edge.StreetEdge; import org.opentripplanner.street.model.edge.StreetEdgeBuilder; import org.opentripplanner.street.model.vertex.BarrierVertex; @@ -57,7 +55,6 @@ public class OsmModule implements GraphBuilderModule { */ private final List providers; private final Graph graph; - // TODO: Use this to store edge stop references private final OsmInfoGraphBuildRepository osmInfoGraphBuildRepository; private final VehicleParkingRepository parkingRepository; @@ -355,7 +352,7 @@ private void buildBasicGraph() { * We split segments at intersections, self-intersections, nodes with ele tags, and transit stops; * the only processing we do on other nodes is to accumulate their geometry */ - if (segmentCoordinates.size() == 0) { + if (segmentCoordinates.isEmpty()) { segmentCoordinates.add(osmStartNode.getCoordinate()); } @@ -413,8 +410,7 @@ private void buildBasicGraph() { way, i, permissions, - geometry, - platform + geometry ); params.edgeNamer().recordEdges(way, streets); @@ -423,7 +419,10 @@ private void buildBasicGraph() { StreetEdge backStreet = streets.back(); normalizer.applyWayProperties(street, backStreet, wayData, way); - osmInfoGraphBuildRepository.addReferences(street, new OsmWayReferences(List.of(street.toString()))); + platform.ifPresent(plat -> { + osmInfoGraphBuildRepository.addPlatform(street, plat); + osmInfoGraphBuildRepository.addPlatform(backStreet, plat); + }); applyEdgesToTurnRestrictions(way, startNode, endNode, street, backStreet); startNode = endNode; @@ -439,7 +438,7 @@ private void buildBasicGraph() { LOG.info(progress.completeMessage()); } - private Optional getPlatform(OsmWay way) { + private Optional getPlatform(OsmWay way) { if (way.isBoardingLocation()) { var nodeRefs = way.getNodeRefs(); var size = nodeRefs.size(); @@ -455,7 +454,7 @@ private Optional getPlatform(OsmWay way) { var references = way.getMultiTagValues(params.boardingAreaRefTags()); return Optional.of( - new LinearPlatform( + new Platform( params.edgeNamer().getNameForWay(way, "platform " + way.getId()), geometry, references @@ -523,8 +522,7 @@ private StreetEdgePair getEdgesForStreet( OsmWay way, int index, StreetTraversalPermission permissions, - LineString geometry, - Optional platform + LineString geometry ) { // No point in returning edges that can't be traversed by anyone. if (permissions.allowsNothing()) { @@ -550,8 +548,7 @@ private StreetEdgePair getEdgesForStreet( length, permissionsFront, geometry, - false, - platform + false ); } if (permissionsBack.allowsAnything()) { @@ -564,8 +561,7 @@ private StreetEdgePair getEdgesForStreet( length, permissionsBack, backGeometry, - true, - platform + true ); } if (street != null && backStreet != null) { @@ -582,19 +578,14 @@ private StreetEdge getEdgeForStreet( double length, StreetTraversalPermission permissions, LineString geometry, - boolean back, - Optional platform + boolean back ) { String label = "way " + way.getId() + " from " + index; label = label.intern(); I18NString name = params.edgeNamer().getNameForWay(way, label); float carSpeed = way.getOsmProvider().getOsmTagMapper().getCarSpeedForWay(way, back); - var seb = platform - .>map(p -> new LinearPlatformEdgeBuilder().withPlatform(p)) - .orElse(new StreetEdgeBuilder<>()); - - seb + StreetEdgeBuilder seb = new StreetEdgeBuilder<>() .withFromVertex(startEndpoint) .withToVertex(endEndpoint) .withGeometry(geometry) diff --git a/application/src/main/java/org/opentripplanner/service/osminfo/OsmInfoGraphBuildRepository.java b/application/src/main/java/org/opentripplanner/service/osminfo/OsmInfoGraphBuildRepository.java index c8a2b908893..e30e0dd19a7 100644 --- a/application/src/main/java/org/opentripplanner/service/osminfo/OsmInfoGraphBuildRepository.java +++ b/application/src/main/java/org/opentripplanner/service/osminfo/OsmInfoGraphBuildRepository.java @@ -2,7 +2,7 @@ import java.io.Serializable; import java.util.Optional; -import org.opentripplanner.service.osminfo.model.OsmWayReferences; +import org.opentripplanner.service.osminfo.model.Platform; import org.opentripplanner.street.model.edge.Edge; /** @@ -12,12 +12,12 @@ */ public interface OsmInfoGraphBuildRepository extends Serializable { /** - * TODO Add doc + * Associate the edge with a platform */ - void addReferences(Edge edge, OsmWayReferences info); + void addPlatform(Edge edge, Platform platform); /** - * TODO Add doc + * Find the platform the edge belongs to */ - Optional findReferences(Edge edge); + Optional findPlatform(Edge edge); } diff --git a/application/src/main/java/org/opentripplanner/service/osminfo/OsmInfoGraphBuildService.java b/application/src/main/java/org/opentripplanner/service/osminfo/OsmInfoGraphBuildService.java index 784867ada30..6a50c3c92be 100644 --- a/application/src/main/java/org/opentripplanner/service/osminfo/OsmInfoGraphBuildService.java +++ b/application/src/main/java/org/opentripplanner/service/osminfo/OsmInfoGraphBuildService.java @@ -1,7 +1,7 @@ package org.opentripplanner.service.osminfo; import java.util.Optional; -import org.opentripplanner.service.osminfo.model.OsmWayReferences; +import org.opentripplanner.service.osminfo.model.Platform; import org.opentripplanner.street.model.edge.Edge; /** @@ -16,7 +16,10 @@ */ public interface OsmInfoGraphBuildService { /** - * TODO Add doc + * Find the platform the given edge is part of. + *

+ * TODO: This service currently only stores linear platforms, but area platforms and + * node platforms should be supported as well. */ - Optional findReferences(Edge edge); + Optional findPlatform(Edge edge); } diff --git a/application/src/main/java/org/opentripplanner/service/osminfo/internal/DefaultOsmInfoGraphBuildRepository.java b/application/src/main/java/org/opentripplanner/service/osminfo/internal/DefaultOsmInfoGraphBuildRepository.java index 4ba575dc8b0..6505fdd67a4 100644 --- a/application/src/main/java/org/opentripplanner/service/osminfo/internal/DefaultOsmInfoGraphBuildRepository.java +++ b/application/src/main/java/org/opentripplanner/service/osminfo/internal/DefaultOsmInfoGraphBuildRepository.java @@ -7,31 +7,31 @@ import java.util.Objects; import java.util.Optional; import org.opentripplanner.service.osminfo.OsmInfoGraphBuildRepository; -import org.opentripplanner.service.osminfo.model.OsmWayReferences; +import org.opentripplanner.service.osminfo.model.Platform; import org.opentripplanner.street.model.edge.Edge; public class DefaultOsmInfoGraphBuildRepository implements OsmInfoGraphBuildRepository, Serializable { - private final Map references = new HashMap<>(); + private final Map platforms = new HashMap<>(); @Inject public DefaultOsmInfoGraphBuildRepository() {} @Override - public void addReferences(Edge edge, OsmWayReferences info) { + public void addPlatform(Edge edge, Platform platform) { Objects.requireNonNull(edge); - Objects.requireNonNull(info); - this.references.put(edge, info); + Objects.requireNonNull(platform); + this.platforms.put(edge, platform); } @Override - public Optional findReferences(Edge edge) { - return Optional.ofNullable(references.get(edge)); + public Optional findPlatform(Edge edge) { + return Optional.ofNullable(platforms.get(edge)); } @Override public String toString() { - return "DefaultOsmInfoGraphBuildRepository{references size = " + references.size() + "}"; + return "DefaultOsmInfoGraphBuildRepository{platforms size = " + platforms.size() + "}"; } } diff --git a/application/src/main/java/org/opentripplanner/service/osminfo/internal/DefaultOsmInfoGraphBuildService.java b/application/src/main/java/org/opentripplanner/service/osminfo/internal/DefaultOsmInfoGraphBuildService.java index 29271e17679..42eb5bf364f 100644 --- a/application/src/main/java/org/opentripplanner/service/osminfo/internal/DefaultOsmInfoGraphBuildService.java +++ b/application/src/main/java/org/opentripplanner/service/osminfo/internal/DefaultOsmInfoGraphBuildService.java @@ -4,7 +4,7 @@ import java.util.Optional; import org.opentripplanner.service.osminfo.OsmInfoGraphBuildRepository; import org.opentripplanner.service.osminfo.OsmInfoGraphBuildService; -import org.opentripplanner.service.osminfo.model.OsmWayReferences; +import org.opentripplanner.service.osminfo.model.Platform; import org.opentripplanner.street.model.edge.Edge; public class DefaultOsmInfoGraphBuildService implements OsmInfoGraphBuildService { @@ -17,8 +17,8 @@ public DefaultOsmInfoGraphBuildService(OsmInfoGraphBuildRepository repository) { } @Override - public Optional findReferences(Edge edge) { - return repository.findReferences(edge); + public Optional findPlatform(Edge edge) { + return repository.findPlatform(edge); } @Override diff --git a/application/src/main/java/org/opentripplanner/service/osminfo/model/OsmWayReferences.java b/application/src/main/java/org/opentripplanner/service/osminfo/model/OsmWayReferences.java deleted file mode 100644 index 6208758f153..00000000000 --- a/application/src/main/java/org/opentripplanner/service/osminfo/model/OsmWayReferences.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.opentripplanner.service.osminfo.model; - -import java.io.Serializable; -import java.util.Collection; -import java.util.List; - -/** - * TODO : Add java doc - */ -public class OsmWayReferences implements Serializable { - - private final List references; - - public OsmWayReferences(Collection references) { - this.references = references.stream().sorted().distinct().toList(); - } - - /** - * TODO : Add java doc - * - * returns a sorted distinct list of references - */ - public List references() { - return references; - } -} \ No newline at end of file diff --git a/application/src/main/java/org/opentripplanner/service/osminfo/model/Platform.java b/application/src/main/java/org/opentripplanner/service/osminfo/model/Platform.java new file mode 100644 index 00000000000..81ff388f69e --- /dev/null +++ b/application/src/main/java/org/opentripplanner/service/osminfo/model/Platform.java @@ -0,0 +1,8 @@ +package org.opentripplanner.service.osminfo.model; + +import java.util.Set; +import org.locationtech.jts.geom.LineString; +import org.opentripplanner.framework.i18n.I18NString; + +public record Platform(I18NString name, LineString geometry, Set references) { +} \ No newline at end of file diff --git a/application/src/main/java/org/opentripplanner/street/model/edge/LinearPlatform.java b/application/src/main/java/org/opentripplanner/street/model/edge/LinearPlatform.java deleted file mode 100644 index 688d4418530..00000000000 --- a/application/src/main/java/org/opentripplanner/street/model/edge/LinearPlatform.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.opentripplanner.street.model.edge; - -import java.io.Serializable; -import java.util.Set; -import org.locationtech.jts.geom.LineString; -import org.opentripplanner.framework.i18n.I18NString; - -public record LinearPlatform(I18NString name, LineString geometry, Set references) - implements Serializable {} diff --git a/application/src/main/java/org/opentripplanner/street/model/edge/LinearPlatformEdge.java b/application/src/main/java/org/opentripplanner/street/model/edge/LinearPlatformEdge.java deleted file mode 100644 index 849266166a2..00000000000 --- a/application/src/main/java/org/opentripplanner/street/model/edge/LinearPlatformEdge.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.opentripplanner.street.model.edge; - -public class LinearPlatformEdge extends StreetEdge { - - public final LinearPlatform platform; - - protected LinearPlatformEdge(LinearPlatformEdgeBuilder builder) { - super(builder); - platform = builder.platform(); - } -} diff --git a/application/src/main/java/org/opentripplanner/street/model/edge/LinearPlatformEdgeBuilder.java b/application/src/main/java/org/opentripplanner/street/model/edge/LinearPlatformEdgeBuilder.java deleted file mode 100644 index 7057f9a7e42..00000000000 --- a/application/src/main/java/org/opentripplanner/street/model/edge/LinearPlatformEdgeBuilder.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.opentripplanner.street.model.edge; - -public class LinearPlatformEdgeBuilder extends StreetEdgeBuilder { - - private LinearPlatform platform; - - @Override - public LinearPlatformEdge buildAndConnect() { - return Edge.connectToGraph(new LinearPlatformEdge(this)); - } - - public LinearPlatform platform() { - return platform; - } - - public LinearPlatformEdgeBuilder withPlatform(LinearPlatform platform) { - this.platform = platform; - return this; - } -} diff --git a/application/src/test/resources/org/opentripplanner/apis/vectortiles/style.json b/application/src/test/resources/org/opentripplanner/apis/vectortiles/style.json index e513a44fcd9..66858390ab5 100644 --- a/application/src/test/resources/org/opentripplanner/apis/vectortiles/style.json +++ b/application/src/test/resources/org/opentripplanner/apis/vectortiles/style.json @@ -244,7 +244,6 @@ "class", "StreetEdge", "AreaEdge", - "LinearPlatformEdge", "EscalatorEdge", "PathwayEdge", "ElevatorHopEdge", @@ -421,7 +420,6 @@ "class", "StreetEdge", "AreaEdge", - "LinearPlatformEdge", "EscalatorEdge", "PathwayEdge", "ElevatorHopEdge", @@ -462,7 +460,6 @@ "class", "StreetEdge", "AreaEdge", - "LinearPlatformEdge", "EscalatorEdge", "PathwayEdge", "ElevatorHopEdge", @@ -495,7 +492,6 @@ "class", "StreetEdge", "AreaEdge", - "LinearPlatformEdge", "EscalatorEdge", "PathwayEdge", "ElevatorHopEdge",