Skip to content

Commit da53ed1

Browse files
committed
Use the new platform information to extract more accurate boarding area centroid
1 parent bf0d628 commit da53ed1

File tree

1 file changed

+42
-27
lines changed

1 file changed

+42
-27
lines changed

application/src/main/java/org/opentripplanner/graph_builder/module/OsmBoardingLocationsModule.java

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.opentripplanner.service.osminfo.model.Platform;
2525
import org.opentripplanner.street.model.StreetTraversalPermission;
2626
import org.opentripplanner.street.model.edge.AreaEdge;
27+
import org.opentripplanner.street.model.edge.AreaEdgeList;
2728
import org.opentripplanner.street.model.edge.BoardingLocationToStopLink;
2829
import org.opentripplanner.street.model.edge.Edge;
2930
import org.opentripplanner.street.model.edge.NamedArea;
@@ -134,42 +135,56 @@ private Envelope getEnvelope(TransitStopVertex ts) {
134135

135136
/**
136137
* Connect a transit stop vertex into a boarding location area in the index.
137-
* <p>
138-
* A centroid vertex is generated in the area and connected to the vertices on the platform edge.
138+
* A centroid vertex is generated in the area or its sub platform
139+
* and connected to the visibility vertices of the area
139140
*
140141
* @return if the vertex has been connected
141142
*/
142143
private boolean connectVertexToArea(TransitStopVertex ts, StreetIndex index) {
143144
RegularStop stop = ts.getStop();
144-
var nearbyAreaEdgeLists = index
145-
.getEdgesForEnvelope(getEnvelope(ts))
146-
.stream()
147-
.filter(AreaEdge.class::isInstance)
148-
.map(AreaEdge.class::cast)
149-
.map(AreaEdge::getArea)
150-
.collect(Collectors.toSet());
145+
var nearbyAreas = new HashMap<AreaEdgeList, Platform>();
151146

152-
// Iterate over all nearby areas representing transit stops in OSM, linking to them if they have a stop code or id
147+
// Find nearby areas representing transit stops in OSM, having a stop code or id
153148
// in their ref= tag that matches the GTFS stop code of this StopVertex.
154-
for (var edgeList : nearbyAreaEdgeLists) {
155-
if (matchesReference(stop, edgeList.references)) {
156-
var name = edgeList
157-
.getAreas()
158-
.stream()
159-
.findFirst()
160-
.map(NamedArea::getName)
161-
.orElse(LOCALIZED_PLATFORM_NAME);
162-
var boardingLocation = makeBoardingLocation(
163-
stop,
164-
edgeList.getGeometry().getCentroid(),
165-
edgeList.references,
166-
name
167-
);
168-
linker.addPermanentAreaVertex(boardingLocation, edgeList);
169-
linkBoardingLocationToStop(ts, stop.getCode(), boardingLocation);
170-
return true;
149+
// Find also an actual included platform which may be a part of a larger area
150+
for (var edge : index.getEdgesForEnvelope(getEnvelope(ts))) {
151+
if (edge instanceof AreaEdge aEdge) {
152+
var areaEdgeList = aEdge.getArea();
153+
if (matchesReference(stop, areaEdgeList.references)) {
154+
var opt = osmInfoGraphBuildService.findPlatform(edge);
155+
if (opt.isPresent()) {
156+
var platform = opt.get();
157+
if (!matchesReference(stop, platform.references())) {
158+
nearbyAreas.put(areaEdgeList, platform);
159+
}
160+
}
161+
// collect area also if no platform available
162+
if (nearbyAreas.get(areaEdgeList) == null) {
163+
nearbyAreas.put(areaEdgeList, null);
164+
}
165+
}
171166
}
172167
}
168+
169+
// Iterate over resulting areas and create proper linking to them
170+
for (var area : nearbyAreas.entrySet()) {
171+
var edgeList = area.getKey();
172+
var name = edgeList
173+
.getAreas()
174+
.stream()
175+
.findFirst()
176+
.map(NamedArea::getName)
177+
.orElse(LOCALIZED_PLATFORM_NAME);
178+
179+
Platform platform = nearbyAreas.get(edgeList);
180+
var centroid = platform != null
181+
? platform.geometry().getCentroid()
182+
: edgeList.getGeometry().getCentroid();
183+
var boardingLocation = makeBoardingLocation(stop, centroid, edgeList.references, name);
184+
linker.addPermanentAreaVertex(boardingLocation, edgeList);
185+
linkBoardingLocationToStop(ts, stop.getCode(), boardingLocation);
186+
return true;
187+
}
173188
return false;
174189
}
175190

0 commit comments

Comments
 (0)