Skip to content

Add support tag combinations cycleway:left and cycleway:right, fixes #2969 - #2970

Merged
karussell merged 2 commits into
graphhopper:masterfrom
ratrun:issue2969
Apr 15, 2024
Merged

karussell merged 2 commits into
graphhopper:masterfrom
ratrun:issue2969

Conversation

@ratrun

@ratrun ratrun commented Apr 12, 2024

Copy link
Copy Markdown
Contributor

This fixes #2969

final List<String> preferredTags = Arrays.asList("track");
final List<String> searchedValues = Stream.concat(slightPreferredTags.stream(), preferredTags.stream()).toList();
String cycleway = way.getFirstMatchingValue(searchedTags , searchedValues);
if (slightPreferredTags.contains(cycleway)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I do not understand this logic with getFirstMatchingValue. What are you trying to do here? Couldn't we keep using getFirstValue and then call searchedValues.contains here?

@karussell karussell Apr 15, 2024 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

E.g. the following code would also make the test pass:

String cycleway = way.getFirstValue(Arrays.asList("cycleway", "cycleway:left", "cycleway:both"));
Collection<String> values = Arrays.asList("lane", "opposite_track", "shared_lane", "share_busway", "shoulder");
if (values.contains(cycleway) || values.contains(way.getTag("cycleway:right", ""))) {

Or what about the (IMO relative simple) code which collects all the cycleway values:

List<String> values = Arrays.asList("lane", "opposite_track", "track", "shared_lane", "share_busway", "shoulder");
List<String> cyclewayValues = Stream.of("cycleway", "cycleway:left", "cycleway:both", "cycleway:right").map(key -> way.getTag(key, "")).filter(values::contains).toList();
if (cyclewayValues.contains("track")) {
    weightToPrioMap.put(100d, PREFER);
} else if (!cyclewayValues.isEmpty()) {
    weightToPrioMap.put(100d, SLIGHT_PREFER);
}

or

List<String> cyclewayValues = Stream.of("cycleway", "cycleway:left", "cycleway:both", "cycleway:right").map(key -> way.getTag(key, "")).toList();
if (cyclewayValues.contains("track")) {
    weightToPrioMap.put(100d, PREFER);
} else if (Stream.of("lane", "opposite_track", "shared_lane", "share_busway", "shoulder").anyMatch(cyclewayValues::contains)) {
    weightToPrioMap.put(100d, SLIGHT_PREFER);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I like your last suggestion the most and will update the PR accordingly.

@karussell karussell added this to the 9.0 milestone Apr 15, 2024
@karussell
karussell merged commit 60405c4 into graphhopper:master Apr 15, 2024
@karussell

Copy link
Copy Markdown
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bike priority determination problem for tag combination of cycleway:left and cycleway:right

2 participants