Ticket #19136: 19136.5.patch
| File 19136.5.patch, 9.8 KB (added by , 6 years ago) |
|---|
-
src/org/openstreetmap/josm/data/validation/tests/MultipolygonTest.java
120 120 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> 127 128 * @param r relation … … 128 129 * @param polygon multipolygon 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")) 156 144 .primitives(Arrays.asList(r, wInner)) … … 159 147 } 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")) 175 163 .primitives(Arrays.asList(r, wOuter)) -
src/org/openstreetmap/josm/data/validation/tests/TagChecker.java
38 38 import org.openstreetmap.josm.command.SequenceCommand; 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; 43 45 import org.openstreetmap.josm.data.osm.Tagged; … … 188 190 protected static final int MISSPELLED_VALUE_NO_FIX = 1215; 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_NO_TAG = 1220; 191 196 // CHECKSTYLE.ON: SingleSpaceSeparator 192 197 193 198 protected EditableList sourcesList; … … 622 627 } 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(); 627 636 TaggingPresetType presetType = TaggingPresetType.forPrimitive(p); … … 659 668 } 660 669 } 661 670 671 private void checkMultipolygonTags(OsmPrimitive p) { 672 if (p.isAnnotated() || hasAcceptedPrimaryTagForMultipolygon(p)) 673 return; 674 Map<String, String> filteredTags = p.getInterestingTags(); 675 TestError.Builder builder = null; 676 if (filteredTags.size() == 1) { 677 builder = TestError.builder(this, Severity.ERROR, MULTIPOLYGON_NO_TAG) 678 .message(tr("multipolygon relation: no further tags")); 679 } 680 if (filteredTags.size() == 2) { 681 if (filteredTags.containsKey("name")) { 682 builder = TestError.builder(this, Severity.ERROR, MULTIPOLYGON_INCOMPLETE) 683 .message(tr("multipolygon relation: only {0} tag", "name")); 684 } 685 if (filteredTags.containsKey("area")) { 686 builder = TestError.builder(this, Severity.WARNING, MULTIPOLYGON_INCOMPLETE) 687 .message(tr("multipolygon relation: only {0} tag", "area")); 688 689 } 690 } 691 if (builder == null && filteredTags.containsKey("surface")) { 692 builder = TestError.builder(this, Severity.OTHER, MULTIPOLYGON_INCOMPLETE) 693 .message(tr("multipolygon relation: only {0} tag", "surface")); 694 } 695 if (builder == null) { 696 builder = TestError.builder(this, Severity.WARNING, MULTIPOLYGON_NO_AREA) 697 .message(tr("multipolygon relation: found no area type tag")); 698 } 699 errors.add(builder.primitives(p).build()); 700 } 701 702 /** 703 * Check if a multipolygon has a main tag that describes the type of area. Accepts also some deprecated tags and typos. 704 * @param p the multipolygon 705 * @return true if the multipolygon has a main tag that (likely) describes the type of area. 706 */ 707 private static boolean hasAcceptedPrimaryTagForMultipolygon(OsmPrimitive p) { 708 return p.hasKey("landuse", "amenity", "building", "building:part", "area:highway", "shop", "place", "landform", 709 "piste:type", "sport", "golf", "landcover", "aeroway", "office", "healthcare", "disused:amenity", 710 "disused:landuse", "disused:building", "disused:leisure") 711 || p.hasTagDifferent("natural", "tree", "peek", "saddle", "tree_row") 712 || p.hasTagDifferent("man_made", "survey_point", "mast", "flagpole", "manhole", "watertap") 713 || p.hasTag("highway", "pedestrian", "services", "rest_area", "platform", "footway") 714 || (p.hasTag("highway", "residential", "footway") && p.hasTag("area", OsmUtils.TRUE_VALUE)) // alternative to place=square 715 || p.hasTag("barrier", "hedge", "retaining_wall") 716 || p.hasTag("boundary", "national_park", "protected_area") 717 || p.hasTag("public_transport", "platform", "station") 718 || p.hasTag("railway", "platform") 719 || p.hasTag("waterway", "riverbank") 720 || p.hasTagDifferent("tourism", "attraction", "artwork") 721 || p.hasTagDifferent("leisure", "picnic_table", "slipway", "firepit") 722 || p.hasTag("indoor", "corridor", "room", "area") 723 || p.hasTag("power", "substation", "generator", "plant", "switchgear", "converter", "sub_station") 724 || p.hasTagDifferent("historic", "wayside_cross", "milestone") 725 || p.hasTag("seamark:type", "harbour", "fairway", "anchorage", "landmark", "berth", "harbour_basin", 726 "separation_zone") 727 || (p.get("seamark:type") != null && p.get("seamark:type").matches(".*\\_(area|zone)$")) 728 || p.hasTag("junction", "yes"); 729 730 } 731 662 732 private void checkSingleTagValueSimple(MultiMap<OsmPrimitive, String> withErrors, OsmPrimitive p, String s, String key, String value) { 663 733 if (!checkValues || value == null) 664 734 return;
