From da53ed1eb236fb226fe74cf64163ef6110a18723 Mon Sep 17 00:00:00 2001 From: Vesa Meskanen Date: Mon, 20 Jan 2025 15:15:13 +0200 Subject: [PATCH] Use the new platform information to extract more accurate boarding area centroid --- .../module/OsmBoardingLocationsModule.java | 69 +++++++++++-------- 1 file changed, 42 insertions(+), 27 deletions(-) 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 e588e55630c..35e0a297c94 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 @@ -24,6 +24,7 @@ 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.AreaEdgeList; import org.opentripplanner.street.model.edge.BoardingLocationToStopLink; import org.opentripplanner.street.model.edge.Edge; import org.opentripplanner.street.model.edge.NamedArea; @@ -134,42 +135,56 @@ private Envelope getEnvelope(TransitStopVertex ts) { /** * Connect a transit stop vertex into a boarding location area in the index. - *

- * A centroid vertex is generated in the area and connected to the vertices on the platform edge. + * A centroid vertex is generated in the area or its sub platform + * and connected to the visibility vertices of the area * * @return if the vertex has been connected */ private boolean connectVertexToArea(TransitStopVertex ts, StreetIndex index) { RegularStop stop = ts.getStop(); - var nearbyAreaEdgeLists = index - .getEdgesForEnvelope(getEnvelope(ts)) - .stream() - .filter(AreaEdge.class::isInstance) - .map(AreaEdge.class::cast) - .map(AreaEdge::getArea) - .collect(Collectors.toSet()); + var nearbyAreas = new HashMap(); - // Iterate over all nearby areas representing transit stops in OSM, linking to them if they have a stop code or id + // Find nearby areas representing transit stops in OSM, having a stop code or id // in their ref= tag that matches the GTFS stop code of this StopVertex. - for (var edgeList : nearbyAreaEdgeLists) { - if (matchesReference(stop, edgeList.references)) { - var name = edgeList - .getAreas() - .stream() - .findFirst() - .map(NamedArea::getName) - .orElse(LOCALIZED_PLATFORM_NAME); - var boardingLocation = makeBoardingLocation( - stop, - edgeList.getGeometry().getCentroid(), - edgeList.references, - name - ); - linker.addPermanentAreaVertex(boardingLocation, edgeList); - linkBoardingLocationToStop(ts, stop.getCode(), boardingLocation); - return true; + // Find also an actual included platform which may be a part of a larger area + for (var edge : index.getEdgesForEnvelope(getEnvelope(ts))) { + if (edge instanceof AreaEdge aEdge) { + var areaEdgeList = aEdge.getArea(); + if (matchesReference(stop, areaEdgeList.references)) { + var opt = osmInfoGraphBuildService.findPlatform(edge); + if (opt.isPresent()) { + var platform = opt.get(); + if (!matchesReference(stop, platform.references())) { + nearbyAreas.put(areaEdgeList, platform); + } + } + // collect area also if no platform available + if (nearbyAreas.get(areaEdgeList) == null) { + nearbyAreas.put(areaEdgeList, null); + } + } } } + + // Iterate over resulting areas and create proper linking to them + for (var area : nearbyAreas.entrySet()) { + var edgeList = area.getKey(); + var name = edgeList + .getAreas() + .stream() + .findFirst() + .map(NamedArea::getName) + .orElse(LOCALIZED_PLATFORM_NAME); + + Platform platform = nearbyAreas.get(edgeList); + var centroid = platform != null + ? platform.geometry().getCentroid() + : edgeList.getGeometry().getCentroid(); + var boardingLocation = makeBoardingLocation(stop, centroid, edgeList.references, name); + linker.addPermanentAreaVertex(boardingLocation, edgeList); + linkBoardingLocationToStop(ts, stop.getCode(), boardingLocation); + return true; + } return false; }