Changeset 32353 in osm


Ignore:
Timestamp:
2016-06-21T20:51:36+02:00 (8 years ago)
Author:
darya
Message:

Test for stop positions at the beginning and end of the route added

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

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/actions/IncompleteMembersDownloadThread.java

    r32338 r32353  
    33import java.util.ArrayList;
    44import java.util.Collection;
     5import java.util.List;
    56
    67import javax.swing.JOptionPane;
     
    89import org.openstreetmap.josm.Main;
    910import org.openstreetmap.josm.data.osm.Node;
     11import org.openstreetmap.josm.data.osm.OsmPrimitive;
     12import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    1013import org.openstreetmap.josm.data.osm.PrimitiveId;
    1114import org.openstreetmap.josm.data.osm.Relation;
     15import org.openstreetmap.josm.data.osm.RelationMember;
    1216import org.openstreetmap.josm.gui.io.DownloadPrimitivesWithReferrersTask;
    1317import org.openstreetmap.josm.plugins.pt_assistant.utils.RouteUtils;
     
    3236                                ArrayList<PrimitiveId> list = new ArrayList<>();
    3337
    34                                 // add all route relations that are of public_transport version 2:
     38                                // add all route relations that are of public_transport version
     39                                // 2:
    3540                                Collection<Relation> allRelations = Main.getLayerManager().getEditDataSet().getRelations();
    3641                                for (Relation currentRelation : allRelations) {
    3742                                        if (RouteUtils.isTwoDirectionRoute(currentRelation)) {
    3843                                                list.add(currentRelation);
     44                                                for (RelationMember rm : currentRelation.getMembers()) {
     45                                                        if (rm.hasRole("stop") || rm.hasRole("stop_entry_only") || rm.hasRole("stop_exit_only")
     46                                                                        || rm.hasRole("platform") || rm.hasRole("platform_entry_only")
     47                                                                        || rm.hasRole("platform_exit_only")) {
     48                                                                List<OsmPrimitive> referrers = rm.getMember().getReferrers();
     49                                                                for (OsmPrimitive referrer : referrers) {
     50                                                                        if (referrer.getType().equals(OsmPrimitiveType.RELATION)
     51                                                                                        && referrer.hasTag("public_transport", "stop_area")) {
     52                                                                                list.add(referrer);
     53                                                                                // TODO: this may never be executed
     54                                                                                // because the platform is an incomplete
     55                                                                                // member yet.
     56                                                                        }
     57                                                                }
     58                                                        }
     59                                                }
    3960                                        }
    4061                                }
    41                                
     62
    4263                                // add all stop_positions:
    4364                                Collection<Node> allNodes = Main.getLayerManager().getEditDataSet().getNodes();
    44                                 for (Node currentNode: allNodes) {
     65                                for (Node currentNode : allNodes) {
    4566                                        if (currentNode.hasTag("public_transport", "stop_position")) {
    46                                                 list.add(currentNode);
     67                                                List<OsmPrimitive> referrers = currentNode.getReferrers();
     68                                                boolean parentWayExists = false;
     69                                                for (OsmPrimitive referrer : referrers) {
     70                                                        if (referrer.getType().equals(OsmPrimitiveType.WAY)) {
     71                                                                parentWayExists = true;
     72                                                                break;
     73                                                        }
     74                                                }
     75                                                if (!parentWayExists) {
     76                                                        list.add(currentNode);
     77
     78                                                }
     79
    4780                                        }
    4881                                }
    49                                
    50                                
     82
    5183                                DownloadPrimitivesWithReferrersTask task = new DownloadPrimitivesWithReferrersTask(false, list, false,
    5284                                                true, null, null);
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/data/PTRouteDataManager.java

    r32303 r32353  
    33import java.util.ArrayList;
    44import java.util.List;
     5
     6import javax.swing.JOptionPane;
    57
    68import org.openstreetmap.josm.data.osm.Relation;
     
    4042
    4143                        if (RouteUtils.isPTStop(member)) {
     44                               
    4245                                // check if there are consecutive elements that belong to the
    4346                                // same stop:
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/data/PTStop.java

    r32303 r32353  
    11package org.openstreetmap.josm.plugins.pt_assistant.data;
     2
     3import java.util.ArrayList;
     4import java.util.List;
     5import java.util.Set;
    26
    37import org.openstreetmap.josm.data.osm.Node;
     
    1115        private Node stopPosition = null;
    1216        private OsmPrimitive platform = null;
    13         private Relation stopArea = null;
    1417       
    15         /* Name of this stop */
    1618        private String name = "";
    1719
     
    2022                super(other);
    2123
    22                 if (other.getRole().equals("stop") && other.getType().equals(OsmPrimitiveType.NODE)) {
     24                if ((other.hasRole("stop") || other.hasRole("stop_entry_only") || other.hasRole("stop_exit_only"))&& other.getType().equals(OsmPrimitiveType.NODE)) {
     25
    2326                        this.stopPosition = other.getNode();
     27                        this.name = stopPosition.get("name");
     28
    2429                } else if (other.getRole().equals("platform") || other.getRole().equals("platform_entry_only")
    2530                                || other.getRole().equals("platform_exit_only")) {
     31
    2632                        this.platform = other.getMember();
    27                 } else if (other.getRole().equals("stop_area") && other.getType().equals(OsmPrimitiveType.RELATION)) {
    28                         this.stopArea = other.getRelation();
    29                         for (RelationMember rm: stopArea.getMembers()) {
    30                                 if (rm.getRole().equals("stop") && rm.isNode()) {
    31                                         this.stopPosition = rm.getNode();
    32                                 }
    33                                 if (rm.getRole().equals("platform") || rm.getRole().equals("platform_entry_only") || rm.getRole().equals("platform_exit_only")) {
    34                                         this.platform = rm.getMember();
    35                                 }
    36                         }
     33                        this.name = platform.get("name");
     34
    3735                } else {
    3836                        throw new IllegalArgumentException("The RelationMember type does not match its role");
    3937                }
    40                
    41                 this.name = other.getMember().get("name");
    4238
    4339        }
     
    5854
    5955                // add stop position:
    60                 if (member.getRole().equals("stop")) {
     56                if (member.hasRole("stop") || member.hasRole("stop_entry_only") || member.hasRole("stop_exit_only")) {
    6157                        if (member.getType().equals(OsmPrimitiveType.NODE) && stopPosition == null) {
    6258                                this.stopPosition = member.getNode();
     
    7470                }
    7571
    76                 // add stop_area:
    77                 if (member.getRole().equals("stop_area") && member.getType().equals(OsmPrimitiveType.RELATION)) {
    78                         if (stopArea == null) {
    79                                 stopArea = member.getRelation();
    80                                 for (RelationMember rm: stopArea.getMembers()) {
    81                                         if (rm.getRole().equals("stop") && rm.isNode()) {
    82                                                 this.stopPosition = rm.getNode();
    83                                         }
    84                                         if (rm.getRole().equals("platform") || rm.getRole().equals("platform_entry_only") || rm.getRole().equals("platform_exit_only")) {
    85                                                 this.platform = rm.getMember();
    86                                         }
    87                                 }
    88                                 return true;
    89                         }
    90                 }
    91 
    9272                return false;
    9373
    9474        }
    95        
     75
     76        /**
     77         * Returns the stop_position for this PTstop. If the stop_position is not
     78         * available directly, the method searches for a stop_area relation
     79         *
     80         * @return
     81         */
    9682        public Node getStopPosition() {
     83
     84                // List<OsmPrimitive> referrers = platform.getReferrers();
     85                // List<Relation> stopAreaRelations = new ArrayList<>();
     86                // for (OsmPrimitive referrer: referrers) {
     87                // if (referrer.getType().equals(OsmPrimitiveType.RELATION) &&
     88                // referrer.hasTag("public_tranport", "stop_area")) {
     89                // stopAreaRelations.add((Relation)referrer);
     90                // }
     91                // }
     92                //
     93                // for (Relation stopArea: stopAreaRelations) {
     94                // for (RelationMember rm: stopArea.getMembers()) {
     95                // if (rm.hasRole("stop") && rm.getType().equals(OsmPrimitiveType.NODE))
     96                // {
     97                // this.stopPosition = rm.getNode();
     98                // }
     99                // }
     100                // }
     101
    97102                return this.stopPosition;
    98103        }
    99        
     104
    100105        /**
    101106         * Returns platform (including platform_entry_only and platform_exit_only)
     107         *
    102108         * @return
    103109         */
     
    106112        }
    107113       
    108         public Relation getStopArea() {
    109                 return this.stopArea;
    110         }
    111        
    112114        public String getName() {
    113115                return this.name;
    114116        }
    115117
     118        public void setStopPosition(Node newStopPosition) {
     119
     120                this.stopPosition = newStopPosition;
     121
     122        }
     123
     124        /**
     125         * Finds potential stop_positions of the platform of this PTStop. It only
     126         * makes sense to call this method if the stop_position attribute is null.
     127         * The stop_positions are potential because they may refer to a different
     128         * route, which this method does not check.
     129         *
     130         * @return List of potential stop_positions for this PTStop
     131         */
     132        public List<Node> findPotentialStopPositions() {
     133
     134                ArrayList<Node> potentialStopPositions = new ArrayList<>();
     135
     136                if (platform == null) {
     137                        return potentialStopPositions;
     138                }
     139
     140                // 1) Look for any stop_area relations that this platform
     141                // belongs to:
     142                ArrayList<OsmPrimitive> platformList = new ArrayList<OsmPrimitive>(1);
     143                platformList.add(platform);
     144                Set<Relation> platformParentRelations = OsmPrimitive.getParentRelations(platformList);
     145                ArrayList<Relation> stopAreaList = new ArrayList<Relation>();
     146                for (Relation platformParentRelation : platformParentRelations) {
     147                        if (platformParentRelation.hasTag("public_transport", "stop_area")) {
     148                                stopAreaList.add(platformParentRelation);
     149                        }
     150                }
     151
     152                // 2) Get all potential stop_positions from those stop_area relations:
     153                for (Relation stopArea : stopAreaList) {
     154                        for (RelationMember rm : stopArea.getMembers()) {
     155                                if ((rm.hasRole("stop") || rm.hasRole("stop_entry_only") || rm.hasRole("stop_exit_only"))&& rm.getType().equals(OsmPrimitiveType.NODE)
     156                                                && rm.getNode().hasTag("public_transport", "stop_position")) {
     157                                        potentialStopPositions.add(rm.getNode());
     158                                }
     159                        }
     160                }
     161
     162                return potentialStopPositions;
     163        }
     164
    116165}
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/data/PTWay.java

    r32303 r32353  
    8484                return false;
    8585        }
     86       
    8687
    8788}
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/utils/RouteUtils.java

    r32299 r32353  
    6161
    6262                if (rm.getType().equals(OsmPrimitiveType.NODE)) {
    63                         return true;
     63
     64                        if (rm.getNode().hasTag("public_transport", "stop_position")
     65                                        || rm.getNode().hasTag("public_transport", "platform")
     66                                        || rm.getNode().hasTag("public_transport", "platform_entry_only")
     67                                        || rm.getNode().hasTag("public_transport", "platform_exit_only")
     68                                        || rm.getNode().hasTag("highway", "platform")
     69                                        || rm.getNode().hasTag("highway", "platform_entry_only")
     70                                        || rm.getNode().hasTag("highway", "platform_exit_only")
     71                                        || rm.getNode().hasTag("railway", "platform")
     72                                        || rm.getNode().hasTag("railway", "platform_entry_only")
     73                                        || rm.getNode().hasTag("railway", "platform_exit_only")) {
     74                                return true;
     75                        }
     76
    6477                }
    6578
    66                 if (rm.getType().equals(OsmPrimitiveType.RELATION)) {
    67                         if (rm.getRole().equals("stop_area")) {
     79                if (rm.getType().equals(OsmPrimitiveType.WAY)) {
     80                        if (rm.getWay().hasTag("public_transport", "platform")
     81                                        || rm.getWay().hasTag("public_transport", "platform_entry_only")
     82                                        || rm.getWay().hasTag("public_transport", "platform_exit_only")
     83                                        || rm.getWay().hasTag("highway", "platform") || rm.getWay().hasTag("highway", "platform_entry_only")
     84                                        || rm.getWay().hasTag("highway", "platform_exist_only") || rm.getWay().hasTag("railway", "platform")
     85                                        || rm.getWay().hasTag("railway", "platform_entry_only")
     86                                        || rm.getWay().hasTag("railway", "platform_exit_only")) {
    6887                                return true;
    69                         } else if (rm.getRole().equals("platform") || rm.getRole().equals("platform_entry_only") || rm.getRole().equals("platform_exit_only")){
    70                                 return true;
    71                         } else {
    72                                 return false;
    7388                        }
    74                 }
    75 
    76                 Way w = rm.getWay();
    77 
    78                 if (w.hasTag("public_transport", "platform") || w.hasTag("highway", "platform")
    79                                 || w.hasTag("railway", "platform") || w.hasTag("public_transport", "platform_entry_only")
    80                                 || w.hasTag("highway", "platform_entry_only") || w.hasTag("railway", "platform_entry_only")
    81                                 || w.hasTag("public_transport", "platform_exit_only") || w.hasTag("highway", "platform_exit_only")
    82                                 || w.hasTag("railway", "platform_exit_only")) {
    83                         return true;
    8489                }
    8590
     
    101106
    102107                return !isPTStop(rm);
     108
    103109        }
    104110
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/PTAssitantValidatorTest.java

    r32338 r32353  
    4343        @Override
    4444        public void visit(Relation r) {
     45               
    4546
    4647                if (!RouteUtils.isTwoDirectionRoute(r)) {
    4748                        return;
    4849                }
     50               
    4951
    5052                // Download incomplete members. If the download does not work, finish.
     
    5557                        }
    5658                }
     59               
     60                if (r.hasIncompleteMembers()) {
     61                        return;
     62                }
    5763
    5864                // Check individual ways using the oneway direction test and the road
     
    6066                WayChecker wayChecker = new WayChecker(r, this);
    6167                this.errors.addAll(wayChecker.getErrors());
     68               
    6269
    6370                if (this.errors.isEmpty()) {
     
    8996                                        t.wait();
    9097                                } catch (InterruptedException e) {
     98                                        // TODO: give the user a message that testing stops
    9199                                        return false;
    92100                                }
     
    184192       
    185193        private void proceedAfterSorting(Relation r) {
    186                 // TODO
    187                 performDummyTest(r);
     194               
     195               
     196               
     197                SegmentChecker segmentChecker = new SegmentChecker(r, this);
     198                segmentChecker.performFirstStopTest();
     199                segmentChecker.performLastStopTest();
     200                // TODO: perform segment test
     201                this.errors.addAll(segmentChecker.getErrors());
     202//              performDummyTest(r);
    188203        }
    189204
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/SegmentChecker.java

    r32303 r32353  
    66import java.util.List;
    77
     8import org.openstreetmap.josm.data.osm.Node;
    89import org.openstreetmap.josm.data.osm.OsmPrimitive;
    910import org.openstreetmap.josm.data.osm.Relation;
     
    3940
    4041                super(relation, test);
    41 
     42               
    4243                this.manager = new PTRouteDataManager(relation);
    4344                this.assigner = new StopToWayAssigner(manager.getPTWays());
    44 
     45               
    4546        }
    4647
     
    5859
    5960        private void performEndStopTest(PTStop endStop) {
    60                 if (manager.getPTStopCount() < 2) {
    61                         // it does not make sense to check a route that has less than 2
    62                         // stops
    63                         return;
    64                 }
     61
     62                /*
     63                 * This test checks: (1) that a stop position exists; (2) that it is the
     64                 * first or last node of its parent ways which belong to this route.
     65                 */
    6566
    6667                if (endStop.getStopPosition() == null) {
    67                         List<Relation> primitives = new ArrayList<>(1);
    68                         primitives.add(relation);
    69                         List<OsmPrimitive> highlighted = new ArrayList<>(1);
    70                         highlighted.add(endStop.getPlatform());
    71                         TestError e = new TestError(this.test, Severity.WARNING,
    72                                         tr("PT: Route should start and end with a stop_position"),
    73                                         PTAssitantValidatorTest.ERROR_CODE_END_STOP, primitives, highlighted);
    74                         this.errors.add(e);
    75                         return;
    76                 }
    7768
    78                 PTWay endWay = assigner.get(endStop);
     69                        List<Node> potentialStopPositionList = endStop.findPotentialStopPositions();
     70                        List<Node> stopPositionsOfThisRoute = new ArrayList<>();
     71                        boolean containsAtLeastOneStopPositionAsFirstOrLastNode = false;
    7972
    80                 boolean found = false;
    81                 List<Way> primitivesOfEndWay = endWay.getWays();
    82                 for (Way primitiveWay : primitivesOfEndWay) {
    83                         if (primitiveWay.firstNode() == endStop.getStopPosition()
    84                                         || primitiveWay.lastNode() == endStop.getStopPosition()) {
    85                                 found = true;
     73                        for (Node potentialStopPosition : potentialStopPositionList) {
     74
     75                                int belongsToWay = belongsToAWayOfThisRoute(potentialStopPosition);
     76
     77                                if (belongsToWay == 0) {
     78                                        stopPositionsOfThisRoute.add(potentialStopPosition);
     79                                        containsAtLeastOneStopPositionAsFirstOrLastNode = true;
     80                                }
     81
     82                                if (belongsToWay == 1) {
     83                                        stopPositionsOfThisRoute.add(potentialStopPosition);
     84                                }
    8685                        }
    8786
    88                 }
     87                        if (stopPositionsOfThisRoute.isEmpty()) {
     88                                List<Relation> primitives = new ArrayList<>(1);
     89                                primitives.add(relation);
     90                                List<OsmPrimitive> highlighted = new ArrayList<>(1);
     91                                highlighted.add(endStop.getPlatform());
     92                                TestError e = new TestError(this.test, Severity.WARNING,
     93                                                tr("PT: Route should start and end with a stop_position"),
     94                                                PTAssitantValidatorTest.ERROR_CODE_END_STOP, primitives, highlighted);
     95                                this.errors.add(e);
     96                                return;
     97                        }
     98                       
     99                        if (stopPositionsOfThisRoute.size() == 1) {
     100                                endStop.setStopPosition(stopPositionsOfThisRoute.get(0));
     101                        }
    89102
    90                 if (!found) {
    91                         List<Relation> primitives = new ArrayList<>(1);
    92                         primitives.add(relation);
    93                         List<OsmPrimitive> highlighted = new ArrayList<>();
    94                         for (Way w : endWay.getWays()) {
    95                                 if (w.getNodes().contains(endStop.getStopPosition())) {
    96                                         highlighted.add(w);
    97                                 }
     103                        // At this point, there is at least one stop_position for this
     104                        // endStop:
     105                        if (!containsAtLeastOneStopPositionAsFirstOrLastNode) {
     106                                List<Relation> primitives = new ArrayList<>(1);
     107                                primitives.add(relation);
     108                                List<OsmPrimitive> highlighted = new ArrayList<>();
     109                                highlighted.addAll(stopPositionsOfThisRoute);
     110
     111                                TestError e = new TestError(this.test, Severity.WARNING, tr("PT: First or last way needs to be split"),
     112                                                PTAssitantValidatorTest.ERROR_CODE_SPLIT_WAY, primitives, highlighted);
     113                                this.errors.add(e);
    98114                        }
    99                         TestError e = new TestError(this.test, Severity.WARNING,
    100                                         tr("PT: First or last way needs to be split"),
    101                                         PTAssitantValidatorTest.ERROR_CODE_SPLIT_WAY, primitives, highlighted);
    102                         this.errors.add(e);
     115
     116                } else {
     117                       
     118                        // if the stop_position is known:
     119                        int belongsToWay = this.belongsToAWayOfThisRoute(endStop.getStopPosition());
     120                       
     121                        if (belongsToWay == 1) {
     122                               
     123                                List<Relation> primitives = new ArrayList<>(1);
     124                                primitives.add(relation);
     125                                List<OsmPrimitive> highlighted = new ArrayList<>();
     126                                highlighted.add(endStop.getStopPosition());
     127                                TestError e = new TestError(this.test, Severity.WARNING, tr("PT: First or last way needs to be split"),
     128                                                PTAssitantValidatorTest.ERROR_CODE_SPLIT_WAY, primitives, highlighted);
     129                                this.errors.add(e);
     130                        }
    103131                }
    104132
     
    109137        }
    110138
     139        /**
     140         * Checks if the given node belongs to the ways of this route.
     141         *
     142         * @param node
     143         *            Node to be checked
     144         * @return 1 if belongs only as an inner node, 0 if belongs as a first or
     145         *         last node for at least one way, -1 if does not belong to any way.
     146         */
     147        private int belongsToAWayOfThisRoute(Node node) {
     148
     149                boolean contains = false;
     150
     151                List<PTWay> ptways = manager.getPTWays();
     152                for (PTWay ptway : ptways) {
     153                        List<Way> ways = ptway.getWays();
     154                        for (Way way : ways) {
     155                                if (way.containsNode(node)) {
     156
     157                                        if (way.firstNode().equals(node) || way.lastNode().equals(node)) {
     158                                                return 0;
     159                                        }
     160
     161                                        contains = true;
     162                                }
     163                        }
     164                }
     165
     166                if (contains) {
     167                        return 1;
     168                }
     169
     170                return -1;
     171        }
     172
    111173}
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/WayChecker.java

    r32299 r32353  
    3030                super(relation, test);
    3131
    32                 this.performDirectionTest();
    33                 this.performRoadTypeTest();
     32                if (!relation.hasIncompleteMembers()) {
     33                        this.performDirectionTest();
     34                        this.performRoadTypeTest();
     35                }
     36
    3437
    3538        }
    3639
    3740        private void performRoadTypeTest() {
    38 
     41               
    3942                if (!relation.hasTag("route", "bus") && !relation.hasTag("route", "trolleybus")
    4043                                && !relation.hasTag("route", "share_taxi")) {
Note: See TracChangeset for help on using the changeset viewer.