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..eeab3fc 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,86 @@ public class StyledConverter implements OsmConverter {
lineAdder = overlayAdder;
}
+ private static Pattern commaPattern = Pattern.compile(",");
+
+ public GType makeGTypeFromTags(Element element, int kind) {
+ String[] vals = commaPattern.split(element.getTag("mkgmap:gtype"));
+ String s;
+
+ element.setName(PolishMapDataSource.unescape(element.getTag("name")));
+
+ for(int i = 0; i < vals.length; ++i)
+ vals[i] = vals[i].trim();
+
+ GType gt = new GType(kind, vals[0]);
+
+ if(vals.length >= 2 && vals[1].length() > 0)
+ s = vals[1];
+ else {
+ s = element.getTag("mkgmap:minres");
+ if(s != null)
+ s = s.trim();
+ }
+ if(s != null) {
+ try {
+ gt.setMinResolution(Integer.decode(s));
+ }
+ catch (NumberFormatException nfe) {
+ log.error("Bad value for minres: " + s);
+ }
+ }
+
+ if(vals.length >= 3 && vals[2].length() > 0)
+ s = vals[2];
+ else {
+ s = element.getTag("mkgmap:maxres");
+ if(s != null)
+ s = s.trim();
+ }
+ if(s != null) {
+ try {
+ gt.setMaxResolution(Integer.decode(s));
+ }
+ catch (NumberFormatException nfe) {
+ log.error("Bad value for maxres tag: " + s);
+ }
+ }
+
+ if(vals.length >= 4 && vals[3].length() > 0)
+ s = vals[3];
+ else {
+ s = element.getTag("mkgmap:roadclass");
+ if(s != null)
+ s = s.trim();
+ }
+ if(s != null) {
+ try {
+ gt.setRoadClass(Integer.decode(s));
+ }
+ catch (NumberFormatException nfe) {
+ log.error("Bad value for roadclass: " + s);
+ }
+ }
+
+ if(vals.length >= 5 && vals[4].length() > 0)
+ s = vals[4];
+ else {
+ s = element.getTag("mkgmap:roadspeed");
+ if(s != null)
+ s = s.trim();
+ }
+ if(s != null) {
+ try {
+ gt.setRoadClass(Integer.decode(s));
+ }
+ catch (NumberFormatException nfe) {
+ log.error("Bad value for roadspeed: " + s);
+ }
+ }
+
+ 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 +241,22 @@ public class StyledConverter implements OsmConverter {
if (way.getPoints().size() < 2)
return;
- preConvertRules(way);
+ GType foundType = null;
+ if(way.getTag("mkgmap:gtype") != null) {
+ if("polygon".equals(way.getTag("mkgmap:kind")))
+ foundType = makeGTypeFromTags(way, GType.POLYGON);
+ else
+ foundType = makeGTypeFromTags(way, GType.POLYLINE);
+ }
+ 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 +275,20 @@ 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, GType.POINT);
+ }
+ 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
[email protected]
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev