Skip to content

Commit

Permalink
Revert using of OsmVertex
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Jul 17, 2023
1 parent 5fbcca6 commit 28c7ded
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.opentripplanner.routing.util.ElevationUtils;
import org.opentripplanner.routing.vehicle_parking.VehicleParking;
import org.opentripplanner.street.model.StreetTraversalPermission;
import org.opentripplanner.street.model.edge.OsmEdge;
import org.opentripplanner.street.model.edge.StairsEdge;
import org.opentripplanner.street.model.edge.StreetEdge;
import org.opentripplanner.street.model.vertex.IntersectionVertex;
Expand Down Expand Up @@ -107,7 +106,7 @@ public Map<Vertex, Double> elevationDataOutput() {
return elevationData;
}

private record StreetEdgePair(OsmEdge main, OsmEdge back) {}
private record StreetEdgePair(StreetEdge main, StreetEdge back) {}

private void build() {
var parkingProcessor = new ParkingProcessor(
Expand Down Expand Up @@ -374,9 +373,12 @@ private void buildBasicGraph() {
elevationData.put(endEndpoint, elevation);
}
}
var length = getGeometryLengthMeters(geometry);
if (way.isEscalator()) {
var length = getGeometryLengthMeters(geometry);
escalatorProcessor.buildEscalatorEdge(way, length);
} else if (way.isSteps()) {
new StairsEdge(startEndpoint, endEndpoint, geometry, length);
new StairsEdge(endEndpoint, startEndpoint, geometry.reverse(), length);
} else {
StreetEdgePair streets = getEdgesForStreet(
startEndpoint,
Expand Down Expand Up @@ -418,8 +420,8 @@ private void applyEdgesToTurnRestrictions(
OSMWay way,
long startNode,
long endNode,
OsmEdge street,
OsmEdge backStreet
StreetEdge street,
StreetEdge backStreet
) {
/* Check if there are turn restrictions starting on this segment */
Collection<TurnRestrictionTag> restrictionTags = osmdb.getFromWayTurnRestrictions(way.getId());
Expand Down Expand Up @@ -465,7 +467,7 @@ private StreetEdgePair getEdgesForStreet(
}

LineString backGeometry = geometry.reverse();
OsmEdge street = null, backStreet = null;
StreetEdge street = null, backStreet = null;
double length = getGeometryLengthMeters(geometry);

var permissionPair = OsmFilter.getPermissions(permissions, way);
Expand Down Expand Up @@ -505,7 +507,7 @@ private StreetEdgePair getEdgesForStreet(
return new StreetEdgePair(street, backStreet);
}

private OsmEdge getEdgeForStreet(
private StreetEdge getEdgeForStreet(
IntersectionVertex from,
IntersectionVertex to,
OSMWay way,
Expand All @@ -519,40 +521,36 @@ private OsmEdge getEdgeForStreet(
label = label.intern();

I18NString name = params.edgeNamer().getNameForWay(way, label);
if (way.isSteps()) {
return new StairsEdge(from, to, geometry, name, length);
} else {
float carSpeed = way.getOsmProvider().getOsmTagMapper().getCarSpeedForWay(way, back);

StreetEdge street = StreetEdge.createStreetEdge(
from,
to,
geometry,
name,
length,
permissions,
back
);
street.setCarSpeed(carSpeed);
street.setLink(OsmFilter.isLink(way));
float carSpeed = way.getOsmProvider().getOsmTagMapper().getCarSpeedForWay(way, back);

StreetEdge street = StreetEdge.createStreetEdge(
from,
to,
geometry,
name,
length,
permissions,
back
);
street.setCarSpeed(carSpeed);
street.setLink(OsmFilter.isLink(way));

if (!way.hasTag("name") && !way.hasTag("ref")) {
street.setHasBogusName(true);
}
if (!way.hasTag("name") && !way.hasTag("ref")) {
street.setHasBogusName(true);
}

street.setRoundabout(way.isRoundabout());
street.setWheelchairAccessible(way.isWheelchairAccessible());
street.setRoundabout(way.isRoundabout());
street.setWheelchairAccessible(way.isWheelchairAccessible());

street.setSlopeOverride(way.getOsmProvider().getWayPropertySet().getSlopeOverride(way));
street.setSlopeOverride(way.getOsmProvider().getWayPropertySet().getSlopeOverride(way));

// < 0.04: account for
if (carSpeed < 0.04) {
issueStore.add(new StreetCarSpeedZero(way));
}
// < 0.04: account for
if (carSpeed < 0.04) {
issueStore.add(new StreetCarSpeedZero(way));
}

params.edgeNamer().recordEdge(way, street);
params.edgeNamer().recordEdge(way, street);

return street;
}
return street;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class TurnRestrictionTag {
TurnRestrictionType type;
Direction direction;
RepeatingTimePeriod time;
public List<OsmEdge> possibleFrom = new ArrayList<>();
public List<OsmEdge> possibleTo = new ArrayList<>();
public List<StreetEdge> possibleFrom = new ArrayList<>();
public List<StreetEdge> possibleTo = new ArrayList<>();
public TraverseModeSet modes;

TurnRestrictionTag(long via, TurnRestrictionType type, Direction direction, long relationOSMID) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package org.opentripplanner.street.model;

import java.io.Serializable;
import org.opentripplanner.street.model.edge.OsmEdge;
import org.opentripplanner.street.model.edge.StreetEdge;
import org.opentripplanner.street.search.TraverseModeSet;

public class TurnRestriction implements Serializable {

public final TurnRestrictionType type;
public final OsmEdge from;
public final OsmEdge to;
public final StreetEdge from;
public final StreetEdge to;
public final RepeatingTimePeriod time;
public final TraverseModeSet modes;

public TurnRestriction(
OsmEdge from,
OsmEdge to,
StreetEdge from,
StreetEdge to,
TurnRestrictionType type,
TraverseModeSet modes,
RepeatingTimePeriod time
Expand Down
83 changes: 13 additions & 70 deletions src/main/java/org/opentripplanner/street/model/edge/StairsEdge.java
Original file line number Diff line number Diff line change
@@ -1,47 +1,32 @@
package org.opentripplanner.street.model.edge;

import javax.annotation.Nonnull;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.LineString;
import org.opentripplanner.framework.geometry.CompactLineStringUtils;
import org.opentripplanner.framework.i18n.I18NString;
import org.opentripplanner.framework.i18n.LocalizedString;
import org.opentripplanner.routing.api.request.preference.RoutingPreferences;
import org.opentripplanner.street.model.StreetTraversalPermission;
import org.opentripplanner.street.model.TurnRestriction;
import org.opentripplanner.street.model.vertex.StreetVertex;
import org.opentripplanner.street.search.state.State;

/**
* Represents a flight of stairs that are derived from OSM data.
*/
public class StairsEdge extends OsmEdge {
public class StairsEdge extends Edge {

// stairs are only allowed for walking and cycling/scootering
private static final StreetTraversalPermission DEFAULT_PERMISSIONS =
StreetTraversalPermission.PEDESTRIAN_AND_BICYCLE;
private static final LocalizedString NAME = new LocalizedString("name.stairs");

private final I18NString name;
private final byte[] compactGeometry;
private final LineString compactGeometry;
private final double distance;
private float walkSafetyFactor = 1f;

public StairsEdge(
StreetVertex from,
StreetVertex to,
LineString geometry,
I18NString name,
double distance
) {
super(from, to, geometry);
this.name = name;
this.compactGeometry =
CompactLineStringUtils.compactLineString(
from.getX(),
from.getY(),
to.getX(),
to.getY(),
geometry,
false
);

public StairsEdge(StreetVertex from, StreetVertex to, LineString geometry, double distance) {
super(from, to);
this.compactGeometry =geometry;
this.distance = distance;
}

Expand All @@ -64,9 +49,9 @@ public State[] traverse(State s0) {

double time = distance / speed;
double weight =
getEffectiveWalkSafetyDistance() *
getDistanceMeters() *
prefs.walk().safetyFactor() +
getEffectiveWalkSafetyDistance() *
getDistanceMeters() *
(1 - prefs.walk().safetyFactor());
weight /= speed;

Expand All @@ -81,57 +66,19 @@ public State[] traverse(State s0) {

@Override
public I18NString getName() {
return this.name;
return NAME;
}

@Override
public LineString getGeometry() {
return CompactLineStringUtils.uncompactLineString(
fromv.getX(),
fromv.getY(),
tov.getX(),
tov.getY(),
compactGeometry,
false
);
return compactGeometry;
}

@Override
public double getDistanceMeters() {
return distance;
}

@Override
public void setBicycleSafetyFactor(float bicycleSafety) {
// we ignore the bicycle safety factor, stairs are inherently unsafe and therefore have a separate
// reluctance
}

@Override
public void setWalkSafetyFactor(float walkSafety) {
this.walkSafetyFactor = walkSafety;
}

@Override
public void setMotorVehicleNoThruTraffic(boolean motorVehicleNoThrough) {
// we are ignoring no-through on stairs
}

@Override
public void setBicycleNoThruTraffic(boolean bicycleNoThrough) {
// we are ignoring no-through on stairs
}

@Override
public void setWalkNoThruTraffic(boolean walkNoThrough) {
// we are ignoring no-through on stairs
}

@Override
public void addTurnRestriction(TurnRestriction restriction) {
// we are ignoring turn restrictions on stairs
}

private static double reluctance(State s0, RoutingPreferences prefs) {
if (s0.getRequest().wheelchair()) {
return StreetEdgeReluctanceCalculator.computeWheelchairReluctance(prefs, 0, true, true);
Expand All @@ -144,8 +91,4 @@ private boolean blockedByBarriers() {
var permission = BarrierCalculator.reducePermissions(DEFAULT_PERMISSIONS, fromv, tov);
return permission.allowsNothing();
}

private double getEffectiveWalkSafetyDistance() {
return walkSafetyFactor * getDistanceMeters();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1070,8 +1070,8 @@ private static void copyRestrictionsToSplitEdges(StreetEdge edge, SplitStreetEdg
}

private static void applyRestrictionsToNewEdge(
OsmEdge fromEdge,
OsmEdge toEdge,
StreetEdge fromEdge,
StreetEdge toEdge,
TurnRestriction restriction
) {
TurnRestriction splitTurnRestriction = new TurnRestriction(
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/WayProperties.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ name.parking_aisle=parking aisle
name.byway=byway
name.track=track
name.sidewalk=sidewalk
name.stairs=stairs

name.steps=steps

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/WayProperties_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ name.parking_aisle=Parkplatz
name.byway=Nebenstra\u00dfe
name.track=Fahrweg
name.sidewalk=B\u00fcrgersteig
name.stairs=Treppe

name.steps=Stufen

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.junit.jupiter.params.provider.Arguments;
import org.opentripplanner.framework.geometry.GeometryUtils;
import org.opentripplanner.framework.i18n.I18NString;
import org.opentripplanner.framework.i18n.NonLocalizedString;
import org.opentripplanner.routing.api.request.StreetMode;
import org.opentripplanner.routing.api.request.preference.WheelchairPreferences;
import org.opentripplanner.street.model.StreetTraversalPermission;
Expand All @@ -29,7 +28,6 @@ class StairsEdgeTest {
V1,
V2,
GeometryUtils.makeLineString(V1.getCoordinate(), V2.getCoordinate()),
new NonLocalizedString("stairs"),
LENGTH
);

Expand Down Expand Up @@ -163,7 +161,6 @@ void barriers(StreetTraversalPermission permission, boolean shouldBlockTraversal
V1,
barrier,
GeometryUtils.makeLineString(V1.getCoordinate(), V2.getCoordinate()),
new NonLocalizedString("stairs"),
LENGTH
);

Expand All @@ -174,7 +171,7 @@ void barriers(StreetTraversalPermission permission, boolean shouldBlockTraversal
assertEquals(shouldBlockTraversal, State.isEmpty(result));
}

private State traverse(OsmEdge edge, StreetSearchRequest request) {
private State traverse(Edge edge, StreetSearchRequest request) {
var state = new State(V1, request);
assertEquals(0, state.weight);
return edge.traverse(state)[0];
Expand Down

0 comments on commit 28c7ded

Please sign in to comment.