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

Allow multiple from/to members in no_entry/no_exit relations #1040

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -591,15 +591,18 @@ private void indexHighwayRestrictions(Entity e, OsmDbAccessorContext ctx) throws
String val = e.getTag("restriction"); //$NON-NLS-1$
if (val != null) {
Relation r = (Relation) e;
List<RelationMember> lfrom = r.getMembers("from");
List<RelationMember> lto = r.getMembers("to");
if("no_u_turn".equalsIgnoreCase(val)) {
if(lfrom.size() == 1 && lto.size() == 1 &&
if ("no_u_turn".equalsIgnoreCase(val)) { //$NON-NLS-1$
List<RelationMember> lfrom = r.getMembers("from"); //$NON-NLS-1$
List<RelationMember> lto = r.getMembers("to"); //$NON-NLS-1$
if (lfrom.size() == 1 && lto.size() == 1 &&
lfrom.get(0).getEntityId().equals(lto.get(0).getEntityId())) {
// don't index such roads - can't go through issue https://www.openstreetmap.org/way/338099991#map=17/46.86699/-0.20473
return;
}
}

boolean allowMultipleFrom = false;
boolean allowMultipleTo = false;
byte type = -1;
if ("no_right_turn".equalsIgnoreCase(val)) { //$NON-NLS-1$
type = MapRenderingTypes.RESTRICTION_NO_RIGHT_TURN;
Expand All @@ -612,9 +615,11 @@ private void indexHighwayRestrictions(Entity e, OsmDbAccessorContext ctx) throws
} else if ("no_entry".equalsIgnoreCase(val)) { //$NON-NLS-1$
// reuse no straight on
type = MapRenderingTypes.RESTRICTION_NO_STRAIGHT_ON;
allowMultipleFrom = true;
} else if ("no_exit".equalsIgnoreCase(val)) { //$NON-NLS-1$
// reuse no straight on
type = MapRenderingTypes.RESTRICTION_NO_STRAIGHT_ON;
allowMultipleTo = true;
} else if ("only_right_turn".equalsIgnoreCase(val)) { //$NON-NLS-1$
type = MapRenderingTypes.RESTRICTION_ONLY_RIGHT_TURN;
} else if ("only_left_turn".equalsIgnoreCase(val)) { //$NON-NLS-1$
Expand All @@ -623,27 +628,39 @@ private void indexHighwayRestrictions(Entity e, OsmDbAccessorContext ctx) throws
type = MapRenderingTypes.RESTRICTION_ONLY_STRAIGHT_ON;
}
if (type != -1) {
ctx.loadEntityRelation((Relation) e);
Collection<RelationMember> fromL = ((Relation) e).getMembers("from"); //$NON-NLS-1$
Collection<RelationMember> toL = ((Relation) e).getMembers("to"); //$NON-NLS-1$
Collection<RelationMember> viaL = ((Relation) e).getMembers("via"); //$NON-NLS-1$
if (!fromL.isEmpty() && !toL.isEmpty()) {
RelationMember from = fromL.iterator().next();
RelationMember to = toL.iterator().next();
if (from.getEntityId().getType() == EntityType.WAY) {
if (!highwayRestrictions.containsKey(from.getEntityId().getId())) {
highwayRestrictions.put(from.getEntityId().getId(), new ArrayList<>());
}
RestrictionInfo rd = new RestrictionInfo();
rd.toWay = to.getEntityId().getId();
rd.type = type;
if(!viaL.isEmpty()) {
RelationMember via = viaL.iterator().next();
if(via.getEntityId().getType() == EntityType.WAY) {
rd.viaWay = via.getEntityId().getId();
ctx.loadEntityRelation(r);
Collection<RelationMember> fromL = r.getMembers("from"); //$NON-NLS-1$
Collection<RelationMember> toL = r.getMembers("to"); //$NON-NLS-1$
Collection<RelationMember> viaL = r.getMembers("via"); //$NON-NLS-1$
if (!toL.isEmpty()) {
for (RelationMember from : fromL) {
if (from.getEntityId().getType() == EntityType.WAY) {
if (!highwayRestrictions.containsKey(from.getEntityId().getId())) {
highwayRestrictions.put(from.getEntityId().getId(), new ArrayList<>());
}

List<RestrictionInfo> rdList = highwayRestrictions.get(from.getEntityId().getId());
for (RelationMember to : toL) {
RestrictionInfo rd = new RestrictionInfo();
rd.toWay = to.getEntityId().getId();
rd.type = type;
if (!viaL.isEmpty()) {
RelationMember via = viaL.iterator().next();
if (via.getEntityId().getType() == EntityType.WAY) {
rd.viaWay = via.getEntityId().getId();
}
}
rdList.add(rd);

if (!allowMultipleTo) {
break;
}
}
}
highwayRestrictions.get(from.getEntityId().getId()).add(rd);

if (!allowMultipleFrom) {
break;
}
}
}
}
Expand Down