Ticket #7259: validations.diff
File validations.diff, 9.1 KB (added by , 12 years ago) |
---|
-
src/org/openstreetmap/josm/data/validation/tests/OverlappingAreas.java
2 2 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.util.ArrayList; 5 6 import java.util.Collection; 6 7 import java.util.Collections; 8 7 9 import org.openstreetmap.josm.data.osm.QuadBuckets; 8 10 import org.openstreetmap.josm.data.osm.Way; 9 11 import org.openstreetmap.josm.data.validation.Severity; … … 39 41 40 42 @Override 41 43 public boolean evaluate(Way wi) { 42 if (w.equals(wi)) {44 if (w.equals(wi)) 43 45 return false; 44 } else {46 else 45 47 return Geometry.polygonIntersection(w.getNodes(), wi.getNodes()) 46 == Geometry.PolygonIntersection.CROSSING; 47 } 48 == Geometry.PolygonIntersection.CROSSING; 48 49 } 49 50 }); 50 51 if (!overlaps.isEmpty()) { 51 errors.add(new TestError(this, Severity.OTHER, tr("Overlapping Areas"), 52 OVERLAPPING_AREAS, Collections.singletonList(w), overlaps)); 52 Collection<Way> overlapsWater = new ArrayList<Way>( 8 ); 53 Collection<Way> overlapsOther = new ArrayList<Way>( 8 ); 54 55 System.out.println( "Overlapping areas for id:" + w.getId() ); 56 String natural1 = w.get("natural"); 57 String landuse1 = w.get("landuse"); 58 boolean isWaterArea = "water".equals(natural1) || "wetland".equals(natural1) || "coastline".equals(natural1) || "reservoir".equals(landuse1); 59 boolean isWaterArea2 = false; 60 61 for( Way wayOther : overlaps ) { 62 String natural2 = wayOther.get("natural"); 63 String landuse2 = wayOther.get("landuse"); 64 boolean isWaterAreaTest = "water".equals(natural2) || "wetland".equals(natural2) || "coastline".equals(natural2) || "reservoir".equals(landuse2); 65 66 if( ! isWaterArea2 ) { 67 isWaterArea2 = isWaterAreaTest; 68 } 69 70 if( isWaterArea && isWaterAreaTest ) { 71 overlapsWater.add( wayOther ); 72 } else { 73 overlapsOther.add( wayOther ); 74 } 75 } 76 77 if( ! overlapsWater.isEmpty() ) { 78 errors.add(new TestError(this, Severity.WARNING, tr("Overlapping Water Areas"), 79 OVERLAPPING_AREAS, Collections.singletonList(w), overlapsWater)); 80 } 81 82 if( ! overlapsOther.isEmpty() ) { 83 errors.add(new TestError(this, Severity.OTHER, tr("Overlapping Areas"), 84 OVERLAPPING_AREAS, Collections.singletonList(w), overlapsOther)); 85 } 53 86 } 54 87 } 55 88 } -
src/org/openstreetmap/josm/data/validation/tests/CrossingWays.java
42 42 */ 43 43 public CrossingWays() { 44 44 super(tr("Crossing ways."), 45 tr("This test checks if two roads, railways, waterways or buildings crosses in the same layer, but are not connected by a node."));45 tr("This test checks if two roads, railways, waterways or buildings crosses in the same layer, but are not connected by a node.")); 46 46 } 47 47 48 48 @Override … … 81 81 return; 82 82 83 83 String layer1 = w.get("layer"); 84 if ("0".equals(layer1)) layer1 = null; //0 is default value 84 if ("0".equals(layer1)) 85 { 86 layer1 = null; //0 is default value 87 } 85 88 86 89 int nodesSize = w.getNodesCount(); 87 90 for (int i = 0; i < nodesSize - 1; i++) { … … 93 96 List<Way> prims; 94 97 List<WaySegment> highlight; 95 98 96 if (errorSegments.contains(ws) && errorSegments.contains(es2.ws)) 99 if (errorSegments.contains(ws) && errorSegments.contains(es2.ws)) { 97 100 continue; 101 } 98 102 99 103 String layer2 = es2.layer; 100 104 String railway2 = es2.railway; 101 105 boolean isCoastline2 = es2.coastline; 102 if (layer1 == null ? layer2 != null : !layer1.equals(layer2)) 106 if (layer1 == null ? layer2 != null : !layer1.equals(layer2)) { 103 107 continue; 108 } 104 109 105 if (!es1.intersects(es2) ) continue; 106 if (isSubway1 && "subway".equals(railway2)) continue; 107 if (isTram1 && "tram".equals(railway2)) continue; 110 if (!es1.intersects(es2) ) { 111 continue; 112 } 113 if (isSubway1 && "subway".equals(railway2)) { 114 continue; 115 } 116 if (isTram1 && "tram".equals(railway2)) { 117 continue; 118 } 108 119 109 if (isCoastline1 != isCoastline2) continue; 120 if (isCoastline1 != isCoastline2) { 121 continue; 122 } 110 123 if (("river".equals(waterway1) && "riverbank".equals(es2.waterway)) 111 || ("riverbank".equals(waterway1) && "river".equals(es2.waterway))) continue; 124 || ("riverbank".equals(waterway1) && "river".equals(es2.waterway))) { 125 continue; 126 } 112 127 113 128 if ((es1.railway != null && es1.railway.equals("abandoned")) 114 || (railway2 != null && railway2.equals("abandoned"))) continue; 129 || (railway2 != null && railway2.equals("abandoned"))) { 130 continue; 131 } 115 132 116 133 prims = Arrays.asList(es1.ws.way, es2.ws.way); 117 134 if ((highlight = ways_seen.get(prims)) == null) { … … 122 139 String message; 123 140 if (isBuilding) { 124 141 message = tr("Crossing buildings"); 142 } else if ((es1.waterway != null && es2.waterway != null)) { 143 message = tr("Crossing waterways"); 125 144 } else if ((es1.waterway != null && es2.ws.way.get("highway") != null) 126 145 || (es2.waterway != null && es1.ws.way.get("highway") != null)) { 127 146 message = tr("Crossing waterway/highway"); … … 130 149 } 131 150 132 151 errors.add(new TestError(this, Severity.WARNING, 133 message,134 CROSSING_WAYS,135 prims,136 highlight));152 message, 153 CROSSING_WAYS, 154 prims, 155 highlight)); 137 156 ways_seen.put(prims, highlight); 138 157 } else { 139 158 highlight.add(es1.ws); … … 146 165 } 147 166 148 167 /** 149 * Returns all the cells this segment crosses. Each cell contains the list150 * of segments already processed151 *152 * @param n1 The first node153 * @param n2 The second node154 * @return A list with all the cells the segment crosses155 */168 * Returns all the cells this segment crosses. Each cell contains the list 169 * of segments already processed 170 * 171 * @param n1 The first node 172 * @param n2 The second node 173 * @return A list with all the cells the segment crosses 174 */ 156 175 public List<List<ExtendedSegment>> getSegments(Node n1, Node n2) { 157 176 158 177 List<List<ExtendedSegment>> cells = new ArrayList<List<ExtendedSegment>>(); … … 217 236 return false; 218 237 219 238 return Line2D.linesIntersect( 220 n1.getEastNorth().east(), n1.getEastNorth().north(),221 n2.getEastNorth().east(), n2.getEastNorth().north(),222 s2.n1.getEastNorth().east(), s2.n1.getEastNorth().north(),223 s2.n2.getEastNorth().east(), s2.n2.getEastNorth().north());239 n1.getEastNorth().east(), n1.getEastNorth().north(), 240 n2.getEastNorth().east(), n2.getEastNorth().north(), 241 s2.n1.getEastNorth().east(), s2.n1.getEastNorth().north(), 242 s2.n2.getEastNorth().east(), s2.n2.getEastNorth().north()); 224 243 } 225 244 } 226 245 }