Moin,
I have extended the stop/continue scheme to style-rules without
conversions, i.e. a style rule might now look as follows:
highway=* & surface=sand {set surface=unpaved} [continue]
With this extension the incomplete rules should get an own priority, so
that the processing order of such rules should be defined by their order
in the style file.
A compiled mkgmap based on the multiple_garmin_elements-mb.patch
provided by Mark Burton on 20.09.2009 can be downloaded at:
http://demuur.gmxhome.de/mkgmap_no_conversion_rules.jar
So please try it out, until now I have tested the modification only on a
rather simple example.
And please let me know, whether the attached patch is usable, since this
is my first generated patch. I simply asked svn for the differences
between my local copy and the head version.
Gruss
Torsten
Index: src/uk/me/parabola/imgfmt/app/BufferedImgFileWriter.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/BufferedImgFileWriter.java (Arbeitskopie)
+++ src/uk/me/parabola/imgfmt/app/BufferedImgFileWriter.java (Revision 1148)
@@ -175,8 +175,10 @@
* @param length The amount of data.
*/
private void ensureSize(int length) {
- if (buf.position() +length > bufferSize - GUARD_SIZE) {
- bufferSize += GROW_SIZE;
+ int needed = buf.position() + length;
+ if (needed > (bufferSize - GUARD_SIZE)) {
+ while(needed > (bufferSize - GUARD_SIZE))
+ bufferSize += GROW_SIZE;
if (bufferSize > 0xffffff) {
// Previous message was confusing people, although it is difficult to come
// up with something that is strictly true in all situations.
Index: src/uk/me/parabola/mkgmap/osmstyle/OverlayReader.java
===================================================================
--- src/uk/me/parabola/mkgmap/osmstyle/OverlayReader.java (Arbeitskopie)
+++ src/uk/me/parabola/mkgmap/osmstyle/OverlayReader.java (Revision 1148)
@@ -20,8 +20,10 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
+import java.util.ListIterator;
import java.util.Map;
+import uk.me.parabola.imgfmt.app.Coord;
import uk.me.parabola.mkgmap.general.LineAdder;
import uk.me.parabola.mkgmap.general.MapLine;
import uk.me.parabola.mkgmap.osmstyle.eval.SyntaxException;
@@ -103,10 +105,17 @@
int origType = line.getType();
List<Integer> integerList = overlays.get(origType);
if (integerList != null) {
- for (int t : integerList) {
- MapLine newline = line.copy();
- newline.setType(t);
- newline.setPoints(line.getPoints());
+ MapLine newline = line.copy();
+ newline.setType(integerList.get(0));
+ List<Coord> points = line.getPoints();
+ newline.setPoints(points);
+ adder.add(newline);
+
+ // Force all following types to be added as lines rather than roads.
+ for (ListIterator<Integer> t=integerList.listIterator(1); t.hasNext(); ) {
+ newline = new MapLine(line);
+ newline.setType(t.next());
+ newline.setPoints(new ArrayList<Coord>(points));
adder.add(newline);
}
} else {
Index: src/uk/me/parabola/mkgmap/osmstyle/SequenceRule.java
===================================================================
--- src/uk/me/parabola/mkgmap/osmstyle/SequenceRule.java (Revision 1143)
+++ src/uk/me/parabola/mkgmap/osmstyle/SequenceRule.java (Arbeitskopie)
@@ -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 1143)
+++ src/uk/me/parabola/mkgmap/osmstyle/TypeReader.java (Arbeitskopie)
@@ -23,6 +23,9 @@
}
public GType readType(TokenScanner ts) {
+
+ GType gt;
+
// We should have a '[' to start with
Token t = ts.nextToken();
if (t == null || t.getType() == TokType.EOF)
@@ -34,33 +37,73 @@
ts.skipSpace();
String type = ts.nextValue();
- if (!Character.isDigit(type.charAt(0)))
- throw new SyntaxException(ts, "Garmin type number must be first. Saw '" + type + '\'');
+ if (Character.isDigit(type.charAt(0))) {
- log.debug("gtype", type);
- GType gt = new GType(kind, type);
+ log.debug("gtype", type);
+ gt = new GType(kind, type);
+ gt.setProcessingAndConversion();
- while (!ts.isEndOfFile()) {
- ts.skipSpace();
- String w = ts.nextValue();
- if (w.equals("]"))
- break;
+ while (!ts.isEndOfFile()) {
+ ts.skipSpace();
+ String w = ts.nextValue();
+ if (w.equals("]"))
+ break;
- if (w.equals("level")) {
- setLevel(ts, gt);
- } else if (w.equals("resolution")) {
- setResolution(ts, gt);
- } else if (w.equals("default_name")) {
- gt.setDefaultName(nextValue(ts));
- } else if (w.equals("road_class")) {
- gt.setRoadClass(nextIntValue(ts));
- } else if (w.equals("road_speed")) {
- gt.setRoadSpeed(nextIntValue(ts));
- } else if (w.equals("copy")) {
- // reserved word. not currently used
- } else {
- throw new SyntaxException(ts, "Unrecognised type command '" + w + '\'');
+ if (w.equals("level")) {
+ setLevel(ts, gt);
+ } else if (w.equals("resolution")) {
+ setResolution(ts, gt);
+ } else if (w.equals("default_name")) {
+ gt.setDefaultName(nextValue(ts));
+ } else if (w.equals("road_class")) {
+ gt.setRoadClass(nextIntValue(ts));
+ } else if (w.equals("road_speed")) {
+ 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 + '\'');
+ }
}
+
+ } else if (type.equals("continue")) {
+
+ gt = new GType(kind, "0");
+ gt.setContinue();
+ gt.setProcessingOnly();
+
+ while (!ts.isEndOfFile()) {
+ ts.skipSpace();
+ String w = ts.nextValue();
+ if (w.equals("]")) {
+ break;
+ } else {
+ throw new SyntaxException(ts, "Unrecognised type command '" + w + '\'');
+ }
+ }
+
+ } else if (type.equals("stop")) {
+
+ gt = new GType(kind, "0");
+ gt.setFinal();
+ gt.setProcessingOnly();
+
+ while (!ts.isEndOfFile()) {
+ ts.skipSpace();
+ String w = ts.nextValue();
+ if (w.equals("]")) {
+ break;
+ } else {
+ throw new SyntaxException(ts, "Unrecognised type command '" + w + '\'');
+ }
+ }
+
+ } else {
+ throw new SyntaxException(ts, "Garmin type number must be first. Saw '" + type + '\'');
}
gt.fixLevels(levels);
Index: src/uk/me/parabola/mkgmap/osmstyle/ActionRule.java
===================================================================
--- src/uk/me/parabola/mkgmap/osmstyle/ActionRule.java (Revision 1143)
+++ src/uk/me/parabola/mkgmap/osmstyle/ActionRule.java (Arbeitskopie)
@@ -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 1143)
+++ src/uk/me/parabola/mkgmap/osmstyle/RuleSet.java (Arbeitskopie)
@@ -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 1143)
+++ src/uk/me/parabola/mkgmap/osmstyle/ExpressionRule.java (Arbeitskopie)
@@ -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 1143)
+++ src/uk/me/parabola/mkgmap/osmstyle/FixedRule.java (Arbeitskopie)
@@ -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 1143)
+++ src/uk/me/parabola/mkgmap/osmstyle/StyledConverter.java (Arbeitskopie)
@@ -247,26 +247,40 @@
foundType = makeGTypeFromTags(way);
if(foundType == null)
return;
+ if (!foundType.isProcessingOnly()){
+ if (foundType.getFeatureKind() == GType.POLYLINE) {
+ if(foundType.isRoad())
+ addRoad(way, foundType);
+ else
+ addLine(way, foundType);
+ }
+ else
+ addShape(way, foundType);
+ }
}
else {
preConvertRules(way);
- foundType = wayRules.resolveType(way);
- if (foundType == null)
- return;
- postConvertRules(way, foundType);
- }
+ do {
+ foundType = wayRules.resolveType(way, foundType);
+ if (foundType == null)
+ return;
+
+ postConvertRules(way, foundType);
- if (foundType.getFeatureKind() == GType.POLYLINE) {
- if(foundType.isRoad() &&
- !MapElement.hasExtendedType(foundType.getType()))
- addRoad(way, foundType);
- else
- addLine(way, foundType);
+ if (!foundType.isProcessingOnly()){
+ if (foundType.getFeatureKind() == GType.POLYLINE) {
+ if(foundType.isRoad())
+ addRoad(way, foundType);
+ else
+ addLine(way, foundType);
+ }
+ else
+ addShape(way, foundType);
+ }
+ } while (!foundType.isFinal());
}
- else
- addShape(way, foundType);
}
/**
@@ -282,18 +296,23 @@
foundType = makeGTypeFromTags(node);
if(foundType == null)
return;
+ if (!foundType.isProcessingOnly())
+ addPoint(node, foundType);
}
else {
preConvertRules(node);
- foundType = nodeRules.resolveType(node);
- if (foundType == null)
- return;
+ do {
+ foundType = nodeRules.resolveType(node, foundType);
+ if (foundType == null)
+ return;
- postConvertRules(node, foundType);
+ postConvertRules(node, foundType);
+
+ if (!foundType.isProcessingOnly())
+ addPoint(node, foundType);
+ } while (!foundType.isFinal());
}
-
- addPoint(node, foundType);
}
/**
@@ -349,7 +368,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;
@@ -382,7 +401,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 1143)
+++ src/uk/me/parabola/mkgmap/reader/osm/Rule.java (Arbeitskopie)
@@ -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 1143)
+++ src/uk/me/parabola/mkgmap/reader/osm/GType.java (Arbeitskopie)
@@ -39,6 +39,10 @@
private static int nextPriority = 1;
private static final int PRIORITY_PUSH = 100000;
+ // control flag, whether this is an empty dummy element
+ // for processing rules
+ private boolean RuleWithoutConversion = false;
+
private final int featureKind;
private final int type;
@@ -58,6 +62,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 +199,30 @@
return road;
}
+ public void setFinal() {
+ FinalElement = true;
+ }
+
+ public void setContinue() {
+ FinalElement = false;
+ }
+
+ public boolean isFinal() {
+ return FinalElement;
+ }
+
+ public void setProcessingOnly() {
+ RuleWithoutConversion = true;
+ }
+
+ public void setProcessingAndConversion() {
+ RuleWithoutConversion = false;
+ }
+
+ public boolean isProcessingOnly() {
+ return RuleWithoutConversion;
+ }
+
public static void push() {
nextPriority += PRIORITY_PUSH;
}
Index: resources/styles/default/lines
===================================================================
--- resources/styles/default/lines (Arbeitskopie)
+++ resources/styles/default/lines (Revision 1148)
@@ -69,7 +69,7 @@
railway=tram [0x14 resolution 18]
railway=platform {add access = no; add foot = yes} [0x16 road_class=0 road_speed=0 resolution 23]
-route=ferry [0x1a road_class=0 road_speed=0 resolution 18]
+route=ferry [0x1b road_class=0 road_speed=0 resolution 18]
waterway=canal [0x1f resolution 21]
waterway=drain [0x1f resolution 22]
_______________________________________________
mkgmap-dev mailing list
[email protected]
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev