Changeset 10141 in josm


Ignore:
Timestamp:
2016-04-11T22:06:50+02:00 (4 years ago)
Author:
simon04
Message:

Validate that stop position lies on public transport route

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/tests/PublicTransportRouteTest.java

    r9937 r10141  
    55
    66import java.util.ArrayList;
     7import java.util.Arrays;
     8import java.util.HashSet;
    79import java.util.List;
     10import java.util.Set;
    811
     12import org.openstreetmap.josm.data.osm.Node;
     13import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    914import org.openstreetmap.josm.data.osm.Relation;
    1015import org.openstreetmap.josm.data.osm.RelationMember;
     
    4045
    4146        final List<RelationMember> membersToCheck = new ArrayList<>();
     47        final Set<Node> routeNodes = new HashSet<>();
    4248        for (RelationMember member : r.getMembers()) {
    4349            if (member.hasRole("forward", "backward")) {
    4450                errors.add(new TestError(this, Severity.WARNING, tr("Route relation contains a ''{0}'' role", "forward/backward"), 3601, r));
    4551                return;
    46             } else if (member.hasRole("")) {
     52            } else if (member.hasRole("") && OsmPrimitiveType.WAY.equals(member.getType())) {
    4753                membersToCheck.add(member);
     54                routeNodes.addAll(member.getWay().getNodes());
    4855            }
    4956        }
     
    6572        }
    6673
     74        for (RelationMember member : r.getMembers()) {
     75            if (member.hasRole("stop", "stop_exit_only", "stop_entry_only")
     76                    && OsmPrimitiveType.NODE.equals(member.getType())
     77                    && !routeNodes.contains(member.getNode())) {
     78                errors.add(new TestError(this, Severity.WARNING, tr("Stop position not part of route"), 3603, Arrays.asList(member.getMember(), r)));
     79            }
     80        }
     81
    6782    }
    6883}
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/PublicTransportRouteTestTest.java

    r9933 r10141  
    6767        assertEquals("Route relation contains a gap", test.getErrors().get(0).getMessage());
    6868
     69        final Relation r5 = TestUtils.newRelation("type=route route=tram public_transport:version=2",
     70                new RelationMember("", w1), new RelationMember("", w2), new RelationMember("", w3),
     71                new RelationMember("stop", w1.firstNode()), new RelationMember("stop", w4.lastNode()));
     72        test.startTest(null);
     73        test.visit(r5);
     74        assertEquals(1, test.getErrors().size());
     75        assertEquals("Stop position not part of route", test.getErrors().get(0).getMessage());
     76        assertEquals(w4.lastNode(), test.getErrors().get(0).getPrimitives().iterator().next());
     77
    6978    }
    7079}
Note: See TracChangeset for help on using the changeset viewer.