Changeset 32734 in osm for applications/editors/josm/plugins
- Timestamp:
- 2016-07-28T12:54:20+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/data/PTStop.java
r32715 r32734 137 137 } 138 138 139 // Look for a stop position within 100 m (around 0.002 degrees) of this139 // Look for a stop position within 0.002 degrees (around 100 m) of this 140 140 // platform: 141 141 … … 147 147 BBox platformBBox = new BBox(ax, ay, bx, by); 148 148 149 // Collection<Node> allNodes =150 // Main.getLayerManager().getEditDataSet().getNodes();151 149 Collection<Node> allNodes = platform.getDataSet().getNodes(); 152 150 for (Node currentNode : allNodes) { … … 163 161 * stop_position or a platform 164 162 * 165 * @param other PTStop to be compared 163 * @param other 164 * PTStop to be compared 166 165 * @return true if equal, false otherwise 167 166 */ … … 172 171 } 173 172 174 if (this.stopPosition != null && (this.stopPosition == other.getStopPosition() || this.stopPosition == other.getPlatform())) { 173 if (this.stopPosition != null 174 && (this.stopPosition == other.getStopPosition() || this.stopPosition == other.getPlatform())) { 175 175 return true; 176 176 } 177 178 if (this.platform != null && (this.platform == other.getPlatform() || this.platform == other.getStopPosition())) { 177 178 if (this.platform != null 179 && (this.platform == other.getPlatform() || this.platform == other.getStopPosition())) { 179 180 return true; 180 181 } … … 182 183 return false; 183 184 } 184 185 185 186 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/utils/StopToWayAssigner.java
r32707 r32734 43 43 public StopToWayAssigner(List<PTWay> ptways) { 44 44 ways = new HashSet<Way>(); 45 for (PTWay ptway : ptways) {45 for (PTWay ptway : ptways) { 46 46 ways.addAll(ptway.getWays()); 47 47 } … … 59 59 if (stopToWay.containsKey(stop)) { 60 60 List<Way> assignedWays = stopToWay.get(stop); 61 for (Way assignedWay : assignedWays) {61 for (Way assignedWay : assignedWays) { 62 62 if (this.ways.contains(assignedWay)) { 63 63 return assignedWay; … … 72 72 return wayOfStopPosition; 73 73 } 74 75 // TODO: search if a stop position is in the vicinity of a platform76 74 77 75 // 3) Search if the stop has a stop_area: … … 98 96 } 99 97 100 // 4) Run the growing-bounding-boxes algorithm: 98 // 4) Search if a stop position is in the vicinity of a platform: 99 if (stop.getPlatform() != null) { 100 List<Node> potentialStopPositionList = stop.findPotentialStopPositions(); 101 Node closestStopPosition = null; 102 double minDistanceSq = Double.MAX_VALUE; 103 for (Node potentialStopPosition : potentialStopPositionList) { 104 double distanceSq = potentialStopPosition.getCoor() 105 .distanceSq(stop.getPlatform().getBBox().getCenter()); 106 if (distanceSq < minDistanceSq) { 107 closestStopPosition = potentialStopPosition; 108 minDistanceSq = distanceSq; 109 } 110 } 111 if (closestStopPosition != null) { 112 Way closestWay = null; 113 double minDistanceSqToWay = Double.MAX_VALUE; 114 for (Way way: this.ways) { 115 if (way.containsNode(closestStopPosition)) { 116 double distanceSq = calculateMinDistanceToSegment(new Node(stop.getPlatform().getBBox().getCenter()), way); 117 if (distanceSq < minDistanceSqToWay) { 118 closestWay = way; 119 minDistanceSqToWay = distanceSq; 120 } 121 } 122 } 123 if (closestWay != null) { 124 addAssignedWayToMap(stop, closestWay); 125 return closestWay; 126 } 127 } 128 } 129 130 // 5) Run the growing-bounding-boxes algorithm: 101 131 double searchRadius = 0.001; 102 132 while (searchRadius < 0.005) { -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/PTAssistantValidatorTest.java
r32715 r32734 45 45 public static final int ERROR_CODE_STOP_BY_STOP = 3754; 46 46 47 48 47 private PTAssistantLayer layer; 49 48 … … 284 283 // If there is only the sorting error, add it and stop testing. 285 284 this.errors.addAll(routeChecker.getErrors()); 286 return; 287 } 288 289 if (!routeChecker.getHasGap()) { 290 // Variant 1 291 // storeCorrectRouteSegments(r); 292 293 } 285 // return; 286 } 287 288 // if (!routeChecker.getHasGap()) { 289 // // Variant 1 290 // storeCorrectRouteSegments(r); 291 // } 294 292 295 293 // Variant 3: … … 311 309 segmentChecker.performFirstStopTest(); 312 310 segmentChecker.performLastStopTest(); 313 segmentChecker.performStopByStopTest(); 311 segmentChecker.performStopNotServedTest(); 312 313 boolean sortingErrorFound = false; 314 for (TestError error : this.errors) { 315 if (error.getCode() == ERROR_CODE_SORTING) { 316 sortingErrorFound = true; 317 break; 318 } 319 } 320 if (!sortingErrorFound) { 321 segmentChecker.performStopByStopTest(); 322 } 314 323 315 324 this.errors.addAll(segmentChecker.getErrors()); … … 317 326 318 327 /** 319 * Creates the PTRouteSegments of a route that has been found correct and stores them in the list of correct route segments 320 * @param r route relation 328 * Creates the PTRouteSegments of a route that has been found correct and 329 * stores them in the list of correct route segments 330 * 331 * @param r 332 * route relation 321 333 */ 322 334 @SuppressWarnings("unused") … … 326 338 if (manager.getPTStops().size() > 1) { 327 339 for (int i = 1; i < manager.getPTStops().size(); i++) { 328 PTStop segmentStartStop = manager.getPTStops().get(i -1);340 PTStop segmentStartStop = manager.getPTStops().get(i - 1); 329 341 PTStop segmentEndStop = manager.getPTStops().get(i); 330 342 Way segmentStartWay = assigner.get(segmentStartStop); … … 348 360 return true; 349 361 } 350 362 351 363 if (testError.getCode() == ERROR_CODE_STOP_BY_STOP && SegmentChecker.isFixable(testError)) { 352 364 return true; 353 365 } 354 366 355 367 return false; 356 368 } … … 378 390 commands.add(NodeChecker.fixError(testError)); 379 391 } 380 392 381 393 if (testError.getCode() == ERROR_CODE_STOP_BY_STOP) { 382 394 commands.add(SegmentChecker.fixError(testError)); -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/SegmentChecker.java
r32715 r32734 219 219 } 220 220 221 public void performStopNotServedTest() { 222 for (PTStop stop : manager.getPTStops()) { 223 Way way = assigner.get(stop); 224 if (way == null) { 225 createStopError(stop); 226 } 227 } 228 } 229 230 /** 231 * Performs the stop-by-stop test by visiting each segment between two 232 * consecutive stops and checking if the ways between them are correct 233 */ 221 234 public void performStopByStopTest() { 222 235 223 236 if (manager.getPTStopCount() < 2) { 224 237 return; … … 233 246 Way startWay = assigner.get(startStop); 234 247 Way endWay = assigner.get(endStop); 235 if (startWay == null ) {248 if (startWay == null || endWay == null) { 236 249 this.firstNodeOfRouteSegmentInDirectionOfTravel = null; 237 if (i == 0) {238 createStopError(startStop);239 }240 250 continue; 241 251 } 242 if (endWay == null) { 243 this.firstNodeOfRouteSegmentInDirectionOfTravel = null; 244 if (i != 0) { 245 createStopError(endStop); 246 } 247 continue; 248 } 252 // 253 // System.out.println(); 254 // System.out.println("start way: " + startWay.getId()); 255 // System.out.println("end way: " + endWay.getId()); 249 256 250 257 List<PTWay> segmentWays = manager.getPTWaysBetween(startWay, endWay); … … 267 274 correctSegments.add(routeSegment); 268 275 } else { 276 // System.out.println("ERROR"); 269 277 PTRouteSegment routeSegment = new PTRouteSegment(startStop, endStop, segmentWays); 270 278 TestError error = this.errors.get(this.errors.size() - 1); … … 366 374 if (start == end) { 367 375 // if both PTStops are on the same PTWay 376 this.firstNodeOfRouteSegmentInDirectionOfTravel = null; 368 377 return true; 369 378 } … … 397 406 // find the next node in direction of travel (which is part of 398 407 // the PTWay start): 408 // if (firstNodeOfRouteSegmentInDirectionOfTravel != null) { 409 // System.out.println("previous node in direction of travel: " 410 // + firstNodeOfRouteSegmentInDirectionOfTravel.getId()); 411 // } else { 412 // System.out.println("previous node in direction of travel: null"); 413 // } 399 414 firstNodeOfRouteSegmentInDirectionOfTravel = getOppositeEndNode(current, 400 415 firstNodeOfRouteSegmentInDirectionOfTravel); 416 // if (firstNodeOfRouteSegmentInDirectionOfTravel != null) { 417 // System.out.println( 418 // "next node in direction of travel: " + firstNodeOfRouteSegmentInDirectionOfTravel.getId()); 419 // } else { 420 // System.out.println("next node in direction of travel: null"); 421 // } 401 422 402 423 List<PTWay> nextWaysInDirectionOfTravel = this.findNextPTWaysInDirectionOfTravel(current, … … 551 572 List<RelationMember> originalRelationMembers = originalRelation.getMembers(); 552 573 List<RelationMember> modifiedRelationMembers = new ArrayList<>(); 553 574 554 575 // copy stops first: 555 for (RelationMember rm : originalRelationMembers) {576 for (RelationMember rm : originalRelationMembers) { 556 577 if (RouteUtils.isPTStop(rm)) { 557 578 if (rm.getRole().equals("stop_position")) { … … 568 589 modifiedRelationMembers.add(rm); 569 590 } 570 } 571 } 572 591 } 592 } 593 573 594 // copy PTWays next: 574 595 List<RelationMember> waysOfOriginalRelation = new ArrayList<>(); 575 for (RelationMember rm : originalRelation.getMembers()) {596 for (RelationMember rm : originalRelation.getMembers()) { 576 597 if (RouteUtils.isPTWay(rm)) { 577 598 waysOfOriginalRelation.add(rm); 578 599 } 579 600 } 580 601 581 602 for (int i = 0; i < waysOfOriginalRelation.size(); i++) { 582 603 if (waysOfOriginalRelation.get(i).getWay() == wrongSegment.getPTWays().get(0).getWays().get(0)) { 583 // if (waysOfOriginalRelation.get(i) == wrongSegment.getPTWays().get(0)) { 584 modifiedRelationMembers.addAll(correctSegment.getPTWays()); 604 // if (waysOfOriginalRelation.get(i) == 605 // wrongSegment.getPTWays().get(0)) { 606 for (PTWay ptway : correctSegment.getPTWays()) { 607 if (ptway.getRole().equals("forward") || ptway.getRole().equals("backward")) { 608 modifiedRelationMembers.add(new RelationMember("", ptway.getMember())); 609 } else { 610 modifiedRelationMembers.add(ptway); 611 } 612 } 585 613 i = i + wrongSegment.getPTWays().size() - 1; 586 614 } else { 587 modifiedRelationMembers.add(waysOfOriginalRelation.get(i)); 588 } 589 } 590 615 if (waysOfOriginalRelation.get(i).getRole().equals("forward") 616 || waysOfOriginalRelation.get(i).getRole().equals("backward")) { 617 modifiedRelationMembers.add(new RelationMember("", waysOfOriginalRelation.get(i).getMember())); 618 } else { 619 modifiedRelationMembers.add(waysOfOriginalRelation.get(i)); 620 } 621 } 622 } 591 623 592 624 modifiedRelation.setMembers(modifiedRelationMembers); 593 625 // TODO: change the data model too 626 wrongSegments.remove(testError); 594 627 ChangeCommand changeCommand = new ChangeCommand(originalRelation, modifiedRelation); 595 628 return changeCommand;
Note:
See TracChangeset
for help on using the changeset viewer.