Torsten Leistikow wrote:
Moin,

finally I got my eclipse environment running and was able to build
mkgmap from source. So the next step was my first extension of mkgmap.

Until now a single OSM element was converted into a single garmin
element, i.e. the first one in the style file with the matching expression.

I have extended the style definition by two commands (stop and
continue), to allow the
generation of multiple elements.

A classic conversion rule has a syntax like:

amenity=restaurant [0x2a00 resolution 20]

With my extension this is equal to

amenity=restaurant [0x2a00 resolution 20 stop]

and has the meaning: If this rule is used, no further rules will be
applied to the element.

If this line is changed now to

amenity=restaurant [0x2a00 resolution 20 continue]

mkgmap will convert a matching OSM element into a garmin Element type
0x2a00, but afterwards it will check, whether another rule is matching
for the same osm element. So this will allow, that for the same item
additionally a

tourism=hotel [0x2b01 resolution 20]

rule might be applied.

My modification is working on points as well as on lines or polygons,
i.e. it will also help with barrier=fence problem.

There are two problems with my modification:

1. The POI generation for an area will not work, with multiple
conversion rules.

2. I do not know, how to provide a proper patch for my modification, so
I just attached the modified java-files (based on mkgmap-r1087).

I hope you can incorporate the modification into your mkgmap and give it
a try. Without any change to the style, the modification should not
change anything. As a try, you could add the continue command to all
point rules and all barrier rules.

What do you think about it?

Gruss
Torsten
------------------------------------------------------------------------

_______________________________________________
mkgmap-dev mailing list
mkgmap-dev@lists.mkgmap.org.uk
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev
Could you or someone try to modify this patch so that it compiles against mkgmap 1140.

I tried merging it for more than 1 hour today but did not get any clean compile. There are nearly 10 conflicts against the new extended types code. Both, the extended types and the "continue" behaviour are very important features for me.....

I would really miss the above patch if it is not implementable to current svn.

thanks very much in advance if someone could try to change it to get it working... I attach the patch as prepared by Thilo again so searching for old e-mails is not needed....
Index: src/uk/me/parabola/mkgmap/osmstyle/SequenceRule.java
===================================================================
--- src/uk/me/parabola/mkgmap/osmstyle/SequenceRule.java	(revision 1097)
+++ src/uk/me/parabola/mkgmap/osmstyle/SequenceRule.java	(working copy)
@@ -34,9 +34,9 @@
 public class SequenceRule implements Rule, Iterable<Rule> {
 	private final List<Rule> ruleList = new ArrayList<Rule>();
 
-	public GType resolveType(Element el) {
+	public GType resolveType(Element el, GType pre) {
 		for (Rule r : ruleList) {
-			GType type = r.resolveType(el);
+			GType type = r.resolveType(el, pre);
 			if (type != null)
 				return type;
 		}
Index: src/uk/me/parabola/mkgmap/osmstyle/TypeReader.java
===================================================================
--- src/uk/me/parabola/mkgmap/osmstyle/TypeReader.java	(revision 1097)
+++ src/uk/me/parabola/mkgmap/osmstyle/TypeReader.java	(working copy)
@@ -58,6 +58,10 @@
 				gt.setRoadSpeed(nextIntValue(ts));
 			} else if (w.equals("copy")) {
 				// reserved word.  not currently used
+			} else if (w.equals("continue")) {
+				gt.setContinue();
+			} else if (w.equals("stop")) {
+				gt.setFinal();
 			} else {
 				throw new SyntaxException(ts, "Unrecognised type command '" + w + '\'');
 			}
Index: src/uk/me/parabola/mkgmap/osmstyle/ActionRule.java
===================================================================
--- src/uk/me/parabola/mkgmap/osmstyle/ActionRule.java	(revision 1097)
+++ src/uk/me/parabola/mkgmap/osmstyle/ActionRule.java	(working copy)
@@ -52,7 +52,7 @@
 		this.type = null;
 	}
 
-	public GType resolveType(Element el) {
+	public GType resolveType(Element el, GType pre) {
 		if (expression == null || expression.eval(el)) {
 			for (Action a : actions)
 				a.perform(el);
Index: src/uk/me/parabola/mkgmap/osmstyle/RuleSet.java
===================================================================
--- src/uk/me/parabola/mkgmap/osmstyle/RuleSet.java	(revision 1097)
+++ src/uk/me/parabola/mkgmap/osmstyle/RuleSet.java	(working copy)
@@ -63,14 +63,14 @@
 		return rules.entrySet();
 	}
 
-	public GType resolveType(Element el) {
+	public GType resolveType(Element el, GType pre) {
 		GType foundType = null;
 		for (String tagKey : el) {
 			Rule rule = rules.get(tagKey);
 			if (rule != null) {
-				GType type = rule.resolveType(el);
+				GType type = rule.resolveType(el, pre);
 				if (type != null) {
-					if (foundType == null || type.isBetterPriority(foundType)) {
+					if ((foundType == null || type.isBetterPriority(foundType)) && (pre == null || pre.isBetterPriority(type))) {
 						foundType = type;
 					}
 				}
Index: src/uk/me/parabola/mkgmap/osmstyle/ExpressionRule.java
===================================================================
--- src/uk/me/parabola/mkgmap/osmstyle/ExpressionRule.java	(revision 1097)
+++ src/uk/me/parabola/mkgmap/osmstyle/ExpressionRule.java	(working copy)
@@ -28,22 +28,22 @@
  * @author Steve Ratcliffe
  */
 public class ExpressionRule implements Rule {
-	private final Op exression;
+	private final Op expression;
 	private final GType gtype;
 
-	public ExpressionRule(Op exression, GType gtype) {
-		this.exression = exression;
+	public ExpressionRule(Op expression, GType gtype) {
+		this.expression = expression;
 		this.gtype = gtype;
 	}
 
-	public GType resolveType(Element el) {
-		if (exression.eval(el))
+	public GType resolveType(Element el, GType pre) {
+		if (expression.eval(el))
 			return gtype;
 
 		return null;
 	}
 
 	public String toString() {
-		return exression.toString() + ' ' + gtype;
+		return expression.toString() + ' ' + gtype;
 	}
 }
Index: src/uk/me/parabola/mkgmap/osmstyle/FixedRule.java
===================================================================
--- src/uk/me/parabola/mkgmap/osmstyle/FixedRule.java	(revision 1097)
+++ src/uk/me/parabola/mkgmap/osmstyle/FixedRule.java	(working copy)
@@ -32,7 +32,7 @@
 		this.gtype = gtype;
 	}
 
-	public GType resolveType(Element el) {
+	public GType resolveType(Element el, GType pre) {
 		return gtype;
 	}
 
Index: src/uk/me/parabola/mkgmap/osmstyle/StyledConverter.java
===================================================================
--- src/uk/me/parabola/mkgmap/osmstyle/StyledConverter.java	(revision 1097)
+++ src/uk/me/parabola/mkgmap/osmstyle/StyledConverter.java	(working copy)
@@ -159,20 +159,24 @@
 
 		preConvertRules(way);
 
-		GType foundType = wayRules.resolveType(way);
-		if (foundType == null)
-			return;
+		GType foundType = null;
 
-		postConvertRules(way, foundType);
+		do {
+			foundType = wayRules.resolveType(way, foundType);
+			if (foundType == null)
+				return;
 
-		if (foundType.getFeatureKind() == GType.POLYLINE) {
-		    if(foundType.isRoad())
-				addRoad(way, foundType);
-		    else
-				addLine(way, foundType);
-		}
-		else
-			addShape(way, foundType);
+			postConvertRules(way, foundType);
+
+			if (foundType.getFeatureKind() == GType.POLYLINE) {
+				if(foundType.isRoad())
+					addRoad(way, foundType);
+				else
+					addLine(way, foundType);
+			}
+			else
+				addShape(way, foundType);
+		} while (!foundType.isFinal());
 	}
 
 	/**
@@ -184,13 +188,17 @@
 	public void convertNode(Node node) {
 		preConvertRules(node);
 
-		GType foundType = nodeRules.resolveType(node);
-		if (foundType == null)
-			return;
+		GType foundType = null;
 
-		postConvertRules(node, foundType);
+		do {
+			foundType = nodeRules.resolveType(node, foundType);
+			if (foundType == null)
+				return;
 
-		addPoint(node, foundType);
+			postConvertRules(node, foundType);
+
+			addPoint(node, foundType);
+		} while (!foundType.isFinal());
 	}
 
 	/**
@@ -246,7 +254,7 @@
 	public void convertRelation(Relation relation) {
 		// Relations never resolve to a GType and so we ignore the return
 		// value.
-		relationRules.resolveType(relation);
+		relationRules.resolveType(relation, null);
 
 		if(relation instanceof RestrictionRelation) {
 			RestrictionRelation rr = (RestrictionRelation)relation;
@@ -279,7 +287,7 @@
 
 		clipper.clipShape(shape, collector);
 		
-		GType pointType = nodeRules.resolveType(way);
+		GType pointType = nodeRules.resolveType(way, null);
 		
 		if(pointType != null)
 			shape.setPoiType(pointType.getType());
Index: src/uk/me/parabola/mkgmap/reader/osm/Rule.java
===================================================================
--- src/uk/me/parabola/mkgmap/reader/osm/Rule.java	(revision 1097)
+++ src/uk/me/parabola/mkgmap/reader/osm/Rule.java	(working copy)
@@ -29,7 +29,8 @@
 	 * represent it.
 	 *
 	 * @param el The element as read from an OSM xml file in 'tag' format.
+	 * @param pre The previous garmin type generated from the element.
 	 * @return Enough information to represent this as a garmin type.
 	 */
-	public GType resolveType(Element el);
+	public GType resolveType(Element el, GType pre);
 }
Index: src/uk/me/parabola/mkgmap/reader/osm/GType.java
===================================================================
--- src/uk/me/parabola/mkgmap/reader/osm/GType.java	(revision 1097)
+++ src/uk/me/parabola/mkgmap/reader/osm/GType.java	(working copy)
@@ -58,6 +58,11 @@
 
 	private boolean road;
 
+	// control flag, whether this element defines
+	// the final conversion, or whether we shall search
+	// for further matching elements
+	private boolean FinalElement = true;
+	
 	public GType(int featureKind, String type) {
 		priority = nextPriority();
 		this.featureKind = featureKind;
@@ -190,6 +195,18 @@
 		return road;
 	}
 
+	public void setFinal() {
+		FinalElement = true;
+	}
+	
+	public void setContinue() {
+		FinalElement = false;
+	}
+	
+	public boolean isFinal() {
+		return FinalElement;
+	}
+	
 	public static void push() {
 		nextPriority += PRIORITY_PUSH;
 	}
_______________________________________________
mkgmap-dev mailing list
mkgmap-dev@lists.mkgmap.org.uk
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev

Reply via email to