v3

Now only has 1 tag (mkgmap:gtype) to specify everything.

tag has the format 'kind,code,minres,maxres,roadclass,roadspeed'

Where kind is 1 for node, 2 for polyline and 3 for polygon.

kind, code and minres are all required to be present, the other values
can be ommitted.

Note, this format has changed since v2.

------------------------

v2

now supports ~[0x??] syntax within name to specify highway shields

to reduce the number of tags required, you can now specify all the
values in the mkgmap:gtype tag like this example:

mkgmap:gtype="0x20,19,,1,2"

type = 0x20
minres = 19
maxres not specified
roadclass = 1
roadspeed = 2

The one tag per value scheme is still supported (for the moment at
least)

--------------

Are you a heavy duty styler? If so, read on:

I notice that quite a lot of postings on the list are from people who
are having problems with complex style files. This little patch won't
(directly) solve those problems but it does provide a useful capability
that could be part of a solution for those people who have complex
styling requirements and are willing to do some coding.

What the patch does is allow elements (nodes, ways) to specify their
garmin type (and a few other things) explicitly using these tags:

mkgmap:gtype  the element's type (integer constant)

mkgmap:kind   one of "node", "polyline", "polygon" (only polygon is used
at this time to differentiate polygons from lines).

mkgmap:minres the element's minimum resolution (needed to make element
visible)

mkgmap:maxres the element's maximum resolution (not required)

mkgmap:roadclass the element's road class (needed for roads)

mkgmap:roadspeed the element's road speed (needed for roads)

If the mkgmap:gtype tag is present, the element will not be passed
through the normal style file process at all.

So how do these tags get added to the OSM data? Well, you could just
add them with an editor but that would get boring pretty quickly so
what I would expect to see is some kind of external filter program that
reads the OSM file and outputs a new OSM file with the appropriate tags
added.

That filter program could be written in any language that has some XML
processing support.

Current issues to be sorted out are handling of the highway shields
(not currently implemented) and also this feature is not compatible with
the cycleway faking code.

All feedback welcome.

Cheers,

Mark

diff --git a/src/uk/me/parabola/mkgmap/osmstyle/StyledConverter.java b/src/uk/me/parabola/mkgmap/osmstyle/StyledConverter.java
index 2a549f8..87ccccd 100644
--- a/src/uk/me/parabola/mkgmap/osmstyle/StyledConverter.java
+++ b/src/uk/me/parabola/mkgmap/osmstyle/StyledConverter.java
@@ -25,6 +25,8 @@ import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
 
+import java.util.regex.Pattern;
+
 import uk.me.parabola.imgfmt.app.Area;
 import uk.me.parabola.imgfmt.app.Coord;
 import uk.me.parabola.imgfmt.app.CoordNode;
@@ -53,6 +55,8 @@ import uk.me.parabola.mkgmap.reader.osm.Rule;
 import uk.me.parabola.mkgmap.reader.osm.Style;
 import uk.me.parabola.mkgmap.reader.osm.Way;
 
+import uk.me.parabola.mkgmap.reader.polish.PolishMapDataSource;
+
 /**
  * Convert from OSM to the mkgmap intermediate format using a style.
  * A style is a collection of files that describe the mappings to be used
@@ -144,6 +148,85 @@ public class StyledConverter implements OsmConverter {
 			lineAdder = overlayAdder;
 	}
 
+	private static Pattern commaPattern = Pattern.compile(",");
+
+	public GType makeGTypeFromTags(Element element) {
+		String[] vals = commaPattern.split(element.getTag("mkgmap:gtype"));
+
+		if(vals.length < 3) {
+			log.error("OSM element " + element.getId() + " has bad mkgmap:gtype value (should be 'kind,code,minres,[maxres],[roadclass],[roadspeed])");
+			log.error("  where kind is " + GType.POINT + "=point, " + GType.POLYLINE + "=polyline, " + GType.POLYGON + "=polygon");
+			return null;
+		}
+
+		element.setName(PolishMapDataSource.unescape(element.getTag("name")));
+
+		for(int i = 0; i < vals.length; ++i)
+			vals[i] = vals[i].trim();
+
+		int kind = 0;
+		try {
+			kind = Integer.decode(vals[0]);
+		}
+		catch (NumberFormatException nfe) {
+			log.error("OSM element " + element.getId() + " has bad value for kind: " + vals[0]);
+			return null;
+		}
+
+		if(kind != GType.POINT &&
+		   kind != GType.POLYLINE &&
+		   kind != GType.POLYGON) {
+			log.error("OSM element " + element.getId() + " has bad value for kind, is " + kind + " but should be " + GType.POINT + ", " + GType.POLYLINE + " or " + GType.POLYGON);
+			return null;
+		}
+
+		try {
+			Integer.decode(vals[1]);
+		}
+		catch (NumberFormatException nfe) {
+			log.error("OSM element " + element.getId() + " has bad value for type: " + vals[1]);
+			return null;
+		}
+
+		GType gt = new GType(kind, vals[1]);
+
+		try {
+			gt.setMinResolution(Integer.decode(vals[2]));
+		}
+		catch (NumberFormatException nfe) {
+			log.error("OSM element " + element.getId() + " has bad value for minres: " + vals[2]);
+		}
+
+		if(vals.length >= 4 && vals[3].length() > 0) {
+			try {
+				gt.setMaxResolution(Integer.decode(vals[3]));
+			}
+			catch (NumberFormatException nfe) {
+				log.error("OSM element " + element.getId() + " has bad value for maxres tag: " + vals[3]);
+			}
+		}
+
+		if(vals.length >= 5 && vals[4].length() > 0) {
+			try {
+				gt.setRoadClass(Integer.decode(vals[4]));
+			}
+			catch (NumberFormatException nfe) {
+				log.error("OSM element " + element.getId() + " has bad value for roadclass: " + vals[4]);
+			}
+		}
+
+		if(vals.length >= 6 && vals[5].length() > 0) {
+			try {
+				gt.setRoadClass(Integer.decode(vals[5]));
+			}
+			catch (NumberFormatException nfe) {
+				log.error("OSM element " + element.getId() + " has bad value for roadspeed: " + vals[5]);
+			}
+		}
+
+		return gt;
+	}
+
 	/**
 	 * This takes the way and works out what kind of map feature it is and makes
 	 * the relevant call to the mapper callback.
@@ -157,13 +240,21 @@ public class StyledConverter implements OsmConverter {
 		if (way.getPoints().size() < 2)
 			return;
 
-		preConvertRules(way);
+		GType foundType = null;
+		if(way.getTag("mkgmap:gtype") != null) {
+			foundType = makeGTypeFromTags(way);
+			if(foundType == null)
+				return;
+		}
+		else {
+			preConvertRules(way);
 
-		GType foundType = wayRules.resolveType(way);
-		if (foundType == null)
-			return;
+			foundType = wayRules.resolveType(way);
+			if (foundType == null)
+				return;
 
-		postConvertRules(way, foundType);
+			postConvertRules(way, foundType);
+		}
 
 		if (foundType.getFeatureKind() == GType.POLYLINE) {
 		    if(foundType.isRoad())
@@ -182,13 +273,22 @@ public class StyledConverter implements OsmConverter {
 	 * @param node The node to convert.
 	 */
 	public void convertNode(Node node) {
-		preConvertRules(node);
 
-		GType foundType = nodeRules.resolveType(node);
-		if (foundType == null)
-			return;
+		GType foundType = null;
+		if(node.getTag("mkgmap:gtype") != null) {
+			foundType = makeGTypeFromTags(node);
+			if(foundType == null)
+				return;
+		}
+		else {
+			preConvertRules(node);
 
-		postConvertRules(node, foundType);
+			foundType = nodeRules.resolveType(node);
+			if (foundType == null)
+				return;
+
+			postConvertRules(node, foundType);
+		}
 
 		addPoint(node, foundType);
 	}
diff --git a/src/uk/me/parabola/mkgmap/reader/polish/PolishMapDataSource.java b/src/uk/me/parabola/mkgmap/reader/polish/PolishMapDataSource.java
index afda875..d2dc657 100644
--- a/src/uk/me/parabola/mkgmap/reader/polish/PolishMapDataSource.java
+++ b/src/uk/me/parabola/mkgmap/reader/polish/PolishMapDataSource.java
@@ -397,7 +397,7 @@ public class PolishMapDataSource extends MapperBasedMapDataSource implements Loa
 	 * @param s The original string that may contain codes.
 	 * @return A string with the escape codes replaced by the single character.
 	 */
-	private String unescape(String s) {
+	public static String unescape(String s) {
 		int ind = s.indexOf("~[");
 		if (ind < 0)
 			return s;
_______________________________________________
mkgmap-dev mailing list
mkgmap-dev@lists.mkgmap.org.uk
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev

Reply via email to