Ignore:
Timestamp:
2016-07-24T15:43:24+02:00 (9 years ago)
Author:
darya
Message:

correction for roundabouts

Location:
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/data/PTRouteDataManager.java

    r32707 r32710  
    22
    33import java.util.ArrayList;
     4import java.util.HashSet;
    45import java.util.List;
    56
     
    182183                return this.failedMembers;
    183184        }
    184        
     185
    185186        /**
    186187         * Returns the route relation for which this manager was created:
     188         *
    187189         * @return
    188190         */
     
    324326         */
    325327        public List<PTWay> getPTWaysBetween(Way start, Way end) {
    326                
     328
    327329                List<Integer> potentialStartIndices = new ArrayList<>();
    328330                List<Integer> potentialEndIndices = new ArrayList<>();
    329                
     331
    330332                for (int i = 0; i < ptways.size(); i++) {
    331333                        if (ptways.get(i).getWays().contains(start)) {
     
    336338                        }
    337339                }
    338                
     340
    339341                List<int[]> pairList = new ArrayList<>();
    340                 for (Integer potentialStartIndex: potentialStartIndices) {
    341                         for (Integer potentialEndIndex: potentialEndIndices) {
     342                for (Integer potentialStartIndex : potentialStartIndices) {
     343                        for (Integer potentialEndIndex : potentialEndIndices) {
    342344                                if (potentialStartIndex <= potentialEndIndex) {
    343                                         int[] pair = {potentialStartIndex, potentialEndIndex};
     345                                        int[] pair = { potentialStartIndex, potentialEndIndex };
    344346                                        pairList.add(pair);
    345347                                }
    346348                        }
    347349                }
    348                
     350
    349351                int minDifference = Integer.MAX_VALUE;
    350                 int[] mostSuitablePair = {0, 0};
    351                 for (int[] pair: pairList) {
     352                int[] mostSuitablePair = { 0, 0 };
     353                for (int[] pair : pairList) {
    352354                        int diff = pair[1] - pair[0];
    353355                        if (diff < minDifference) {
     
    356358                        }
    357359                }
    358                
     360
    359361                List<PTWay> result = new ArrayList<>();
    360362                for (int i = mostSuitablePair[0]; i <= mostSuitablePair[1]; i++) {
     
    363365                return result;
    364366        }
    365        
    366         /**
    367          * Returns the common Node of two PTWays or null if there is no common Node
     367
     368        /**
     369         * Returns the common Node of two PTWays or null if there is no common Node.
     370         * If there is more than one common Node, only the first found is returned.
     371         *
    368372         * @param way1
    369373         * @param way2
     
    371375         */
    372376        public Node getCommonNode(PTWay way1, PTWay way2) {
    373                
     377
    374378                List<Way> wayList1 = way1.getWays();
    375379                List<Way> wayList2 = way2.getWays();
    376                
    377                 for (int i = 0; i < wayList1.size(); i++) {
    378                         for (int j = 0; j < wayList2.size(); j++) {
    379                                 if (wayList1.get(i).firstNode() == wayList2.get(j).firstNode() || wayList1.get(i).firstNode() == wayList2.get(j).lastNode()) {
    380                                         return wayList1.get(i).firstNode();
    381                                 }
    382                                 if (wayList1.get(i).lastNode() == wayList2.get(j).firstNode() || wayList1.get(i).lastNode() == wayList2.get(j).lastNode()) {
    383                                         return wayList1.get(i).lastNode();
    384                                 }
    385                         }
    386                 }
     380
     381                HashSet<Node> nodeSet1 = new HashSet<>();
     382                for (Way w : wayList1) {
     383                        nodeSet1.addAll(w.getNodes());
     384                }
     385                HashSet<Node> nodeSet2 = new HashSet<>();
     386                for (Way w : wayList2) {
     387                        nodeSet2.addAll(w.getNodes());
     388                }
     389
     390                for (Node n : nodeSet1) {
     391                        if (nodeSet2.contains(n)) {
     392                                return n;
     393                        }
     394                }
     395
    387396                return null;
    388397        }
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/data/PTWay.java

    r32707 r32710  
    118118                return endNodes;
    119119        }
     120       
     121        public boolean containsUnsplitRoundabout() {
     122               
     123                List<Way> ways = this.getWays();
     124                for (Way way: ways) {
     125                        if (way.hasTag("junction", "roundabout") && way.firstNode() == way.lastNode()) {
     126                                return true;
     127                        }
     128                }
     129                return false;
     130        }
    120131
    121132}
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/SegmentChecker.java

    r32707 r32710  
    342342                        // matter which of the geometrically equal PTWays it finds
    343343
    344                         // find the next node in direction of travel (which is part of the
    345                         // PTWay start):
    346                         firstNodeOfRouteSegmentInDirectionOfTravel = getOppositeEndNode(current,
    347                                         firstNodeOfRouteSegmentInDirectionOfTravel);
    348 
    349                         List<PTWay> nextWaysInDirectionOfTravel = this.findNextPTWaysInDirectionOfTravel(current,
    350                                         firstNodeOfRouteSegmentInDirectionOfTravel);
    351        
    352344                        PTWay nextPTWayAccortingToExistingSorting = manager.getNextPTWay(current);
    353                         if (!nextWaysInDirectionOfTravel.contains(nextPTWayAccortingToExistingSorting)) {
    354                                 List<Relation> primitives = new ArrayList<>(1);
    355                                 primitives.add(relation);
    356                                 List<OsmPrimitive> highlighted = new ArrayList<>();
    357 
    358                                 highlighted.addAll(current.getWays());
    359                                 highlighted.add(firstNodeOfRouteSegmentInDirectionOfTravel);
    360 
    361                                 TestError e = new TestError(this.test, Severity.WARNING, tr("PT: Problem in the route segment"),
    362                                                 PTAssistantValidatorTest.ERROR_CODE_STOP_BY_STOP, primitives, highlighted);
    363                                 this.errors.add(e);
    364                                 this.firstNodeOfRouteSegmentInDirectionOfTravel = null;
    365                                 return false;
     345
     346                        // if current contains an unsplit roundabout:
     347                        if (current.containsUnsplitRoundabout()) {
     348                                firstNodeOfRouteSegmentInDirectionOfTravel = manager.getCommonNode(current,
     349                                                nextPTWayAccortingToExistingSorting);
     350                                if (firstNodeOfRouteSegmentInDirectionOfTravel == null) {
     351                                        List<Relation> primitives = new ArrayList<>(1);
     352                                        primitives.add(relation);
     353                                        List<OsmPrimitive> highlighted = new ArrayList<>();
     354                                        highlighted.addAll(current.getWays());
     355                                        TestError e = new TestError(this.test, Severity.WARNING, tr("PT: Problem in the route segment"),
     356                                                        PTAssistantValidatorTest.ERROR_CODE_STOP_BY_STOP, primitives, highlighted);
     357                                        this.errors.add(e);
     358                                        return false;
     359                                }
     360                        } else {
     361                                // if this is a regular way, not an unsplit roundabout
     362
     363                                // find the next node in direction of travel (which is part of
     364                                // the PTWay start):
     365                                firstNodeOfRouteSegmentInDirectionOfTravel = getOppositeEndNode(current,
     366                                                firstNodeOfRouteSegmentInDirectionOfTravel);
     367
     368                                List<PTWay> nextWaysInDirectionOfTravel = this.findNextPTWaysInDirectionOfTravel(current,
     369                                                firstNodeOfRouteSegmentInDirectionOfTravel);
     370
     371                                if (!nextWaysInDirectionOfTravel.contains(nextPTWayAccortingToExistingSorting)) {
     372                                        List<Relation> primitives = new ArrayList<>(1);
     373                                        primitives.add(relation);
     374                                        List<OsmPrimitive> highlighted = new ArrayList<>();
     375
     376                                        highlighted.addAll(current.getWays());
     377                                        highlighted.add(firstNodeOfRouteSegmentInDirectionOfTravel);
     378
     379                                        TestError e = new TestError(this.test, Severity.WARNING, tr("PT: Problem in the route segment"),
     380                                                        PTAssistantValidatorTest.ERROR_CODE_STOP_BY_STOP, primitives, highlighted);
     381                                        this.errors.add(e);
     382                                        this.firstNodeOfRouteSegmentInDirectionOfTravel = null;
     383                                        return false;
     384
     385                                }
    366386                        }
    367387
     
    373393        }
    374394
     395        /**
     396         * Will return the same node if the way is an unsplit roundabout
     397         * @param way
     398         * @param node
     399         * @return
     400         */
    375401        private Node getOppositeEndNode(Way way, Node node) {
    376402
     
    386412        }
    387413
     414        /**
     415         * Does not work correctly for unsplit roundabouts
     416         * @param ptway
     417         * @param node
     418         * @return
     419         */
    388420        private Node getOppositeEndNode(PTWay ptway, Node node) {
    389421                if (ptway.isWay()) {
     
    425457
    426458                        if (ptway != currentWay) {
    427                                 Node[] endNodes = ptway.getEndNodes();
    428                                 if (endNodes[0] == nextNodeInDirectionOfTravel || endNodes[1] == nextNodeInDirectionOfTravel) {
    429                                         nextPtways.add(ptway);
     459                                for (Way way: ptway.getWays()) {
     460                                        if (way.containsNode(nextNodeInDirectionOfTravel)) {
     461                                                nextPtways.add(ptway);
     462                                        }
    430463                                }
    431464                        }
Note: See TracChangeset for help on using the changeset viewer.