Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detailed Road Classification #507

Merged
merged 10 commits into from
Dec 11, 2020
Merged

Detailed Road Classification #507

merged 10 commits into from
Dec 11, 2020

Conversation

Udumft
Copy link
Contributor

@Udumft Udumft commented Dec 7, 2020

Adds support for Mapbox Streets V8 road classes.

@Udumft Udumft added improvement Improvement for an existing feature. platform parity labels Dec 7, 2020
@Udumft Udumft added this to the v1.2.0 milestone Dec 7, 2020
@Udumft Udumft self-assigned this Dec 7, 2020
@Udumft Udumft marked this pull request as ready for review December 7, 2020 14:42
Sources/MapboxDirections/MapboxStreetClass.swift Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
Comment on lines 53 to 54
/// Smaller variation of a roundabout with no center island or obstacle
case MiniRoundabout = "mini_roundabout"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By definition, mini roundabouts are never mapped as ways in OpenStreetMap, so they wouldn’t appear in the routing graph as an edge to assign a Mapbox Streets road class to. It’s worth confirming that this is also true of other data sources, but I’d be hard-pressed to think of a situation where it would make sense to represent a mini roundabout as a linear feature (as opposed to a full-size roundabout).

Comment on lines 55 to 64
/// (point Widened section at the end of a cul-de-sac for turning around a vehicle
case TurningCircle = "turning_circle"
/// (point Similar to a turning circle but with an island or other obstruction at the centerpoint
case TurningLoop = "turning_loop"
/// (point Lights or other signal controlling traffic flow at an intersection
case TrafficSignals = "traffic_signals"
/// (point A point indication for road junctions
case Junction = "junction"
/// (point Indicating the class and type of roads meeting at an intersection. Intersections are only available in Japan
case Intersection = "intersection"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should omit these values. As these road classifications are currently used, they would only occur on linear features, not point features. They appear in the road layer of the Mapbox Streets source because that layer also contains point features. For example, some styles use the road layer’s traffic_signals-classed point features to label traffic lights with 🚦.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Directions team suggests to still have these values even though not all of them can really be present... So maybe we should leave it just to be safe?

Copy link
Contributor

@1ec5 1ec5 Dec 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m inclined to say YAGNI, since we could always add more cases to this non-frozen enumeration without breaking backwards compatibility, and it’s difficult to imagine a situation where the Directions API would start adding these values to edges without breaking backwards compatibility in other ways.

If we really want to be on the safe side, I guess we could leave it in but keep it undocumented. But even then, the downside is that developers still have to deal with these dead code paths whenever they deal with Streets road classes. Swift will complain about these cases being missing from any switch statement unless the developer adds a default @unknown clause. So I’m inclined to omit these values; if on the off chance they occur, it would be the same as an unexpected new value that the Directions API adds after the fact.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the source code, there are more cases which will never make it to the real world navigation: pedestrian (this one is surprising, why not?) , construction, track, path, "major_rail", minor_rail, service_rail, aerialway, golf.
Maybe we should also not add them for now?

Sources/MapboxDirections/MapboxStreetClass.swift Outdated Show resolved Hide resolved
Sources/MapboxDirections/MapboxStreetClass.swift Outdated Show resolved Hide resolved
Sources/MapboxDirections/Intersection.swift Outdated Show resolved Hide resolved
Sources/MapboxDirections/MapboxStreetClass.swift Outdated Show resolved Hide resolved
Sources/MapboxDirections/MapboxStreetClass.swift Outdated Show resolved Hide resolved
Sources/MapboxDirections/MapboxStreetClass.swift Outdated Show resolved Hide resolved
Copy link
Contributor

@1ec5 1ec5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some additional documentation nits:

Sources/MapboxDirections/Intersection.swift Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
Comment on lines 116 to 120
/**
Street class according to Mapbox Streets V8 classification.

This value is set to `nil` of such info is not available.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/**
Street class according to Mapbox Streets V8 classification.
This value is set to `nil` of such info is not available.
*/
/**
The road classes of the road that the containing step uses to leave the intersection, according to the [Mapbox Streets source](https://docs.mapbox.com/vector-tiles/reference/mapbox-streets-v8/#road), version 8.
If detailed road class information is unavailable, this property is set to `nil`. This property only indicates the road classification; for other aspects of the road, use the `outletRoadClasses` property.
*/

And in the outletRoadClasses documentation, add a cross-reference like this:

For more detailed road classifications, use the outletMapboxStreetsRoadClass property.

@Udumft Udumft requested a review from 1ec5 December 9, 2020 11:56
Copy link
Contributor

@1ec5 1ec5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for iterating on this PR a few times; it looks great.

Comment on lines +42 to +51
/// Railways, including mainline, commuter rail, and rapid transit.
case majorRail = "major_rail"
/// Includes light rail & tram lines.
case minorRail = "minor_rail"
/// Yard and service railways.
case serviceRail = "service_rail"
/// Ski lifts, gondolas, and other types of aerialway.
case aerialway = "aerialway"
/// The approximate centerline of a golf course hole
case golf = "golf"
Copy link
Contributor

@1ec5 1ec5 Dec 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case you’re wondering how these classes would ever come up: railroads are sometimes used as driveways in rural areas (but would have to be tagged with the appropriate access tags to be included in a route), and theoretically a ski lift could be part of a pedestrian route.

@Udumft
Copy link
Contributor Author

Udumft commented Dec 11, 2020

I've added a small change that will allow to safely ignore unrecognized road classes. This will allow backwards compatibility with potential future additions to the road classes list without crashing the app.

@Udumft Udumft requested a review from 1ec5 December 11, 2020 08:31
if let classString = try container.decodeIfPresent(String.self, forKey: .streetClass) {
streetClass = MapboxStreetsRoadClass(rawValue: classString)
} else {
streetClass = nil
Copy link
Contributor

@1ec5 1ec5 Dec 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine because adding new road classes is a rare event and the new value wouldn’t be immediately useful in the navigation SDK anyways. However, if we ever learn of a plan to add new road classes in Streets source v8.x, we should proactively implement the other case with an associated value, similar to what’s proposed in #506 (comment). Not necessary just yet though.

@Udumft Udumft merged commit c6fe640 into main Dec 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improvement for an existing feature. platform parity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants