Changeset 32603 in osm for applications/editors/josm


Ignore:
Timestamp:
2016-07-08T15:30:53+02:00 (8 years ago)
Author:
darya
Message:

Checks for adjacent ways

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  
    149149        }
    150150
     151        /**
     152         * Checks if the ways have a common node
     153         * @param w1
     154         * @param w2
     155         * @return
     156         */
    151157        public static boolean waysTouch(Way w1, Way w2) {
    152158
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/WayChecker.java

    r32597 r32603  
    55import java.util.ArrayList;
    66import java.util.Collection;
     7import java.util.HashSet;
    78import java.util.List;
     9import java.util.Set;
    810
    911import javax.swing.SwingUtilities;
     
    194196                        primitives.add(relation);
    195197                        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);
    197201                        TestError e = new TestError(this.test, Severity.WARNING,
    198202                                        tr("PT: Route passes a oneway road in the wrong direction"),
     
    200204                        this.errors.add(e);
    201205                }
     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;
    202370
    203371        }
     
    365533        }
    366534
    367         /**
    368          * Checks if the current way touches its neighbouring was correctly
    369          *
    370          * @param prev
    371          *            can be null
    372          * @param curr
    373          *            cannot be null
    374          * @param next
    375          *            can be null
    376          * @return
    377          */
    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 
    420535}
  • applications/editors/josm/plugins/pt_assistant/test/unit/org/openstreetmap/josm/plugins/pt_assistant/AbstractTest.java

    r32299 r32603  
    4040 public static final String PATH_TO_ROAD_TYPE_ERROR = "test/data/road-type.osm";
    4141 
     42 public static final String PATH_TO_ONEWAY_BAD_MEMBER_SORTING = "test/data/oneway-bad-member-sorting.osm";
    4243 
     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
    4347  /**
    4448   * 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  
    1919   
    2020    @Test
    21     public void test() {
     21    public void testOnewayTrue() {
    2222       
    23         File file = new File(AbstractTest.PATH_TO_ROUNDABOUT_ONEWAY);
     23        File file = new File(AbstractTest.PATH_TO_ONEWAY_WRONG_DIRECTION);
    2424        DataSet ds = ImportUtils.importOsmFile(file, "testLayer");
    2525       
     
    3333        }
    3434       
    35         assertEquals(route.getMembersCount(), 213);
    36                
     35             
    3736        List<TestError> errors = new ArrayList<>();
    3837       
     
    4342        }
    4443       
    45         assertEquals(errors.size(), 1);
     44        assertEquals(errors.size(), 2);
    4645        int onewayErrorCaught = 0;
    4746        for (TestError e: errors ) {
     
    5150        }
    5251       
    53         assertEquals(onewayErrorCaught, 1);
     52        assertEquals(onewayErrorCaught, 2);
    5453       
    5554        // fix the direction errors:
     
    6059                @SuppressWarnings("unchecked")
    6160                List<OsmPrimitive> highlighted = (List<OsmPrimitive>) e.getHighlighted();
    62                 if (highlighted.get(0).getId() != 26130630 && highlighted.get(0).getId() != 151278290)  {
     61                if (highlighted.get(0).getId() != 225732678 && highlighted.get(0).getId() != 24215210)  {
    6362                    detectedErrorsAreCorrect = false;
    6463                }
Note: See TracChangeset for help on using the changeset viewer.