Ticket #17010: 17010-v1.patch
File 17010-v1.patch, 6.5 KB (added by , 6 years ago) |
---|
-
src/org/openstreetmap/josm/data/validation/tests/MultipolygonTest.java
53 53 public static final int WRONG_MEMBER_ROLE = 1602; 54 54 /** Multipolygon is not closed */ 55 55 public static final int NON_CLOSED_WAY = 1603; 56 /** No outer way for multipolygon */57 public static final int MISSING_OUTER_WAY = 1604;58 56 /** Multipolygon inner way is outside */ 59 57 public static final int INNER_WAY_OUTSIDE = 1605; 60 58 /** Intersection between multipolygon ways */ … … 132 130 @Override 133 131 public void visit(Relation r) { 134 132 if (r.isMultipolygon() && r.getMembersCount() > 0) { 135 checkMembersAndRoles(r);136 checkOuterWay(r);137 133 boolean hasRepeatedMembers = checkRepeatedWayMembers(r); 134 boolean simpleCheck = true; 138 135 // Rest of checks is only for complete multipolygon 139 136 if (!hasRepeatedMembers && !r.hasIncompleteMembers()) { 140 137 Multipolygon polygon = new Multipolygon(r); 141 138 checkStyleConsistency(r, polygon); 142 139 checkGeometryAndRoles(r, polygon); 140 simpleCheck = false; 143 141 } 142 checkMembersAndRoles(r, simpleCheck); 144 143 } 145 144 } 146 145 147 146 /** 148 * Checks that multipolygon has at least an outer way:<ul>149 * <li>{@link #MISSING_OUTER_WAY}: No outer way for multipolygon</li>150 * </ul>151 * @param r relation152 */153 private void checkOuterWay(Relation r) {154 for (RelationMember m : r.getMembers()) {155 if (m.isWay() && "outer".equals(m.getRole())) {156 return;157 }158 }159 errors.add(TestError.builder(this, Severity.WARNING, MISSING_OUTER_WAY)160 .message(r.isBoundary() ? tr("No outer way for boundary") : tr("No outer way for multipolygon"))161 .primitives(r)162 .build());163 }164 165 /**166 147 * Various style-related checks:<ul> 167 148 * <li>{@link #NO_STYLE_POLYGON}: Multipolygon relation should be tagged with area tags and not the outer way</li> 168 149 * <li>{@link #INNER_STYLE_MISMATCH}: With the currently used mappaint style the style for inner way equals the multipolygon style</li> … … 704 685 * <li>{@link #WRONG_MEMBER_TYPE}: Non-Way in multipolygon</li> 705 686 * </ul> 706 687 * @param r relation 688 * @param simpleCheck if true test also roles of way members 707 689 */ 708 private void checkMembersAndRoles(Relation r ) {690 private void checkMembersAndRoles(Relation r, boolean simpleCheck) { 709 691 for (RelationMember rm : r.getMembers()) { 710 692 if (rm.isWay()) { 711 if ( !(rm.hasRole("inner", "outer") || !rm.hasRole())) {712 errors.add(TestError.builder(this, Severity. WARNING, WRONG_MEMBER_ROLE)693 if (simpleCheck && (!(rm.hasRole("inner", "outer")) || !rm.hasRole())) { 694 errors.add(TestError.builder(this, Severity.ERROR, WRONG_MEMBER_ROLE) 713 695 .message(tr("No useful role for multipolygon member")) 714 696 .primitives(Arrays.asList(r, rm.getMember())) 715 697 .build()); … … 748 730 boolean hasDups = false; 749 731 Map<OsmPrimitive, List<RelationMember>> seenMemberPrimitives = new HashMap<>(); 750 732 for (RelationMember rm : r.getMembers()) { 733 if (!rm.isWay()) 734 continue; 751 735 List<RelationMember> list = seenMemberPrimitives.get(rm.getMember()); 752 736 if (list == null) { 753 737 list = new ArrayList<>(2); -
src/org/openstreetmap/josm/data/validation/tests/RelationChecker.java
18 18 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 19 19 import org.openstreetmap.josm.data.osm.Relation; 20 20 import org.openstreetmap.josm.data.osm.RelationMember; 21 import org.openstreetmap.josm.data.validation.OsmValidator; 21 22 import org.openstreetmap.josm.data.validation.Severity; 22 23 import org.openstreetmap.josm.data.validation.Test; 23 24 import org.openstreetmap.josm.data.validation.TestError; 25 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 24 26 import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset; 25 27 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItem; 26 28 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetType; … … 60 62 * @since 6731 61 63 */ 62 64 public static final String ROLE_VERIF_PROBLEM_MSG = tr("Role verification problem"); 65 private boolean ignoreMultiPolygons; 63 66 64 67 /** 65 68 * Constructor … … 99 102 } 100 103 101 104 @Override 105 public void startTest(ProgressMonitor progressMonitor) { 106 super.startTest(progressMonitor); 107 108 for (Test t : OsmValidator.getEnabledTests(false)) { 109 if (t instanceof MultipolygonTest) { 110 ignoreMultiPolygons = true; 111 break; 112 } 113 } 114 } 115 116 @Override 102 117 public void visit(Relation n) { 118 Map<String, RoleInfo> map = buildRoleInfoMap(n); 119 if (map.isEmpty()) { 120 errors.add(TestError.builder(this, Severity.ERROR, RELATION_EMPTY) 121 .message(tr("Relation is empty")) 122 .primitives(n) 123 .build()); 124 } 125 if (ignoreMultiPolygons && n.isMultipolygon()) { 126 // see #17010: don't report same problem twice 127 return; 128 } 103 129 Map<Role, String> allroles = buildAllRoles(n); 104 130 if (allroles.isEmpty() && n.hasTag("type", "route") 105 131 && n.hasTag("route", "train", "subway", "monorail", "tram", "bus", "trolleybus", "aerialway", "ferry")) { … … 114 140 .build()); 115 141 } 116 142 117 Map<String, RoleInfo> map = buildRoleInfoMap(n); 118 if (map.isEmpty()) { 119 errors.add(TestError.builder(this, Severity.ERROR, RELATION_EMPTY) 120 .message(tr("Relation is empty")) 121 .primitives(n) 122 .build()); 123 } else if (!allroles.isEmpty()) { 143 if (!map.isEmpty() && !allroles.isEmpty()) { 124 144 checkRoles(n, allroles, map); 125 145 } 126 146 }