Ticket #737: WronglyOrderedWays.diff
| File WronglyOrderedWays.diff, 3.0 KB (added by , 18 years ago) |
|---|
-
WronglyOrderedWays.java
59 59 if( natural == null) 60 60 return; 61 61 62 if( !natural.equals("coastline") ){62 if(natural.equals("coastline") ){ 63 63 errortype = "Clockwise coastline"; 64 }else if( !natural.equals("water") ){64 }else if(natural.equals("water") ){ 65 65 errortype = "Clockwise water"; 66 }else if( !natural.equals("land") ){66 }else if(natural.equals("land") ){ 67 67 errortype = "Clockwise land"; 68 68 } else { 69 69 return; … … 72 72 /** 73 73 * Test the directionality of the way 74 74 * 75 * Checks if the node following the northern-most node is further 76 * west then the node previous 75 * Assuming a closed non-looping way, compute twice the area 76 * of the pollygon using the formula 2*a = sum (Xn * Yn+1 - Xn+1 * Yn) 77 * If the area is negative the way is ordered in a clockwise direction 77 78 * 78 * Only tests ways that the first and last node is the same currently79 *80 79 */ 81 80 82 81 if(w.nodes.get(0) == w.nodes.get(w.nodes.size()-1)){ 83 int maxnode = -1; 84 double maxlat = -90; 85 86 for (int node = 0; node < w.nodes.size(); node++){ 87 double lat = w.nodes.get(node).coor.lat(); 88 if(lat > maxlat){ 89 maxnode = node; 90 maxlat = lat; 91 } 92 } 93 94 int nextnode; 95 int prevnode; 96 97 // Determine the previous and next nodes in the loop 98 if(maxnode==0){ 99 nextnode = 1; 100 prevnode = w.nodes.size()-1; 101 }else if(maxnode == w.nodes.size()-1){ 102 nextnode = 0; 103 prevnode = maxnode - 1; 104 } else { 105 nextnode = maxnode + 1; 106 prevnode = maxnode - 1; 107 } 108 109 double prevlon = w.nodes.get(prevnode).coor.lon(); 110 double nextlon = w.nodes.get(nextnode).coor.lon(); 111 112 if(((natural.equals("coastline") || natural.equals("land")) && prevlon < nextlon) 113 || (natural.equals("water") && prevlon > nextlon)){ 82 double area2 = 0; 83 84 for (int node = 1; node < w.nodes.size(); node++){ 85 area2 += (w.nodes.get(node-1).coor.lon() * w.nodes.get(node).coor.lat() 86 - w.nodes.get(node).coor.lon() * w.nodes.get(node-1).coor.lat()); 87 } 88 89 if(((natural.equals("coastline") || natural.equals("land")) && area2 < 0.) 90 || (natural.equals("water") && area2 > 0.)){ 114 91 List<OsmPrimitive> primitives = new ArrayList<OsmPrimitive>(); 115 92 primitives.add(w); 116 93 errors.add( new TestError(this, Severity.WARNING, tr(errortype), primitives) );
