Changeset 16406 in josm for trunk/src/org
- Timestamp:
- 2020-05-13T15:14:41+02:00 (4 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data/validation/tests
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/MultipolygonTest.java
r16333 r16406 121 121 /** 122 122 * Various style-related checks:<ul> 123 * <li>{@link #NO_STYLE}: No area style for multipolygon</li> 123 124 * <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>125 * <li>{@link #OUTER_STYLE_MISMATCH}: With the currently used mappaint style the style for outer way mismatches the area style</li> 125 126 * <li>{@link #OUTER_STYLE}: Area style on outer way</li> 126 127 * </ul> … … 129 130 */ 130 131 private void checkStyleConsistency(Relation r, Multipolygon polygon) { 131 ElemStyles styles = MapPaintStyles.getStyles(); 132 if (styles != null && !r.isBoundary()) { 132 if (MapPaintStyles.getStyles() != null && !r.isBoundary()) { 133 133 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 134 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) { 135 errors.add(TestError.builder(this, Severity.OTHER, NO_STYLE) 136 .message(tr("No area style for multipolygon")) 137 .primitives(r) 138 .build()); 139 } else { 152 140 for (Way wInner : polygon.getInnerWays()) { 153 if ( area.equals(ElemStyles.getAreaElemStyle(wInner, false))) {141 if (wInner.isClosed() && area.equals(ElemStyles.getAreaElemStyle(wInner, false))) { 154 142 errors.add(TestError.builder(this, Severity.OTHER, INNER_STYLE_MISMATCH) 155 143 .message(tr("With the currently used mappaint style the style for inner way equals the multipolygon style")) … … 160 148 } 161 149 for (Way wOuter : polygon.getOuterWays()) { 150 if (!wOuter.isArea()) 151 continue; 162 152 AreaElement areaOuter = ElemStyles.getAreaElemStyle(wOuter, false); 163 153 if (areaOuter != null) { 164 154 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 155 errors.add(TestError.builder(this, Severity.OTHER, OUTER_STYLE_MISMATCH) 168 .message( message)156 .message(tr("With the currently used mappaint style the style for outer way mismatches the area style")) 169 157 .primitives(Arrays.asList(r, wOuter)) 170 158 .highlight(wOuter) 171 159 .build()); 172 } else if (areaStyle){ /* style on outer way of multipolygon, but equal to polygon */160 } else { /* style on outer way of multipolygon, but equal to polygon */ 173 161 errors.add(TestError.builder(this, Severity.WARNING, OUTER_STYLE) 174 162 .message(tr("Area style on outer way")) -
trunk/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java
r16332 r16406 39 39 import org.openstreetmap.josm.data.osm.AbstractPrimitive; 40 40 import org.openstreetmap.josm.data.osm.OsmPrimitive; 41 import org.openstreetmap.josm.data.osm.OsmUtils; 42 import org.openstreetmap.josm.data.osm.Relation; 41 43 import org.openstreetmap.josm.data.osm.Tag; 42 44 import org.openstreetmap.josm.data.osm.TagMap; … … 189 191 protected static final int UNUSUAL_UNICODE_CHAR_VALUE = 1216; 190 192 protected static final int INVALID_PRESETS_TYPE = 1217; 193 protected static final int MULTIPOLYGON_NO_AREA = 1218; 194 protected static final int MULTIPOLYGON_INCOMPLETE = 1219; 195 protected static final int MULTIPOLYGON_MAYBE_NO_AREA = 1220; 191 196 // CHECKSTYLE.ON: SingleSpaceSeparator 192 197 … … 623 628 } 624 629 630 if (p instanceof Relation && p.hasTag("type", "multipolygon")) { 631 checkMultipolygonTags(p); 632 } 633 625 634 if (checkPresetsTypes) { 626 635 TagMap tags = p.getKeys(); … … 658 667 } 659 668 } 669 } 670 671 private static final Collection<String> NO_AREA_KEYS = Arrays.asList("name", "area", "ref", "access", "operator"); 672 673 private void checkMultipolygonTags(OsmPrimitive p) { 674 if (p.isAnnotated() || hasAcceptedPrimaryTagForMultipolygon(p)) 675 return; 676 if (p.keySet().stream().anyMatch(k -> k.matches("^(abandoned|construction|demolished|disused|planned|razed|removed|was).*"))) 677 return; 678 679 TestError.Builder builder = null; 680 if (p.hasKey("surface")) { 681 // accept often used tag surface=* as area tag 682 builder = TestError.builder(this, Severity.OTHER, MULTIPOLYGON_INCOMPLETE) 683 .message(tr("Multipolygon tags"), marktr("only {0} tag"), "surface"); 684 } else { 685 Map<String, String> filteredTags = p.getInterestingTags(); 686 filteredTags.remove("type"); 687 NO_AREA_KEYS.forEach(filteredTags::remove); 688 filteredTags.keySet().removeIf(key -> !key.matches("[a-z0-9:_]+")); 689 690 if (filteredTags.isEmpty()) { 691 builder = TestError.builder(this, Severity.ERROR, MULTIPOLYGON_NO_AREA) 692 .message(tr("Multipolygon tags"), marktr("tag describing the area is missing"), new Object()); 693 694 } 695 } 696 if (builder == null) { 697 // multipolygon has either no area tag or a rarely used one 698 builder = TestError.builder(this, Severity.WARNING, MULTIPOLYGON_MAYBE_NO_AREA) 699 .message(tr("Multipolygon tags"), marktr("tag describing the area might be missing"), new Object()); 700 } 701 errors.add(builder.primitives(p).build()); 702 } 703 704 /** 705 * Check if a multipolygon has a main tag that describes the type of area. Accepts also some deprecated tags and typos. 706 * @param p the multipolygon 707 * @return true if the multipolygon has a main tag that (likely) describes the type of area. 708 */ 709 private static boolean hasAcceptedPrimaryTagForMultipolygon(OsmPrimitive p) { 710 if (p.hasKey("landuse", "amenity", "building", "building:part", "area:highway", "shop", "place", "boundary", 711 "landform", "piste:type", "sport", "golf", "landcover", "aeroway", "office", "healthcare", "craft", "room") 712 || p.hasTagDifferent("natural", "tree", "peek", "saddle", "tree_row") 713 || p.hasTagDifferent("man_made", "survey_point", "mast", "flagpole", "manhole", "watertap") 714 || p.hasTagDifferent("highway", "crossing", "bus_stop", "turning_circle", "street_lamp", 715 "traffic_signals", "stop", "milestone", "mini_roundabout", "motorway_junction", "passing_place", 716 "speed_camera", "traffic_mirror", "trailhead", "turning_circle", "turning_loop", "toll_gantry") 717 || p.hasTagDifferent("tourism", "attraction", "artwork") 718 || p.hasTagDifferent("leisure", "picnic_table", "slipway", "firepit") 719 || p.hasTagDifferent("historic", "wayside_cross", "milestone")) 720 return true; 721 if (p.hasTag("barrier", "hedge", "retaining_wall") 722 || p.hasTag("public_transport", "platform", "station") 723 || p.hasTag("railway", "platform") 724 || p.hasTag("waterway", "riverbank", "dam", "rapids", "dock", "boatyard", "fuel") 725 || p.hasTag("indoor", "corridor", "room", "area") 726 || p.hasTag("power", "substation", "generator", "plant", "switchgear", "converter", "sub_station") 727 || p.hasTag("seamark:type", "harbour", "fairway", "anchorage", "landmark", "berth", "harbour_basin", 728 "separation_zone") 729 || (p.get("seamark:type") != null && p.get("seamark:type").matches(".*\\_(area|zone)$"))) 730 return true; 731 return p.hasTag("harbour", OsmUtils.TRUE_VALUE) 732 || p.hasTag("flood_prone", OsmUtils.TRUE_VALUE) 733 || p.hasTag("bridge", OsmUtils.TRUE_VALUE) 734 || p.hasTag("ruins", OsmUtils.TRUE_VALUE) 735 || p.hasTag("junction", OsmUtils.TRUE_VALUE); 660 736 } 661 737
Note:
See TracChangeset
for help on using the changeset viewer.