Changeset 18194 in osm for applications/editors


Ignore:
Timestamp:
2009-10-17T15:37:04+02:00 (15 years ago)
Author:
stoecker
Message:

fix josm 3677 - patch by Daeron - rework coastline checks

Location:
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/Coastlines.java

    r17722 r18194  
    66import java.util.*;
    77
     8import org.openstreetmap.josm.command.ChangeCommand;
     9import org.openstreetmap.josm.command.Command;
    810import org.openstreetmap.josm.data.osm.OsmPrimitive;
     11import org.openstreetmap.josm.data.osm.Node;
    912import org.openstreetmap.josm.data.osm.Way;
    10 import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    1113import org.openstreetmap.josm.plugins.validator.Severity;
    1214import org.openstreetmap.josm.plugins.validator.Test;
    1315import org.openstreetmap.josm.plugins.validator.TestError;
    14 import org.openstreetmap.josm.plugins.validator.util.Bag;
    15 import org.openstreetmap.josm.plugins.validator.util.Util;
    1616
    1717/**
     
    2222public class Coastlines extends Test
    2323{
    24     protected static int UNORDERED_COASTLINES = 901;
     24    protected static int UNORDERED_COASTLINE = 901;
     25    protected static int REVERSED_COASTLINE = 902;
     26    protected static int UNCONNECTED_COASTLINE = 903;
    2527
    26     /** All ways, grouped by cells */
    27     Map<Point2D,List<Way>> _cellWays;
    28     /** The already detected errors */
    29     Bag<Way, Way> _errorWays;
    30 
     28    private boolean fixable = false;
     29   
    3130    /**
    3231     * Constructor
     
    3938
    4039    @Override
    41     public void startTest(ProgressMonitor monitor)
     40    public void visit(Way w)
    4241    {
    43         super.startTest(monitor);
    44         _cellWays = new HashMap<Point2D,List<Way>>(1000);
    45         _errorWays = new Bag<Way, Way>();
     42        if(!w.isUsable() || w.isClosed())
     43            return;
     44
     45        String natural = w.get("natural");
     46        if(natural == null || !natural.equals("coastline"))
     47            return;
     48
     49        Node f = w.firstNode();
     50        Node l = w.lastNode();
     51        Way prev = null;
     52        Way next = null;
     53
     54        for (OsmPrimitive parent: this.backreferenceDataSet.getParents(f)) {
     55            natural = parent.get("natural");
     56            if (parent instanceof Way && !w.equals(parent) && (natural != null && "coastline".equals(natural))) {
     57                prev = (Way)parent;
     58                break;
     59            }
     60        }
     61        for (OsmPrimitive parent: this.backreferenceDataSet.getParents(l)) {
     62            natural = parent.get("natural");
     63            if (parent instanceof Way && !w.equals(parent) && (natural != null && "coastline".equals(natural))) {
     64                next = (Way)parent;
     65                break;
     66            }
     67        }
     68
     69        List<OsmPrimitive> primitives = new ArrayList<OsmPrimitive>();
     70        List<OsmPrimitive> highlight = new ArrayList<OsmPrimitive>();
     71        primitives.add(w);
     72
     73        if (prev == null || next == null) {
     74            if (prev == null)
     75                highlight.add(f);
     76            if (next == null)
     77                highlight.add(l);
     78
     79            errors.add(new TestError(this, Severity.ERROR, tr("Unconnected coastline"),
     80                                     UNCONNECTED_COASTLINE, primitives, highlight));
     81        }
     82
     83        boolean fuo = (prev != null && !f.equals(prev.lastNode()));
     84        boolean luo = (next != null && !l.equals(next.firstNode()));
     85
     86        if (fuo || luo) {
     87            if (fuo && luo) {
     88                errors.add(new TestError(this, Severity.ERROR, tr("Reversed coastline"),
     89                                         REVERSED_COASTLINE, primitives));
     90
     91            } else {
     92                if (fuo)
     93                    highlight.add(f);
     94                if (luo)
     95                    highlight.add(l);
     96
     97                errors.add(new TestError(this, Severity.ERROR, tr("Unordered coastline"),
     98                                         UNORDERED_COASTLINE, primitives, highlight));
     99            }
     100        }
    46101    }
    47102
    48103    @Override
    49     public void endTest()
    50     {
    51         super.endTest();
    52         _cellWays = null;
    53         _errorWays = null;
     104    public Command fixError(TestError testError) {
     105        if (isFixable(testError)) {
     106            Way w = (Way) testError.getPrimitives().iterator().next();
     107            Way wnew = new Way(w);
     108
     109            List<Node> nodesCopy = wnew.getNodes();
     110            Collections.reverse(nodesCopy);
     111            wnew.setNodes(nodesCopy);
     112
     113            return new ChangeCommand(w, wnew);
     114        }
     115
     116        return null;
    54117    }
    55118
    56119    @Override
    57     public void visit(Way w)
    58     {
    59         if( !w.isUsable() )
    60             return;
     120    public boolean isFixable(TestError testError) {
     121        if (testError.getTester() instanceof Coastlines) {
     122            return (testError.getCode() == REVERSED_COASTLINE);
     123        }
    61124
    62         String natural = w.get("natural");
    63         if( natural == null || !natural.equals("coastline") )
    64             return;
    65 
    66         List<List<Way>> cellWays = Util.getWaysInCell(w, _cellWays);
    67         for( List<Way> ways : cellWays)
    68         {
    69             for( Way w2 : ways)
    70             {
    71                 if( _errorWays.contains(w, w2) || _errorWays.contains(w2, w) )
    72                     continue;
    73 
    74                 String natural2 = w.get("natural");
    75                 if( natural2 == null || !natural2.equals("coastline") )
    76                     continue;
    77 
    78                 if( w.getNodes().get(0).equals(w2.getNodes().get(0)) || w.getNodes().get(w.getNodesCount() - 1).equals(w2.getNodes().get(w2.getNodesCount() - 1)))
    79                 {
    80                     List<OsmPrimitive> primitives = new ArrayList<OsmPrimitive>();
    81                     primitives.add(w);
    82                     primitives.add(w2);
    83                     errors.add( new TestError(this, Severity.ERROR, tr("Unordered coastline"), UNORDERED_COASTLINES, primitives) );
    84                     _errorWays.add(w, w2);
    85                 }
    86             }
    87             ways.add(w);
    88         }
     125        return false;
    89126    }
    90127}
  • applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/UnclosedWays.java

    r18088 r18194  
    5050    private String etype;
    5151    private int mode;
    52     private boolean force;
    5352
    54     public void set(boolean f, int m, String text, String desc) {
     53    public void set(int m, String text, String desc) {
    5554        etype = MessageFormat.format(text, desc);
    5655        type = tr(text, tr(desc));
    5756        mode = m;
    58         force = f;
    5957    }
    6058
    61     public void set(boolean f, int m, String text) {
     59    public void set(int m, String text) {
    6260        etype = text;
    6361        type = tr(text);
    6462        mode = m;
    65         force = f;
    6663    }
    6764
     
    6966    public void visit(Way w) {
    7067        String test;
    71         force = false; /* force even if end-to-end distance is long */
    7268        type = etype = null;
    7369        mode = 0;
     
    7773
    7874        test = w.get("natural");
    79         if (test != null)
    80             set(!"coastline".equals(test), 1101, marktr("natural type {0}"), test);
     75        if (test != null && !"coastline".equals(test))
     76            set(1101, marktr("natural type {0}"), test);
    8177        test = w.get("landuse");
    8278        if (test != null)
    83             set(true, 1102, marktr("landuse type {0}"), test);
     79            set(1102, marktr("landuse type {0}"), test);
    8480        test = w.get("amenities");
    8581        if (test != null)
    86             set(true, 1103, marktr("amenities type {0}"), test);
     82            set(1103, marktr("amenities type {0}"), test);
    8783        test = w.get("sport");
    8884        if (test != null && !test.equals("water_slide"))
    89             set(true, 1104, marktr("sport type {0}"), test);
     85            set(1104, marktr("sport type {0}"), test);
    9086        test = w.get("tourism");
    9187        if (test != null)
    92             set(true, 1105, marktr("tourism type {0}"), test);
     88            set(1105, marktr("tourism type {0}"), test);
    9389        test = w.get("shop");
    9490        if (test != null)
    95             set(true, 1106, marktr("shop type {0}"), test);
     91            set(1106, marktr("shop type {0}"), test);
    9692        test = w.get("leisure");
    9793        if (test != null)
    98             set(true, 1107, marktr("leisure type {0}"), test);
     94            set(1107, marktr("leisure type {0}"), test);
    9995        test = w.get("waterway");
    10096        if (test != null && test.equals("riverbank"))
    101             set(true, 1108, marktr("waterway type {0}"), test);
     97            set(1108, marktr("waterway type {0}"), test);
    10298        Boolean btest = OsmUtils.getOsmBoolean(w.get("building"));
    10399        if (btest != null && btest)
    104             set(true, 1120, marktr("building"));
     100            set(1120, marktr("building"));
    105101        btest = OsmUtils.getOsmBoolean(w.get("area"));
    106102        if (btest != null && btest)
    107             set(true, 1130, marktr("area"));
     103            set(1130, marktr("area"));
    108104
    109         if (type != null && !w.isClosed())
    110         {
     105        if (type != null && !w.isClosed()) {
    111106            for (OsmPrimitive parent: this.backreferenceDataSet.getParents(w)) {
    112107                if (parent instanceof Relation && "multipolygon".equals(parent.get("type")))
    113108                    return;
    114109            }
    115             Node f = w.getNode(0);
    116             Node l = w.getNode(w.getNodesCount() - 1);
    117             if(force || f.getCoor().greatCircleDistance(l.getCoor()) < 10000)
    118             {
    119                 List<OsmPrimitive> primitives = new ArrayList<OsmPrimitive>();
    120                 List<OsmPrimitive> highlight = new ArrayList<OsmPrimitive>();
    121                 primitives.add(w);
    122                 // The important parts of an unclosed way are the first and
    123                 // the last node which should be connected, therefore we highlight them
    124                 highlight.add(f);
    125                 highlight.add(l);
    126                 errors.add(new TestError(this, Severity.WARNING, tr("Unclosed way"), type, etype, mode, primitives,
    127                         highlight));
    128                 _errorWays.add(w, w);
    129             }
     110            Node f = w.firstNode();
     111            Node l = w.lastNode();
     112
     113            List<OsmPrimitive> primitives = new ArrayList<OsmPrimitive>();
     114            List<OsmPrimitive> highlight = new ArrayList<OsmPrimitive>();
     115            primitives.add(w);
     116
     117            // The important parts of an unclosed way are the first and
     118            // the last node which should be connected, therefore we highlight them
     119            highlight.add(f);
     120            highlight.add(l);
     121
     122            errors.add(new TestError(this, Severity.WARNING, tr("Unclosed way"),
     123                            type, etype, mode, primitives, highlight));
     124            _errorWays.add(w, w);
    130125        }
    131126    }
Note: See TracChangeset for help on using the changeset viewer.