Skip to content

Commit

Permalink
use a service to store platform data
Browse files Browse the repository at this point in the history
  • Loading branch information
miklcct committed Dec 19, 2024
1 parent 12e5eb2 commit d40d0b3
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -81,7 +80,6 @@ public class DebugStyleSpec {
private static final Class<Edge>[] EDGES_TO_DISPLAY = new Class[] {
StreetEdge.class,
AreaEdge.class,
LinearPlatformEdge.class,
EscalatorEdge.class,
PathwayEdge.class,
ElevatorHopEdge.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<LinearPlatform, List<LinearPlatformEdge>>();
var nearbyEdges = new HashMap<Platform, List<Edge>>();

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<LinearPlatformEdge>();
list.add(platformEdge);
nearbyLinearPlatformEdges.put(platform, list);
if (!nearbyEdges.containsKey(platform)) {
var list = new ArrayList<Edge>();
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();
Expand Down Expand Up @@ -269,7 +267,7 @@ private void linkBoardingLocationToStop(
);
}

private boolean matchesReference(StationElement<?, ?> stop, Set<String> references) {
private boolean matchesReference(StationElement<?, ?> stop, Collection<String> references) {
var stopCode = stop.getCode();
var stopId = stop.getId().getId();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -57,7 +55,6 @@ public class OsmModule implements GraphBuilderModule {
*/
private final List<OsmProvider> providers;
private final Graph graph;
// TODO: Use this to store edge stop references
private final OsmInfoGraphBuildRepository osmInfoGraphBuildRepository;
private final VehicleParkingRepository parkingRepository;

Expand Down Expand Up @@ -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());
}

Expand Down Expand Up @@ -413,8 +410,7 @@ private void buildBasicGraph() {
way,
i,
permissions,
geometry,
platform
geometry
);

params.edgeNamer().recordEdges(way, streets);
Expand All @@ -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;
Expand All @@ -439,7 +438,7 @@ private void buildBasicGraph() {
LOG.info(progress.completeMessage());
}

private Optional<LinearPlatform> getPlatform(OsmWay way) {
private Optional<Platform> getPlatform(OsmWay way) {
if (way.isBoardingLocation()) {
var nodeRefs = way.getNodeRefs();
var size = nodeRefs.size();
Expand All @@ -455,7 +454,7 @@ private Optional<LinearPlatform> 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
Expand Down Expand Up @@ -523,8 +522,7 @@ private StreetEdgePair getEdgesForStreet(
OsmWay way,
int index,
StreetTraversalPermission permissions,
LineString geometry,
Optional<LinearPlatform> platform
LineString geometry
) {
// No point in returning edges that can't be traversed by anyone.
if (permissions.allowsNothing()) {
Expand All @@ -550,8 +548,7 @@ private StreetEdgePair getEdgesForStreet(
length,
permissionsFront,
geometry,
false,
platform
false
);
}
if (permissionsBack.allowsAnything()) {
Expand All @@ -564,8 +561,7 @@ private StreetEdgePair getEdgesForStreet(
length,
permissionsBack,
backGeometry,
true,
platform
true
);
}
if (street != null && backStreet != null) {
Expand All @@ -582,19 +578,14 @@ private StreetEdge getEdgeForStreet(
double length,
StreetTraversalPermission permissions,
LineString geometry,
boolean back,
Optional<LinearPlatform> 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
.<StreetEdgeBuilder<?>>map(p -> new LinearPlatformEdgeBuilder().withPlatform(p))
.orElse(new StreetEdgeBuilder<>());

seb
StreetEdgeBuilder<?> seb = new StreetEdgeBuilder<>()
.withFromVertex(startEndpoint)
.withToVertex(endEndpoint)
.withGeometry(geometry)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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<OsmWayReferences> findReferences(Edge edge);
Optional<Platform> findPlatform(Edge edge);
}
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand All @@ -16,7 +16,10 @@
*/
public interface OsmInfoGraphBuildService {
/**
* TODO Add doc
* Find the platform the given edge is part of.
* <p>
* TODO: This service currently only stores linear platforms, but area platforms and
* node platforms should be supported as well.
*/
Optional<OsmWayReferences> findReferences(Edge edge);
Optional<Platform> findPlatform(Edge edge);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Edge, OsmWayReferences> references = new HashMap<>();
private final Map<Edge, Platform> 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<OsmWayReferences> findReferences(Edge edge) {
return Optional.ofNullable(references.get(edge));
public Optional<Platform> 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() + "}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -17,8 +17,8 @@ public DefaultOsmInfoGraphBuildService(OsmInfoGraphBuildRepository repository) {
}

@Override
public Optional<OsmWayReferences> findReferences(Edge edge) {
return repository.findReferences(edge);
public Optional<Platform> findPlatform(Edge edge) {
return repository.findPlatform(edge);
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<String> references) {
}

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit d40d0b3

Please sign in to comment.