Changeset 18453 in osm for applications/editors/josm/plugins/validator/src
- Timestamp:
- 2009-11-04T15:17:43+01:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/Coastlines.java
r18384 r18453 4 4 5 5 import java.awt.geom.Area; 6 import java.awt.geom.Point2D;7 6 import java.util.*; 8 7 … … 14 13 import org.openstreetmap.josm.data.osm.Way; 15 14 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 15 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 16 16 import org.openstreetmap.josm.plugins.validator.Severity; 17 17 import org.openstreetmap.josm.plugins.validator.Test; … … 22 22 * 23 23 * @author frsantos 24 * @author Teemu Koskinen 24 25 */ 25 26 public class Coastlines extends Test … … 29 30 protected static int UNCONNECTED_COASTLINE = 903; 30 31 31 private boolean fixable = false; 32 private List<Way> coastlines; 33 34 private Area downloadedArea = null; 32 35 33 36 /** … … 41 44 42 45 @Override 43 public void visit(Way way) 44 { 45 if(!way.isUsable() || way.isClosed()) 46 return; 47 48 String natural = way.get("natural"); 49 if(natural == null || !natural.equals("coastline")) 50 return; 51 52 Node firstNode = way.firstNode(); 53 Node lastNode = way.lastNode(); 54 Way previousWay = null; 55 Way nextWay = null; 56 57 for (OsmPrimitive parent: this.backreferenceDataSet.getParents(firstNode)) { 58 natural = parent.get("natural"); 59 if (parent instanceof Way && !way.equals(parent) && (natural != null && "coastline".equals(natural))) { 60 previousWay = (Way)parent; 61 break; 62 } 63 } 64 for (OsmPrimitive parent: this.backreferenceDataSet.getParents(lastNode)) { 65 natural = parent.get("natural"); 66 if (parent instanceof Way && !way.equals(parent) && (natural != null && "coastline".equals(natural))) { 67 nextWay = (Way)parent; 68 break; 69 } 70 } 71 72 List<OsmPrimitive> primitives = new ArrayList<OsmPrimitive>(); 73 List<OsmPrimitive> highlight = new ArrayList<OsmPrimitive>(); 74 primitives.add(way); 46 public void startTest(ProgressMonitor monitor) 47 { 48 super.startTest(monitor); 75 49 76 50 OsmDataLayer layer = Main.map.mapView.getEditLayer(); 77 Area downloadedArea = null; 51 78 52 if (layer != null) 79 53 downloadedArea = layer.data.getDataSourceArea(); 80 54 81 if (previousWay == null || nextWay == null) { 82 boolean firstNodeUnconnected = false; 83 boolean lastNodeUnconnected = false; 84 85 if (previousWay == null && (downloadedArea == null || downloadedArea.contains(firstNode.getCoor()))) { 86 firstNodeUnconnected = true; 87 highlight.add(firstNode); 88 } 89 if (nextWay == null && (downloadedArea == null || downloadedArea.contains(lastNode.getCoor()))) { 90 lastNodeUnconnected = true; 91 highlight.add(lastNode); 92 } 93 94 if (firstNodeUnconnected || lastNodeUnconnected) 95 errors.add(new TestError(this, Severity.ERROR, tr("Unconnected coastline"), 96 UNCONNECTED_COASTLINE, primitives, highlight)); 97 } 98 99 boolean firstNodeUnordered = (previousWay != null && !firstNode.equals(previousWay.lastNode())); 100 boolean lastNodeUnordered = (nextWay != null && !lastNode.equals(nextWay.firstNode())); 101 102 if (firstNodeUnordered || lastNodeUnordered) { 103 if (firstNodeUnordered && lastNodeUnordered && !previousWay.equals(nextWay)) { 55 coastlines = new LinkedList<Way>(); 56 } 57 58 @Override 59 public void endTest() 60 { 61 for (Way c1 : coastlines) { 62 Node head = c1.firstNode(); 63 Node tail = c1.lastNode(); 64 65 if (head.equals(tail)) 66 continue; 67 68 int headWays = 0; 69 int tailWays = 0; 70 boolean headReversed = false; 71 boolean tailReversed = false; 72 boolean headUnordered = false; 73 boolean tailUnordered = false; 74 Way next = null; 75 Way prev = null; 76 77 for (Way c2 : coastlines) { 78 if (c1 == c2) 79 continue; 80 81 if (c2.containsNode(head)) { 82 headWays++; 83 next = c2; 84 85 if (head.equals(c2.firstNode())) 86 headReversed = true; 87 else if (!head.equals(c2.lastNode())) 88 headUnordered = true; 89 } 90 91 if (c2.containsNode(tail)) { 92 tailWays++; 93 prev = c2; 94 95 if (tail.equals(c2.lastNode())) 96 tailReversed = true; 97 else if (!tail.equals(c2.firstNode())) 98 tailUnordered = true; 99 } 100 } 101 102 103 List<OsmPrimitive> primitives = new ArrayList<OsmPrimitive>(); 104 primitives.add(c1); 105 106 if (headWays == 0 || tailWays == 0) { 107 List<OsmPrimitive> highlight = new ArrayList<OsmPrimitive>(); 108 109 System.out.println("Unconnected coastline: " + c1.getId()); 110 if (headWays == 0 && (downloadedArea == null || downloadedArea.contains(head.getCoor()))) { 111 System.out.println("headways: " +headWays+ " node: " + head.toString()); 112 highlight.add(head); 113 } 114 if (tailWays == 0 && (downloadedArea == null || downloadedArea.contains(tail.getCoor()))) { 115 System.out.println("tailways: " +tailWays+ " tail: " + tail.toString()); 116 highlight.add(tail); 117 } 118 119 if (highlight.size() > 0) 120 errors.add(new TestError(this, Severity.ERROR, tr("Unconnceted coastline"), 121 UNCONNECTED_COASTLINE, primitives, highlight)); 122 } 123 124 boolean unordered = false; 125 boolean reversed = false; 126 127 if (headWays == 1 && headReversed && tailWays == 1 && tailReversed) 128 reversed = true; 129 130 if (headWays > 1 || tailWays > 1) 131 unordered = true; 132 else if (headUnordered || tailUnordered) 133 unordered = true; 134 else if (reversed && next == prev) 135 unordered = true; 136 137 if (unordered) { 138 List<OsmPrimitive> highlight = new ArrayList<OsmPrimitive>(); 139 140 System.out.println("Unordered coastline: " + c1.toString()); 141 if (headWays > 1 || headUnordered || reversed) { 142 System.out.println("head: " + head.toString()); 143 highlight.add(head); 144 } 145 if (tailWays > 1 || tailUnordered || reversed) { 146 System.out.println("tail: " + tail.toString()); 147 highlight.add(tail); 148 } 149 150 errors.add(new TestError(this, Severity.ERROR, tr("Unordered coastline"), 151 UNORDERED_COASTLINE, primitives, highlight)); 152 } 153 else if (reversed) { 104 154 errors.add(new TestError(this, Severity.ERROR, tr("Reversed coastline"), 105 155 REVERSED_COASTLINE, primitives)); 106 107 } else {108 if (firstNodeUnordered)109 highlight.add(firstNode);110 if (lastNodeUnordered)111 highlight.add(lastNode);112 113 errors.add(new TestError(this, Severity.ERROR, tr("Unordered coastline"),114 UNORDERED_COASTLINE, primitives, highlight));115 156 } 116 157 } 158 159 coastlines = null; 160 downloadedArea = null; 161 162 super.endTest(); 163 } 164 165 @Override 166 public void visit(Way way) 167 { 168 if (!way.isUsable()) 169 return; 170 171 String natural = way.get("natural"); 172 if (natural == null || !natural.equals("coastline")) 173 return; 174 175 coastlines.add(way); 117 176 } 118 177
Note:
See TracChangeset
for help on using the changeset viewer.