Hello cyclists,

Here's a little patch that will synthesise a cycleway that "lies on
top" of an existing oneway street when any of the cycleway="opposite"
tags are present. This will allow bicycle traffic to route in the
reverse direction. I have tested this using mapsource (it worked!) but
not a real GPS yet.

It seems to me that if the cycleway is actually a separate track then
it would be better not to use cycleway="opposite_track" but to have a
separate cycleway in the OSM data.

If the original way was called Foostrasse, the cycleway will be
called "Foostrasse (cycleway)". The word cycleway is hard coded. If
that's an issue for you, feel free to submit a new version of the patch
that localises that word.

Cheers,

Mark
diff --git a/src/uk/me/parabola/mkgmap/reader/osm/xml/Osm5XmlHandler.java b/src/uk/me/parabola/mkgmap/reader/osm/xml/Osm5XmlHandler.java
index b7a0ee0..6bb3fc2 100644
--- a/src/uk/me/parabola/mkgmap/reader/osm/xml/Osm5XmlHandler.java
+++ b/src/uk/me/parabola/mkgmap/reader/osm/xml/Osm5XmlHandler.java
@@ -68,6 +68,8 @@ class Osm5XmlHandler extends DefaultHandler {
 	private static final int MODE_RELATION = 4;
 	private static final int MODE_BOUNDS = 5;
 
+	private static final long CYCLEWAY_ID_OFFSET = 0x10000000;
+
 	private Node currentNode;
 	private Way currentWay;
 	private Relation currentRelation;
@@ -277,6 +279,34 @@ class Osm5XmlHandler extends DefaultHandler {
 								currentWay.addTag("mkgmap:frig_roundabout", frigRoundabouts);
 						}
 					}
+					if(currentWay.isBoolTag("oneway")) {
+						String cyclewayTag = currentWay.getTag("cycleway");
+						if("opposite".equals(cyclewayTag) ||
+						   "opposite_lane".equals(cyclewayTag) ||
+						   "opposite_track".equals(cyclewayTag)) {
+							// what we have here is a oneway street
+							// that allows bicycle traffic in both
+							// directions -- to enable bicyle routing
+							// in the reverse direction, we synthesise
+							// a cycleway that has the same points as
+							// the original way
+							long cycleWayId = currentWay.getId() + CYCLEWAY_ID_OFFSET;
+							Way cycleWay = new Way(cycleWayId);
+							wayMap.put(cycleWayId, cycleWay);
+							// this reverses the direction of the way
+							// but that isn't really necessary as the
+							// cycleway isn't tagged as oneway
+							List<Coord> points = currentWay.getPoints();
+							for(int i = points.size() - 1; i >= 0; --i)
+								cycleWay.addPoint(points.get(i));
+							cycleWay.copyTags(currentWay);
+							cycleWay.addTag("name", currentWay.getTag("name") + " (cycleway)");
+							cycleWay.addTag("oneway", "no");
+							cycleWay.addTag("access", "no");
+							cycleWay.addTag("bicycle", "yes");
+							log.info("Synthesising cycleway '" + cycleWay.getTag("name") + "' as way is tagged cycleway=" + cyclewayTag);
+						}
+					}
 				}
 				if("motorway".equals(highway) ||
 				   "trunk".equals(highway))
_______________________________________________
mkgmap-dev mailing list
mkgmap-dev@lists.mkgmap.org.uk
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev

Reply via email to