Changeset 32603 in osm
- Timestamp:
- 2016-07-08T15:30:53+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/pt_assistant
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/utils/RouteUtils.java
r32597 r32603 149 149 } 150 150 151 /** 152 * Checks if the ways have a common node 153 * @param w1 154 * @param w2 155 * @return 156 */ 151 157 public static boolean waysTouch(Way w1, Way w2) { 152 158 -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/WayChecker.java
r32597 r32603 5 5 import java.util.ArrayList; 6 6 import java.util.Collection; 7 import java.util.HashSet; 7 8 import java.util.List; 9 import java.util.Set; 8 10 9 11 import javax.swing.SwingUtilities; … … 194 196 primitives.add(relation); 195 197 List<Way> highlighted = new ArrayList<>(1); 196 highlighted.add(problematicWay); 198 // highlighted.add(problematicWay); 199 Set<Way> adjacentWays = checkAdjacentWays(problematicWay, new HashSet<Way>()); 200 highlighted.addAll(adjacentWays); 197 201 TestError e = new TestError(this.test, Severity.WARNING, 198 202 tr("PT: Route passes a oneway road in the wrong direction"), … … 200 204 this.errors.add(e); 201 205 } 206 207 } 208 209 /** 210 * Checks if the current way touches its neighbouring was correctly 211 * 212 * @param prev 213 * can be null 214 * @param curr 215 * cannot be null 216 * @param next 217 * can be null 218 * @return 219 */ 220 private boolean touchCorrectly(Way prev, Way curr, Way next) { 221 222 if (RouteUtils.isOnewayForPublicTransport(curr) == 0) { 223 return true; 224 } 225 226 if (prev != null) { 227 228 if (RouteUtils.waysTouch(curr, prev)) { 229 Node nodeInQuestion; 230 if (RouteUtils.isOnewayForPublicTransport(curr) == 1) { 231 nodeInQuestion = curr.firstNode(); 232 } else { 233 nodeInQuestion = curr.lastNode(); 234 } 235 236 List<Way> nb = findNeighborWays(curr, nodeInQuestion); 237 238 if (nb.size() < 2 && nodeInQuestion != prev.firstNode() && nodeInQuestion != prev.lastNode()) { 239 return false; 240 } 241 } 242 } 243 244 if (next != null) { 245 246 if (RouteUtils.waysTouch(curr, next)) { 247 Node nodeInQuestion; 248 if (RouteUtils.isOnewayForPublicTransport(curr) == 1) { 249 nodeInQuestion = curr.lastNode(); 250 } else { 251 nodeInQuestion = curr.firstNode(); 252 } 253 254 List<Way> nb = findNeighborWays(curr, nodeInQuestion); 255 256 if (nb.size() < 2 && nodeInQuestion != next.firstNode() && nodeInQuestion != next.lastNode()) { 257 return false; 258 } 259 } 260 } 261 262 return true; 263 264 } 265 266 protected Set<Way> checkAdjacentWays(Way curr, Set<Way> flags) { 267 // curr is supposed to be a wrong oneway way!! 268 269 Set<Way> resultSet = new HashSet<>(); 270 resultSet.addAll(flags); 271 resultSet.add(curr); 272 273 if (RouteUtils.isOnewayForPublicTransport(curr) == 0) { 274 return null; 275 } 276 277 Node firstNodeInRouteDirection; 278 Node lastNodeInRouteDirection; 279 if (RouteUtils.isOnewayForPublicTransport(curr) == 1) { 280 firstNodeInRouteDirection = curr.lastNode(); 281 lastNodeInRouteDirection = curr.firstNode(); 282 } else { 283 firstNodeInRouteDirection = curr.firstNode(); 284 lastNodeInRouteDirection = curr.lastNode(); 285 } 286 287 List<Way> firstNodeInRouteDirectionNeighbors = findNeighborWays(curr, firstNodeInRouteDirection); 288 List<Way> lastNodeInRouteDirectionNeighbors = findNeighborWays(curr, lastNodeInRouteDirection); 289 290 for (Way nb : firstNodeInRouteDirectionNeighbors) { 291 292 if (resultSet.contains(nb)) { 293 continue; 294 } 295 296 if (RouteUtils.isOnewayForPublicTransport(nb) == 1 && nb.firstNode() == firstNodeInRouteDirection) { 297 Set<Way> newSet = this.checkAdjacentWays(nb, resultSet); 298 resultSet.addAll(newSet); 299 300 } else if (RouteUtils.isOnewayForPublicTransport(nb) == -1 && nb.lastNode() == firstNodeInRouteDirection) { 301 Set<Way> newSet = this.checkAdjacentWays(nb, resultSet); 302 resultSet.addAll(newSet); 303 304 } 305 } 306 307 for (Way nb : lastNodeInRouteDirectionNeighbors) { 308 309 if (resultSet.contains(nb)) { 310 continue; 311 } 312 313 if (RouteUtils.isOnewayForPublicTransport(nb) == 1 && nb.lastNode() == lastNodeInRouteDirection) { 314 Set<Way> newSet = this.checkAdjacentWays(nb, resultSet); 315 resultSet.addAll(newSet); 316 } else if (RouteUtils.isOnewayForPublicTransport(nb) == -1 && nb.firstNode() == lastNodeInRouteDirection) { 317 Set<Way> newSet = this.checkAdjacentWays(nb, resultSet); 318 resultSet.addAll(newSet); 319 } 320 321 } 322 323 return resultSet; 324 325 } 326 327 /** 328 * Finds all ways that touch the given way at the given node AND belong to 329 * the relation of this WayChecker 330 * 331 * @param way 332 * @param node 333 * @return 334 */ 335 private List<Way> findNeighborWays(Way way, Node node) { 336 337 List<Way> resultList = new ArrayList<>(); 338 339 List<OsmPrimitive> nodeReferrers = node.getReferrers(); 340 341 for (OsmPrimitive referrer : nodeReferrers) { 342 if (referrer.getType().equals(OsmPrimitiveType.WAY)) { 343 Way neighborWay = (Way) referrer; 344 if (neighborWay != way && containsWay(neighborWay)) { 345 resultList.add(neighborWay); 346 } 347 } 348 } 349 350 return resultList; 351 } 352 353 /** 354 * Checks if the relation of this WayChecker contains the given way 355 * 356 * @param way 357 * @return 358 */ 359 private boolean containsWay(Way way) { 360 361 List<RelationMember> members = relation.getMembers(); 362 363 for (RelationMember rm : members) { 364 if (rm.isWay() && rm.getWay() == way) { 365 return true; 366 } 367 } 368 369 return false; 202 370 203 371 } … … 365 533 } 366 534 367 /**368 * Checks if the current way touches its neighbouring was correctly369 *370 * @param prev371 * can be null372 * @param curr373 * cannot be null374 * @param next375 * can be null376 * @return377 */378 private boolean touchCorrectly(Way prev, Way curr, Way next) {379 380 if (RouteUtils.isOnewayForPublicTransport(curr) == 0) {381 return true;382 }383 384 if (prev != null) {385 386 if (RouteUtils.waysTouch(curr, prev)) {387 Node nodeInQuestion;388 if (RouteUtils.isOnewayForPublicTransport(curr) == 1) {389 nodeInQuestion = curr.firstNode();390 } else {391 nodeInQuestion = curr.lastNode();392 }393 394 if (nodeInQuestion != prev.firstNode() && nodeInQuestion != prev.lastNode()) {395 return false;396 }397 }398 }399 400 if (next != null) {401 402 if (RouteUtils.waysTouch(curr, next)) {403 Node nodeInQuestion;404 if (RouteUtils.isOnewayForPublicTransport(curr) == 1) {405 nodeInQuestion = curr.lastNode();406 } else {407 nodeInQuestion = curr.firstNode();408 }409 410 if (nodeInQuestion != next.firstNode() && nodeInQuestion != next.lastNode()) {411 return false;412 }413 }414 }415 416 return true;417 418 }419 420 535 } -
applications/editors/josm/plugins/pt_assistant/test/unit/org/openstreetmap/josm/plugins/pt_assistant/AbstractTest.java
r32299 r32603 40 40 public static final String PATH_TO_ROAD_TYPE_ERROR = "test/data/road-type.osm"; 41 41 42 public static final String PATH_TO_ONEWAY_BAD_MEMBER_SORTING = "test/data/oneway-bad-member-sorting.osm"; 42 43 44 public static final String PATH_TO_ONEWAY_WRONG_DIRECTION = "test/data/oneway-wrong-direction.osm"; 45 public static final String PATH_TO_ONEWAY_WRONG_DIRECTION2 = "test/data/oneway-wrong-direction2.osm"; 46 43 47 /** 44 48 * Initiates the basic parts of JOSM. -
applications/editors/josm/plugins/pt_assistant/test/unit/org/openstreetmap/josm/plugins/pt_assistant/validation/DirecionTestTest.java
r32582 r32603 19 19 20 20 @Test 21 public void test () {21 public void testOnewayTrue() { 22 22 23 File file = new File(AbstractTest.PATH_TO_ ROUNDABOUT_ONEWAY);23 File file = new File(AbstractTest.PATH_TO_ONEWAY_WRONG_DIRECTION); 24 24 DataSet ds = ImportUtils.importOsmFile(file, "testLayer"); 25 25 … … 33 33 } 34 34 35 assertEquals(route.getMembersCount(), 213); 36 35 37 36 List<TestError> errors = new ArrayList<>(); 38 37 … … 43 42 } 44 43 45 assertEquals(errors.size(), 1);44 assertEquals(errors.size(), 2); 46 45 int onewayErrorCaught = 0; 47 46 for (TestError e: errors ) { … … 51 50 } 52 51 53 assertEquals(onewayErrorCaught, 1);52 assertEquals(onewayErrorCaught, 2); 54 53 55 54 // fix the direction errors: … … 60 59 @SuppressWarnings("unchecked") 61 60 List<OsmPrimitive> highlighted = (List<OsmPrimitive>) e.getHighlighted(); 62 if (highlighted.get(0).getId() != 2 6130630 && highlighted.get(0).getId() != 151278290) {61 if (highlighted.get(0).getId() != 225732678 && highlighted.get(0).getId() != 24215210) { 63 62 detectedErrorsAreCorrect = false; 64 63 }
Note:
See TracChangeset
for help on using the changeset viewer.