In case multiple ways were joined to a polygon the polygon was tagged with the union set of tags of all joined ways. This algorithm is not compatible to the tag join algorithm described on the multipolygon relation definition (http://wiki.openstreetmap.org/wiki/Relation:multipolygon#Tagging).

Additionally it can produce weired results. Example:

MP, Tags: type=multipolygon (no more)
Way 1, role=outer, Tags: boundary=administrative, highway=primary
Way 2, role=outer, Tags: boundary=administrative

The resulting polygon was tagged with
boundary=administrative, highway=primary

So a primary road was created around the complete region.

The new algorithm creates a polygon with boundary=administrative only.

WanMil
Index: src/uk/me/parabola/mkgmap/reader/osm/Element.java
===================================================================
--- src/uk/me/parabola/mkgmap/reader/osm/Element.java   (revision 1598)
+++ src/uk/me/parabola/mkgmap/reader/osm/Element.java   (working copy)
@@ -66,7 +66,7 @@
                this.id = id;
        }
 
-       protected String toTagString() {
+       String toTagString() {
                if (tags == null)
                        return "";
 
Index: src/uk/me/parabola/mkgmap/reader/osm/MultiPolygonRelation.java
===================================================================
--- src/uk/me/parabola/mkgmap/reader/osm/MultiPolygonRelation.java      
(revision 1598)
+++ src/uk/me/parabola/mkgmap/reader/osm/MultiPolygonRelation.java      
(working copy)
@@ -670,11 +670,7 @@
                                        // remove all polygons tags from the 
original ways
                                        // sometimes the ways seem to be 
autoclosed later on
                                        // in mkgmap
-                                       for (Way w : 
currentPolygon.polygon.getOriginalWays()) {
-                                               for (String polygonTag : 
polygonTags) {
-                                                       w.deleteTag(polygonTag);
-                                               }
-                                       }
+                                       
currentPolygon.polygon.removePolygonTagsInOrgWays();
                                }
 
                                boolean useRelationTags = currentPolygon.outer
@@ -684,12 +680,15 @@
                                        // tags of the outer polygon
                                        for (Way p : singularOuterPolygons) {
                                                p.copyTags(this);
+                                               p.deleteTag("type");
                                        }
                                }
 
                                for (Way mpWay : singularOuterPolygons) {
                                        // put the cut out polygons to the
                                        // final way map
+                                       if (log.isDebugEnabled())
+                                               
log.debug(mpWay.getId(),mpWay.toTagString());
                                        tileWayMap.put(mpWay.getId(), mpWay);
                                }
                        }
@@ -1616,11 +1615,13 @@
                }
        }
 
+       private static final boolean joinWayTagMerge = false;
+       
        /**
         * This is a helper class that stores that gives access to the original
         * segments of a joined way.
         */
-       private static class JoinedWay extends Way {
+       private static final class JoinedWay extends Way {
                private final List<Way> originalWays;
                private boolean closedArtificially = false;
 
@@ -1723,10 +1724,26 @@
                }
 
                private void addTagsOf(Way way) {
-                       for (Map.Entry<String, String> tag : 
way.getEntryIteratable()) {
-                               if (getTag(tag.getKey()) == null) {
+                       boolean merge = (joinWayTagMerge || 
getOriginalWays().size()<=1);
+                       if (merge) {
+                               for (Map.Entry<String, String> tag : 
way.getEntryIteratable()) {
                                        addTag(tag.getKey(), tag.getValue());
                                }
+                       } else {
+                               // only use tags that are in both ways
+                               for (Map.Entry<String, String> tag : 
this.getEntryIteratable()) {
+                                       String wayTagValue = 
way.getTag(tag.getKey());
+                                       if 
(tag.getValue().equals(wayTagValue)==false) {
+                                               // the tags are different
+                                               if (log.isDebugEnabled()) {
+                                                       log.debug("Remove 
differing 
tag",tag.getKey(),getId()+"="+tag.getValue(),way.getId()+"="+wayTagValue);
+                                               }
+                                               if (wayTagValue!= null) {
+                                                       deleteTag(tag.getKey());
+                                               }
+                                       }
+                               }
+                               
                        }
                }
 
@@ -1734,6 +1751,14 @@
                        return originalWays;
                }
 
+               public void removePolygonTagsInOrgWays() {
+                       for (Way w : getOriginalWays()) {
+                               for (String polygonTag : polygonTags) {
+                                       w.deleteTag(polygonTag);
+                               }
+                       }
+               }
+               
                public void removeAllTagsDeep() {
                        removeOriginalTags();
                        removeAllTags();
@@ -1744,7 +1769,12 @@
                                if (w instanceof JoinedWay) {
                                        ((JoinedWay) w).removeAllTagsDeep();
                                } else {
-                                       w.removeAllTags();
+                                       log.info("Before 
remove",w.toTagString());
+                                       for (Map.Entry<String, String> wayTag : 
w
+                                                       .getEntryIteratable()) {
+                                               w.deleteTag(wayTag.getKey());
+                                       }
+                                       log.info("After 
remove",w.toTagString());
                                }
                        }
                }
@@ -1762,7 +1792,7 @@
                        sb.append(getId());
                        sb.append("(");
                        sb.append(getPoints().size());
-                       sb.append("P : (");
+                       sb.append("P)(");
                        boolean first = true;
                        for (Way w : getOriginalWays()) {
                                if (first) {
_______________________________________________
mkgmap-dev mailing list
[email protected]
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev

Reply via email to