As per OSM Wiki, it expects vehicle classes to be separated with ';'
Works in mapsource, not tried on a real GPS.
Doesn't appear to work for either pedestrians or emergency vehicles.
diff --git a/src/uk/me/parabola/imgfmt/app/net/RouteRestriction.java b/src/uk/me/parabola/imgfmt/app/net/RouteRestriction.java
index ee51bad..ba5691b 100644
--- a/src/uk/me/parabola/imgfmt/app/net/RouteRestriction.java
+++ b/src/uk/me/parabola/imgfmt/app/net/RouteRestriction.java
@@ -56,16 +56,27 @@ public class RouteRestriction {
// last restriction in a node
private boolean last;
+ // mask that specifies which vehicle types the restriction doesn't apply to
+ private final byte exceptMask;
+
+ public final static byte EXCEPT_CAR = 0x01;
+ public final static byte EXCEPT_BUS = 0x02;
+ public final static byte EXCEPT_TAXI = 0x04;
+ public final static byte EXCEPT_DELIVERY = 0x10;
+ public final static byte EXCEPT_BICYCLE = 0x20;
+ public final static byte EXCEPT_TRUCK = 0x40;
+
/**
* Create a route restriction.
*
* @param from The inverse arc of "from" arc.
* @param to The "to" arc.
*/
- public RouteRestriction(RouteArc from, RouteArc to) {
+ public RouteRestriction(RouteArc from, RouteArc to, byte exceptMask) {
assert from.getSource().equals(to.getSource()) : "arcs in restriction don't meet";
this.from = from;
this.to = to;
+ this.exceptMask = exceptMask;
}
private int calcOffset(RouteNode node, int tableOffset) {
@@ -82,7 +93,16 @@ public class RouteRestriction {
* @param tableOffset The offset in NOD 1 of the tables area.
*/
public void write(ImgFileWriter writer, int tableOffset) {
- writer.put3(HEADER);
+ int header = HEADER;
+
+ if(exceptMask != 0)
+ header |= 0x0800;
+
+ writer.put3(header);
+
+ if(exceptMask != 0)
+ writer.put(exceptMask);
+
int[] offsets = new int[3];
if (from.isInternal())
@@ -125,7 +145,10 @@ public class RouteRestriction {
* Size in bytes of the Table C entry.
*/
public int getSize() {
- return SIZE;
+ int size = SIZE;
+ if(exceptMask != 0)
+ ++size;
+ return size;
}
public void setOffsetC(int offsetC) {
diff --git a/src/uk/me/parabola/mkgmap/general/RoadNetwork.java b/src/uk/me/parabola/mkgmap/general/RoadNetwork.java
index 0c45d68..8506381 100644
--- a/src/uk/me/parabola/mkgmap/general/RoadNetwork.java
+++ b/src/uk/me/parabola/mkgmap/general/RoadNetwork.java
@@ -182,7 +182,7 @@ public class RoadNetwork {
return boundary;
}
- public void addRestriction(CoordNode fromNode, CoordNode toNode, CoordNode viaNode) {
+ public void addRestriction(CoordNode fromNode, CoordNode toNode, CoordNode viaNode, byte exceptMask) {
RouteNode fn = nodes.get(fromNode.getId());
RouteNode tn = nodes.get(toNode.getId());
RouteNode vn = nodes.get(viaNode.getId());
@@ -197,7 +197,7 @@ public class RoadNetwork {
assert fa != null : "can't locate arc from 'via' node to 'from' node";
assert ta != null : "can't locate arc from 'via' node to 'to' node";
- vn.addRestriction(new RouteRestriction(fa, ta));
+ vn.addRestriction(new RouteRestriction(fa, ta, exceptMask));
}
}
diff --git a/src/uk/me/parabola/mkgmap/reader/osm/RestrictionRelation.java b/src/uk/me/parabola/mkgmap/reader/osm/RestrictionRelation.java
index e00f677..6fafaa2 100644
--- a/src/uk/me/parabola/mkgmap/reader/osm/RestrictionRelation.java
+++ b/src/uk/me/parabola/mkgmap/reader/osm/RestrictionRelation.java
@@ -7,6 +7,7 @@ import java.util.Map;
import uk.me.parabola.imgfmt.app.Coord;
import uk.me.parabola.imgfmt.app.CoordNode;
+import uk.me.parabola.imgfmt.app.net.RouteRestriction;
import uk.me.parabola.log.Logger;
import uk.me.parabola.mkgmap.general.RoadNetwork;
@@ -28,6 +29,7 @@ public class RestrictionRelation extends Relation {
private CoordNode toNode;
private CoordNode viaNode;
private final List<CoordNode> otherNodes = new ArrayList<CoordNode>();
+ private byte exceptMask;
private final String messagePrefix;
/**
@@ -105,7 +107,6 @@ public class RestrictionRelation extends Relation {
restriction = getTag("restriction");
String[] unsupportedTags = {
- "except",
"day_on",
"day_off",
"hour_on",
@@ -115,6 +116,29 @@ public class RestrictionRelation extends Relation {
log.warn(messagePrefix + "ignoring unsupported '" + unsupportedTag + "' tag");
}
}
+
+ String except = getTag("except");
+ if(except == null)
+ except = getTag("exception"); // be nice
+ if(except != null) {
+ for(String e : except.split(";")) {
+ e = e.trim();
+ if(e.equals("motorcar") || e.equals("motorcycle"))
+ exceptMask |= RouteRestriction.EXCEPT_CAR;
+ else if(e.equals("psv") || e.equals("bus"))
+ exceptMask |= RouteRestriction.EXCEPT_BUS;
+ else if(e.equals("taxi"))
+ exceptMask |= RouteRestriction.EXCEPT_TAXI;
+ else if(e.equals("delivery") || e.equals("goods"))
+ exceptMask |= RouteRestriction.EXCEPT_DELIVERY;
+ else if(e.equals("bicycle"))
+ exceptMask |= RouteRestriction.EXCEPT_BICYCLE;
+ else if(e.equals("hgv") || e.equals("truck"))
+ exceptMask |= RouteRestriction.EXCEPT_TRUCK;
+ else
+ log.warn(messagePrefix + "ignoring unsupported vehicle class '" + e + "' in turn restriction exception");
+ }
+ }
}
public Way getFromWay() {
@@ -236,7 +260,7 @@ public class RestrictionRelation extends Relation {
restriction.equals("no_straight_on") ||
restriction.equals("no_u_turn") ||
restriction.startsWith("no_turn")) {
- roadNetwork.addRestriction(fromNode, toNode, viaNode);
+ roadNetwork.addRestriction(fromNode, toNode, viaNode, exceptMask);
if(restriction.startsWith("no_turn"))
log.warn(messagePrefix + "has bad type '" + restriction + "' it should be of the form no_X_turn rather than no_turn_X - I added the restriction anyway at " + viaNode.toDegreeString() + " (blocked routing to " + toNode.toDegreeString() + ")");
else
@@ -246,7 +270,7 @@ public class RestrictionRelation extends Relation {
restriction.equals("only_right_turn") ||
restriction.equals("only_straight_on")) {
for(CoordNode otherNode : otherNodes) {
- roadNetwork.addRestriction(fromNode, otherNode, viaNode);
+ roadNetwork.addRestriction(fromNode, otherNode, viaNode, exceptMask);
log.info(messagePrefix + "(" + restriction + ") added at " + viaNode.toDegreeString() + " (blocked routing to " + otherNode.toDegreeString() + ")");
}
}
_______________________________________________
mkgmap-dev mailing list
[email protected]
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev