Steve, all,
Some relations legitimately contain elements in multiple roles.
An example is bus routes that partially coincide with oneway streets
or roundabouts. These are best drawn as closed loops that do cover
the twoway streets twice (once in role=forward and once in role=backward).
The attached patch implements an apply_once keyword that will apply the
commands only once per matching relation member. OK to commit?
Best regards,
Marko
Index: src/uk/me/parabola/mkgmap/osmstyle/actions/ActionReader.java
===================================================================
--- src/uk/me/parabola/mkgmap/osmstyle/actions/ActionReader.java (revision 1455)
+++ src/uk/me/parabola/mkgmap/osmstyle/actions/ActionReader.java (working copy)
@@ -55,7 +55,9 @@ public class ActionReader {
} else if ("add".equals(cmd)) {
actions.add(readTagValue(false));
} else if ("apply".equals(cmd)) {
- actions.add(readAllCmd());
+ actions.add(readAllCmd(false));
+ } else if ("apply_once".equals(cmd)) {
+ actions.add(readAllCmd(true));
} else if ("name".equals(cmd)) {
actions.add(readNameCmd());
} else if ("delete".equals(cmd)) {
@@ -81,7 +83,7 @@ public class ActionReader {
return actions;
}
- private Action readAllCmd() {
+ private Action readAllCmd(boolean once) {
String role = null;
if (scanner.checkToken("role")) {
scanner.nextToken();
@@ -90,7 +92,7 @@ public class ActionReader {
throw new SyntaxException(scanner, "Expecting '=' after role keyword");
role = scanner.nextWord();
}
- SubAction subAction = new SubAction(role);
+ SubAction subAction = new SubAction(role, once);
List<Action> actionList = readActions();
for (Action a : actionList)
Index: src/uk/me/parabola/mkgmap/osmstyle/actions/SubAction.java
===================================================================
--- src/uk/me/parabola/mkgmap/osmstyle/actions/SubAction.java (revision 1455)
+++ src/uk/me/parabola/mkgmap/osmstyle/actions/SubAction.java (working copy)
@@ -18,6 +18,7 @@ package uk.me.parabola.mkgmap.osmstyle.a
import java.util.ArrayList;
import java.util.Formatter;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -35,9 +36,11 @@ import uk.me.parabola.mkgmap.reader.osm.
public class SubAction implements Action {
private final List<Action> actionList = new ArrayList<Action>();
private final String role;
+ private final boolean once;
- public SubAction(String role) {
+ public SubAction(String role, boolean once) {
this.role = role;
+ this.once = once;
}
public void perform(Element el) {
@@ -48,8 +51,10 @@ public class SubAction implements Action
private void performOnSubElements(Relation rel) {
List<Element> elements = rel.getElements();
Map<Element, String> roles = rel.getRoles();
+ HashSet<Element> elems = once ? new HashSet<Element>() : null;
+
for (Element el : elements) {
- if (role == null || role.equals(roles.get(el))) {
+ if ((role == null || role.equals(roles.get(el))) && (!once || elems.add(el))) {
for (Action a : actionList) {
if (a instanceof AddTagAction)
((AddTagAction) a).setValueTags(rel);
@@ -67,7 +72,8 @@ public class SubAction implements Action
Formatter fmt = new Formatter();
if (role != null)
fmt.format("role=%s ", role);
- fmt.format("apply {");
+ fmt.format(once ? "apply_once" : "apply");
+ fmt.format(" {");
for (Iterator<Action> it = actionList.iterator(); it.hasNext();) {
Action a = it.next();
_______________________________________________
mkgmap-dev mailing list
[email protected]
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev