Ticket #19136: 19136.4.patch
File 19136.4.patch, 8.3 KB (added by , 4 years ago) |
---|
-
src/org/openstreetmap/josm/data/validation/tests/MultipolygonTest.java
73 73 public static final int RINGS_SHARE_NODES = 1617; 74 74 /** Incomplete multipolygon was modified */ 75 75 public static final int MODIFIED_INCOMPLETE = 1618; 76 /** No further tags for multipolygon */ 77 public static final int NO_TAGS = 1619; 78 /** No area tag for multipolygon */ 79 public static final int NO_AREA_TAG = 1620; 76 80 77 81 private static final int FOUND_INSIDE = 1; 78 82 private static final int FOUND_OUTSIDE = 2; … … 93 97 @Override 94 98 public void visit(Relation r) { 95 99 if (r.isMultipolygon() && !r.isEmpty()) { 100 tagTest(r); 96 101 List<TestError> tmpErrors = new ArrayList<>(30); 97 102 boolean hasUnexpectedWayRoles = checkMembersAndRoles(r, tmpErrors); 98 103 boolean hasRepeatedMembers = checkRepeatedWayMembers(r); … … 119 124 } 120 125 121 126 /** 127 * Check if there is any useful tag on a multipolygon relation. 128 * @param r relation 129 */ 130 private void tagTest(Relation r) { 131 if (!r.isBoundary()) { 132 if (r.getInterestingTags().size() <= 1) { 133 errors.add(TestError.builder(this, Severity.ERROR, NO_TAGS) 134 .message(tr("No further tags for multipolygon")) 135 .primitives(r) 136 .build()); 137 } else if (!r.concernsArea()) { 138 errors.add(TestError.builder(this, Severity.WARNING, NO_AREA_TAG) 139 .message(tr("No area tag for multipolygon")) 140 .primitives(r) 141 .build()); 142 } 143 } 144 } 145 146 /** 122 147 * Various style-related checks:<ul> 148 * <li>{@link #NO_STYLE}: No area style for multipolygon</li> 123 149 * <li>{@link #INNER_STYLE_MISMATCH}: With the currently used mappaint style the style for inner way equals the multipolygon style</li> 124 * <li>{@link #OUTER_STYLE_MISMATCH}: Style for outer way mismatches</li>150 * <li>{@link #OUTER_STYLE_MISMATCH}: With the currently used mappaint style the style for outer way mismatches the area style</li> 125 151 * <li>{@link #OUTER_STYLE}: Area style on outer way</li> 126 152 * </ul> 127 153 * @param r relation … … 128 154 * @param polygon multipolygon 129 155 */ 130 156 private void checkStyleConsistency(Relation r, Multipolygon polygon) { 131 ElemStyles styles = MapPaintStyles.getStyles(); 132 if (styles != null && !r.isBoundary()) { 157 if (MapPaintStyles.getStyles() != null && !r.isBoundary()) { 133 158 AreaElement area = ElemStyles.getAreaElemStyle(r, false); 134 boolean areaStyle = area != null;135 // If area style was not found for relation then use style of ways136 159 if (area == null) { 137 for (Way w : polygon.getOuterWays()) { 138 area = ElemStyles.getAreaElemStyle(w, true); 139 if (area != null) { 140 break; 141 } 142 } 143 if (area == null) { 144 errors.add(TestError.builder(this, Severity.OTHER, NO_STYLE) 145 .message(tr("No area style for multipolygon")) 146 .primitives(r) 147 .build()); 148 } 149 } 150 151 if (area != null) { 160 errors.add(TestError.builder(this, Severity.OTHER, NO_STYLE) 161 .message(tr("No area style for multipolygon")) 162 .primitives(r) 163 .build()); 164 } else { 152 165 for (Way wInner : polygon.getInnerWays()) { 153 if ( area.equals(ElemStyles.getAreaElemStyle(wInner, false))) {166 if (wInner.isClosed() && area.equals(ElemStyles.getAreaElemStyle(wInner, false))) { 154 167 errors.add(TestError.builder(this, Severity.OTHER, INNER_STYLE_MISMATCH) 155 168 .message(tr("With the currently used mappaint style the style for inner way equals the multipolygon style")) 156 169 .primitives(Arrays.asList(r, wInner)) … … 159 172 } 160 173 } 161 174 for (Way wOuter : polygon.getOuterWays()) { 175 if (!wOuter.isArea()) 176 continue; 162 177 AreaElement areaOuter = ElemStyles.getAreaElemStyle(wOuter, false); 163 178 if (areaOuter != null) { 164 179 if (!area.equals(areaOuter)) { 165 String message = !areaStyle ? tr("Style for outer way mismatches")166 : tr("With the currently used mappaint style the style for outer way mismatches the area style");167 180 errors.add(TestError.builder(this, Severity.OTHER, OUTER_STYLE_MISMATCH) 168 .message( message)181 .message(tr("With the currently used mappaint style the style for outer way mismatches the area style")) 169 182 .primitives(Arrays.asList(r, wOuter)) 170 183 .highlight(wOuter) 171 184 .build()); 172 } else if (areaStyle){ /* style on outer way of multipolygon, but equal to polygon */185 } else { /* style on outer way of multipolygon, but equal to polygon */ 173 186 errors.add(TestError.builder(this, Severity.WARNING, OUTER_STYLE) 174 187 .message(tr("Area style on outer way")) 175 188 .primitives(Arrays.asList(r, wOuter)) … … 913 926 boolean hasRepeatedMembers = checkRepeatedWayMembers(r); 914 927 if (!hasRepeatedMembers) { 915 928 polygon = new Multipolygon(r); 916 // don't check style consistency here929 // don't check style tags or consistency here 917 930 checkGeometryAndRoles(r, polygon); 918 931 } 919 932 createdRelation = null; // makes sure that repeatCheck is only set once -
src/org/openstreetmap/josm/data/validation/tests/UnclosedWays.java
9 9 import java.util.HashSet; 10 10 import java.util.Set; 11 11 12 import org.openstreetmap.josm.data.osm.OsmPrimitive;13 12 import org.openstreetmap.josm.data.osm.OsmUtils; 14 import org.openstreetmap.josm.data.osm.Relation;15 13 import org.openstreetmap.josm.data.osm.Way; 16 14 import org.openstreetmap.josm.data.validation.Severity; 17 15 import org.openstreetmap.josm.data.validation.Test; … … 179 177 if (!w.isUsable() || w.isArea()) 180 178 return; 181 179 182 for (OsmPrimitive parent: w.getReferrers()) {183 if (parent instanceof Relation && ((Relation) parent).isMultipolygon())184 return;185 }186 187 180 for (UnclosedWaysCheck c : checks) { 188 181 TestError error = c.getTestError(w, this); 189 182 if (error != null) { -
test/unit/org/openstreetmap/josm/data/validation/tests/UnclosedWaysTest.java
78 78 } 79 79 80 80 /** 81 * Test to make sure the multipolygon ways are ignored 81 * Test to make sure the multipolygon ways are not ignored 82 * See #19136 82 83 * @throws Exception if an exception occurs 83 84 */ 84 85 @Test … … 95 96 ds.addPrimitive(r); 96 97 uwTest.visit(w); 97 98 assertTrue(ElemStyles.hasAreaElemStyle(w, false)); 98 assertEquals( 0, uwTest.getErrors().size());99 assertEquals(1, uwTest.getErrors().size()); 99 100 100 101 uwTest.endTest(); 101 102 }