Skip to content

Commit

Permalink
Use the new platform information to extract more accurate boarding ar…
Browse files Browse the repository at this point in the history
…ea centroid
  • Loading branch information
vesameskanen committed Jan 20, 2025
1 parent bf0d628 commit da53ed1
Showing 1 changed file with 42 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -134,42 +135,56 @@ private Envelope getEnvelope(TransitStopVertex ts) {

/**
* Connect a transit stop vertex into a boarding location area in the index.
* <p>
* 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<AreaEdgeList, Platform>();

// 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;
}

Expand Down

0 comments on commit da53ed1

Please sign in to comment.