Ticket #20663: 20663-2.patch
| File 20663-2.patch, 9.3 KB (added by , 5 years ago) |
|---|
-
src/org/openstreetmap/josm/data/validation/tests/MultipolygonTest.java
56 56 public static final int INNER_WAY_OUTSIDE = 1605; 57 57 /** Intersection between multipolygon ways */ 58 58 public static final int CROSSING_WAYS = 1606; 59 /** Style for outer way mismatches / With the currently used mappaint style(s) the style for outer way mismatches the area style */ 60 public static final int OUTER_STYLE_MISMATCH = 1607; 59 // 1607 is no longer used: With the currently used mappaint style(s) the style for outer way mismatches the area style 61 60 /** With the currently used mappaint style the style for inner way equals the multipolygon style */ 62 61 public static final int INNER_STYLE_MISMATCH = 1608; 63 // no longer used: Area style way is not closed NOT_CLOSED = 160962 // 1609 is no longer used: Area style way is not closed 64 63 /** No area style for multipolygon */ 65 64 public static final int NO_STYLE = 1610; 66 // no longer used: Multipolygon relation should be tagged with area tags and not the outer way(s) NO_STYLE_POLYGON = 1611;65 // 1611 is no longer used: Multipolygon relation should be tagged with area tags and not the outer way(s) 67 66 /** Area style on outer way */ 68 67 public static final int OUTER_STYLE = 1613; 69 68 /** Multipolygon member repeated (same primitive, same role */ … … 125 124 * Various style-related checks:<ul> 126 125 * <li>{@link #NO_STYLE}: No area style for multipolygon</li> 127 126 * <li>{@link #INNER_STYLE_MISMATCH}: With the currently used mappaint style the style for inner way equals the multipolygon style</li> 128 * <li>{@link #OUTER_STYLE_MISMATCH}: With the currently used mappaint style the style for outer way mismatches the area style</li>129 127 * <li>{@link #OUTER_STYLE}: Area style on outer way</li> 130 128 * </ul> 131 129 * @param r relation … … 154 152 continue; 155 153 AreaElement areaOuter = ElemStyles.getAreaElemStyle(wOuter, false); 156 154 if (areaOuter != null) { 157 if (!area.equals(areaOuter)) { 158 errors.add(TestError.builder(this, Severity.OTHER, OUTER_STYLE_MISMATCH) 159 .message(tr("With the currently used mappaint style the style for outer way mismatches the area style")) 160 .primitives(Arrays.asList(r, wOuter)) 161 .highlight(wOuter) 162 .build()); 163 } else { /* style on outer way of multipolygon, but equal to polygon */ 164 errors.add(TestError.builder(this, Severity.WARNING, OUTER_STYLE) 165 .message(tr("Area style on outer way")) 166 .primitives(Arrays.asList(r, wOuter)) 167 .highlight(wOuter) 168 .build()); 169 } 155 errors.add(TestError.builder(this, Severity.WARNING, OUTER_STYLE) 156 .message(tr("Area style on outer way")) 157 .primitives(Arrays.asList(r, wOuter)) 158 .highlight(wOuter) 159 .build()); 170 160 } 171 161 } 172 162 } -
src/org/openstreetmap/josm/data/validation/tests/TagChecker.java
42 42 import org.openstreetmap.josm.data.osm.OsmPrimitive; 43 43 import org.openstreetmap.josm.data.osm.OsmUtils; 44 44 import org.openstreetmap.josm.data.osm.Relation; 45 import org.openstreetmap.josm.data.osm.RelationMember;46 45 import org.openstreetmap.josm.data.osm.Tag; 47 46 import org.openstreetmap.josm.data.osm.TagMap; 48 47 import org.openstreetmap.josm.data.osm.Tagged; 49 import org.openstreetmap.josm.data.osm.Way;50 48 import org.openstreetmap.josm.data.osm.visitor.MergeSourceBuildingVisitor; 51 49 import org.openstreetmap.josm.data.preferences.sources.ValidatorPrefHelper; 52 50 import org.openstreetmap.josm.data.validation.OsmValidator; … … 103 101 /** tag keys that have only numerical values in the presets */ 104 102 private static final Set<String> ignoreForLevenshtein = new HashSet<>(); 105 103 106 /** tag keys that are allowed to be the same on a multipolygon and an outer way */107 private static final Set<String> ignoreForOuterMPSameTagCheck = new HashSet<>();108 109 104 /** The preferences prefix */ 110 105 protected static final String PREFIX = ValidatorPrefHelper.PREFIX + "." + TagChecker.class.getSimpleName(); 111 106 … … 160 155 */ 161 156 public static final String PREF_CHECK_PRESETS_TYPES_BEFORE_UPLOAD = PREF_CHECK_PRESETS_TYPES + BEFORE_UPLOAD; 162 157 163 /**164 * The preference key for the list of tag keys that are allowed to be the same on a multipolygon and an outer way165 */166 public static final String PREF_KEYS_IGNORE_OUTER_MP_SAME_TAG = PREFIX + ".ignore-keys-outer-mp-same-tag";167 168 158 private static final int MAX_LEVENSHTEIN_DISTANCE = 2; 169 159 170 160 protected boolean includeOtherSeverity; … … 209 199 protected static final int MULTIPOLYGON_NO_AREA = 1218; 210 200 protected static final int MULTIPOLYGON_INCOMPLETE = 1219; 211 201 protected static final int MULTIPOLYGON_MAYBE_NO_AREA = 1220; 212 protected static final int MULTIPOLYGON_SAME_TAG_ON_OUTER = 1221;213 202 // CHECKSTYLE.ON: SingleSpaceSeparator 214 203 215 204 protected EditableList sourcesList; … … 264 253 ignoreForLevenshtein.clear(); 265 254 oftenUsedTags.clear(); 266 255 presetIndex.clear(); 267 ignoreForOuterMPSameTagCheck.clear();268 256 269 257 StringBuilder errorSources = new StringBuilder(); 270 258 for (String source : Config.getPref().getList(PREF_SOURCES, DEFAULT_SOURCES)) { … … 649 637 } 650 638 651 639 if (p instanceof Relation && p.hasTag("type", "multipolygon")) { 652 checkMultipolygonTags(p);640 checkMultipolygonTags(p); 653 641 } 654 642 655 643 if (checkPresetsTypes) { … … 694 682 .anyMatch(k -> k.matches("^(abandoned|construction|demolished|disused|planned|razed|removed|was).*"))) 695 683 return; 696 684 697 checkOuterWaysOfRelation((Relation) p);698 699 685 if (hasAcceptedPrimaryTagForMultipolygon(p)) 700 686 return; 701 687 TestError.Builder builder = null; … … 724 710 } 725 711 726 712 /** 727 * Check if an outer way of the relation has the same tag as the relation.728 * @param rel the relation729 */730 private void checkOuterWaysOfRelation(Relation rel) {731 for (Entry<String, String> tag : rel.getInterestingTags().entrySet()) {732 if (ignoreForOuterMPSameTagCheck.contains(tag.getKey()))733 continue;734 735 Set<Way> sameOuters = rel.getMembers().stream()736 .filter(rm -> rm.isWay() && rm.getWay().isArea() && "outer".equals(rm.getRole())737 && tag.getValue().equals(rm.getWay().get(tag.getKey())))738 .map(RelationMember::getWay).collect(Collectors.toSet());739 if (!sameOuters.isEmpty()) {740 List<OsmPrimitive> primitives = new ArrayList<>(sameOuters.size() + 1);741 primitives.add(rel);742 primitives.addAll(sameOuters);743 Way w = new Way();744 w.put(tag.getKey(), tag.getValue());745 if (hasAcceptedPrimaryTagForMultipolygon(w)) {746 errors.add(TestError.builder(this, Severity.WARNING, MULTIPOLYGON_SAME_TAG_ON_OUTER)747 .message(tr("Multipolygon outer way repeats major tag of relation"),748 marktr("Same tag:''{0}''=''{1}''"), tag.getKey(), tag.getValue())749 .primitives(primitives)750 .build());751 } else {752 errors.add(TestError.builder(this, Severity.OTHER, MULTIPOLYGON_SAME_TAG_ON_OUTER)753 .message(tr("Multipolygon outer way repeats tag of relation"),754 marktr("Same tag:''{0}''=''{1}''"), tag.getKey(), tag.getValue())755 .primitives(primitives)756 .build());757 }758 }759 }760 }761 762 /**763 713 * Check if a multipolygon has a main tag that describes the type of area. Accepts also some deprecated tags and typos. 764 714 * @param p the multipolygon 765 715 * @return true if the multipolygon has a main tag that (likely) describes the type of area. … … 1098 1048 checkPresetsTypes = checkPresetsTypes && Config.getPref().getBoolean(PREF_CHECK_PRESETS_TYPES_BEFORE_UPLOAD, true); 1099 1049 } 1100 1050 deprecatedChecker = OsmValidator.getTest(MapCSSTagChecker.class); 1101 ignoreForOuterMPSameTagCheck.addAll(Config.getPref().getList(PREF_KEYS_IGNORE_OUTER_MP_SAME_TAG, Collections.emptyList()));1102 1051 } 1103 1052 1104 1053 @Override
