Changeset 18194 in osm for applications
- Timestamp:
- 2009-10-17T15:37:04+02:00 (15 years ago)
- 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 6 6 import java.util.*; 7 7 8 import org.openstreetmap.josm.command.ChangeCommand; 9 import org.openstreetmap.josm.command.Command; 8 10 import org.openstreetmap.josm.data.osm.OsmPrimitive; 11 import org.openstreetmap.josm.data.osm.Node; 9 12 import org.openstreetmap.josm.data.osm.Way; 10 import org.openstreetmap.josm.gui.progress.ProgressMonitor;11 13 import org.openstreetmap.josm.plugins.validator.Severity; 12 14 import org.openstreetmap.josm.plugins.validator.Test; 13 15 import org.openstreetmap.josm.plugins.validator.TestError; 14 import org.openstreetmap.josm.plugins.validator.util.Bag;15 import org.openstreetmap.josm.plugins.validator.util.Util;16 16 17 17 /** … … 22 22 public class Coastlines extends Test 23 23 { 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; 25 27 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 31 30 /** 32 31 * Constructor … … 39 38 40 39 @Override 41 public void startTest(ProgressMonitor monitor)40 public void visit(Way w) 42 41 { 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 } 46 101 } 47 102 48 103 @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; 54 117 } 55 118 56 119 @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 } 61 124 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; 89 126 } 90 127 } -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/UnclosedWays.java
r18088 r18194 50 50 private String etype; 51 51 private int mode; 52 private boolean force;53 52 54 public void set( boolean f,int m, String text, String desc) {53 public void set(int m, String text, String desc) { 55 54 etype = MessageFormat.format(text, desc); 56 55 type = tr(text, tr(desc)); 57 56 mode = m; 58 force = f;59 57 } 60 58 61 public void set( boolean f,int m, String text) {59 public void set(int m, String text) { 62 60 etype = text; 63 61 type = tr(text); 64 62 mode = m; 65 force = f;66 63 } 67 64 … … 69 66 public void visit(Way w) { 70 67 String test; 71 force = false; /* force even if end-to-end distance is long */72 68 type = etype = null; 73 69 mode = 0; … … 77 73 78 74 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); 81 77 test = w.get("landuse"); 82 78 if (test != null) 83 set( true,1102, marktr("landuse type {0}"), test);79 set(1102, marktr("landuse type {0}"), test); 84 80 test = w.get("amenities"); 85 81 if (test != null) 86 set( true,1103, marktr("amenities type {0}"), test);82 set(1103, marktr("amenities type {0}"), test); 87 83 test = w.get("sport"); 88 84 if (test != null && !test.equals("water_slide")) 89 set( true,1104, marktr("sport type {0}"), test);85 set(1104, marktr("sport type {0}"), test); 90 86 test = w.get("tourism"); 91 87 if (test != null) 92 set( true,1105, marktr("tourism type {0}"), test);88 set(1105, marktr("tourism type {0}"), test); 93 89 test = w.get("shop"); 94 90 if (test != null) 95 set( true,1106, marktr("shop type {0}"), test);91 set(1106, marktr("shop type {0}"), test); 96 92 test = w.get("leisure"); 97 93 if (test != null) 98 set( true,1107, marktr("leisure type {0}"), test);94 set(1107, marktr("leisure type {0}"), test); 99 95 test = w.get("waterway"); 100 96 if (test != null && test.equals("riverbank")) 101 set( true,1108, marktr("waterway type {0}"), test);97 set(1108, marktr("waterway type {0}"), test); 102 98 Boolean btest = OsmUtils.getOsmBoolean(w.get("building")); 103 99 if (btest != null && btest) 104 set( true,1120, marktr("building"));100 set(1120, marktr("building")); 105 101 btest = OsmUtils.getOsmBoolean(w.get("area")); 106 102 if (btest != null && btest) 107 set( true,1130, marktr("area"));103 set(1130, marktr("area")); 108 104 109 if (type != null && !w.isClosed()) 110 { 105 if (type != null && !w.isClosed()) { 111 106 for (OsmPrimitive parent: this.backreferenceDataSet.getParents(w)) { 112 107 if (parent instanceof Relation && "multipolygon".equals(parent.get("type"))) 113 108 return; 114 109 } 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 123 124 125 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); 130 125 } 131 126 }
Note:
See TracChangeset
for help on using the changeset viewer.