Changeset 9539 in josm for trunk/src


Ignore:
Timestamp:
2016-01-19T13:28:25+01:00 (9 years ago)
Author:
simon04
Message:

fix #10290 - Improve ReverseWayNoTagCorrector

It evaluates its own directional tags together with those defined at
OsmPrimitive#directionKeys minus the ones that can be corrected using
ReverseWayTagCorrector.

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/corrector/ReverseWayNoTagCorrector.java

    r8919 r9539  
    66
    77import java.util.Arrays;
     8import java.util.Map;
    89
    910import javax.swing.JOptionPane;
    1011
    1112import org.openstreetmap.josm.Main;
     13import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1214import org.openstreetmap.josm.data.osm.Tag;
    1315import org.openstreetmap.josm.data.osm.TagCollection;
     16import org.openstreetmap.josm.data.osm.Tagged;
    1417import org.openstreetmap.josm.data.osm.Way;
    1518import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
     
    3437     * Tags that imply a semantic meaning from the way direction and cannot be changed.
    3538     */
    36     public static final TagCollection directionalTags = new TagCollection(Arrays.asList(new Tag[]{
     39    private static final TagCollection directionalTags = new TagCollection(Arrays.asList(new Tag[]{
    3740            new Tag("natural", "coastline"),
    3841            new Tag("natural", "cliff"),
     
    4144            new Tag("barrier", "retaining_wall"),
    4245            new Tag("man_made", "embankment"),
    43             new Tag("waterway", "stream"),
    44             new Tag("waterway", "river"),
    45             new Tag("waterway", "ditch"),
    46             new Tag("waterway", "drain"),
    47             new Tag("waterway", "canal")
    4846    }));
    4947
     
    5351     * @return tags that imply a semantic meaning from <code>way</code> direction and cannot be changed
    5452     */
    55     public static TagCollection getDirectionalTags(Way way) {
    56         return directionalTags.intersect(TagCollection.from(way));
     53    public static TagCollection getDirectionalTags(Tagged way) {
     54        final TagCollection collection = new TagCollection();
     55        for (Map.Entry<String, String> entry : way.getKeys().entrySet()) {
     56            final Tag tag = new Tag(entry.getKey(), entry.getValue());
     57            final boolean isDirectional = directionalTags.contains(tag) || OsmPrimitive.directionalKeyPredicate.evaluate(tag);
     58            if (isDirectional) {
     59                final boolean cannotBeCorrected = ReverseWayTagCorrector.getTagCorrections(tag).isEmpty();
     60                if (cannotBeCorrected) {
     61                    collection.add(tag);
     62                }
     63            }
     64        }
     65        return collection;
    5766    }
    5867
     
    6372     * @return false if the semantic meaning change if the way is reversed, true otherwise.
    6473     */
    65     public static boolean isReversible(Way way) {
     74    public static boolean isReversible(Tagged way) {
    6675        return getDirectionalTags(way).isEmpty();
    67     }
    68 
    69     protected static String getHTML(TagCollection tags) {
    70         if (tags.size() == 1) {
    71             return tags.iterator().next().toString();
    72         } else if (tags.size() > 1) {
    73             return Utils.joinAsHtmlUnorderedList(tags);
    74         } else {
    75             return "";
    76         }
    7776    }
    7877
     
    8988                tags.size(),
    9089                way.getDisplayName(DefaultNameFormatter.getInstance()),
    91                 getHTML(tags)
     90                Utils.joinAsHtmlUnorderedList(tags)
    9291            );
    9392        int ret = ConditionalOptionPaneUtil.showOptionDialog(
  • trunk/src/org/openstreetmap/josm/corrector/ReverseWayTagCorrector.java

    r8919 r9539  
    2020import org.openstreetmap.josm.data.osm.Tag;
    2121import org.openstreetmap.josm.data.osm.TagCollection;
     22import org.openstreetmap.josm.data.osm.Tagged;
    2223import org.openstreetmap.josm.data.osm.Way;
    2324import org.openstreetmap.josm.tools.UserCancelException;
     
    202203    }
    203204
    204     @Override
    205     public Collection<Command> execute(Way oldway, Way way) throws UserCancelException {
    206         Map<OsmPrimitive, List<TagCorrection>> tagCorrectionsMap = new HashMap<>();
    207 
     205    static List<TagCorrection> getTagCorrections(Tagged way) {
    208206        List<TagCorrection> tagCorrections = new ArrayList<>();
    209207        for (String key : way.keySet()) {
     
    225223            }
    226224        }
    227         if (!tagCorrections.isEmpty()) {
    228             tagCorrectionsMap.put(way, tagCorrections);
    229         }
    230 
    231         Map<OsmPrimitive, List<RoleCorrection>> roleCorrectionMap = new HashMap<>();
     225        return tagCorrections;
     226    }
     227
     228    static List<RoleCorrection> getRoleCorrections(Way oldway) {
    232229        List<RoleCorrection> roleCorrections = new ArrayList<>();
    233230
     
    263260            }
    264261        }
     262        return roleCorrections;
     263    }
     264
     265    @Override
     266    public Collection<Command> execute(Way oldway, Way way) throws UserCancelException {
     267        Map<OsmPrimitive, List<TagCorrection>> tagCorrectionsMap = new HashMap<>();
     268        List<TagCorrection> tagCorrections = getTagCorrections(way);
     269        if (!tagCorrections.isEmpty()) {
     270            tagCorrectionsMap.put(way, tagCorrections);
     271        }
     272
     273        Map<OsmPrimitive, List<RoleCorrection>> roleCorrectionMap = new HashMap<>();
     274        List<RoleCorrection> roleCorrections = getRoleCorrections(oldway);
    265275        if (!roleCorrections.isEmpty()) {
    266276            roleCorrectionMap.put(way, roleCorrections);
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r9538 r9539  
    238238        @Override public boolean evaluate(OsmPrimitive primitive) {
    239239            return true;
     240        }
     241    };
     242
     243    public static final Predicate<Tag> directionalKeyPredicate = new Predicate<Tag>() {
     244        @Override
     245        public boolean evaluate(Tag tag) {
     246            return directionKeys.match(tag);
    240247        }
    241248    };
     
    803810        String reversedDirectionDefault = "oneway=\"-1\"";
    804811
    805         String directionDefault = "oneway? | (aerialway=* aerialway!=station) | "+
     812        String directionDefault = "oneway? | (aerialway=* -aerialway=station) | "+
    806813                "waterway=stream | waterway=river | waterway=ditch | waterway=wadi | waterway=drain | "+
    807814                "\"piste:type\"=downhill | \"piste:type\"=sled | man_made=\"piste:halfpipe\" | "+
Note: See TracChangeset for help on using the changeset viewer.