Changeset 32367 in osm


Ignore:
Timestamp:
2016-06-23T00:23:53+02:00 (8 years ago)
Author:
darya
Message:

fix #13025

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

Legend:

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

    r32353 r32367  
    4242                                        if (RouteUtils.isTwoDirectionRoute(currentRelation)) {
    4343                                                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                                                 }
     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//                                                                      }
     54//                                                              }
     55//                                                      }
     56//                                              }
    6057                                        }
    6158                                }
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/data/PTRouteDataManager.java

    r32353 r32367  
    66import javax.swing.JOptionPane;
    77
     8import org.openstreetmap.josm.data.coor.LatLon;
    89import org.openstreetmap.josm.data.osm.Relation;
    910import org.openstreetmap.josm.data.osm.RelationMember;
     
    2930        private List<PTWay> ptways = new ArrayList<>();
    3031
    31         public PTRouteDataManager(Relation relation) {
     32        /*
     33         * Stores relation members that could not be created because they are not
     34         * expected in the model for public_transport version 2
     35         */
     36        private List<RelationMember> failedMembers = new ArrayList<>();
     37
     38        public PTRouteDataManager(Relation relation) throws IllegalArgumentException {
    3239
    3340                // It is assumed that the relation is a route. Build in a check here
    3441                // (e.g. from class RouteUtils) if you want to invoke this constructor
    3542                // from outside the pt_assitant SegmentChecker)
    36                
     43
    3744                this.relation = relation;
    38                
     45
    3946                PTStop prev = null; // stores the last created PTStop
    4047
     
    4249
    4350                        if (RouteUtils.isPTStop(member)) {
    44                                
    45                                 // check if there are consecutive elements that belong to the
    46                                 // same stop:
    47                                 if (prev != null && prev.getName().equalsIgnoreCase(member.getMember().get("name"))) {
    48                                         // this PTStop already exists, so just add a new element:
     51
     52                                // First, check if the stop already exists (i.e. there are
     53                                // consecutive elements that belong to the same stop:
     54                                boolean stopExists = false;
     55
     56                                if (prev != null) {
     57                                        if (prev.getName() == null || prev.getName().equals("") || member.getMember().get("name") == null
     58                                                        || member.getMember().get("name").equals("")) {
     59
     60                                                // if there is no name, check by proximity:
     61                                                // Squared distance of 0.000004 corresponds to
     62                                                // around 100 m
     63                                                if (this.calculateDistanceSq(member, prev) < 0.000004) {
     64
     65                                                        stopExists = true;
     66                                                }
     67                                        } else {
     68
     69                                                // if there is a name, check by name comparison:
     70                                                if (prev.getName().equalsIgnoreCase(member.getMember().get("name"))) {
     71
     72                                                        stopExists = true;
     73                                                }
     74                                        }
     75                                }
     76
     77                                // check if there are consecutive elements that belong to
     78                                // the same stop:
     79                                if (stopExists) {
     80                                        // this PTStop already exists, so just add a new
     81                                        // element:
    4982                                        prev.addStopElement(member);
    50                                         // TODO: something may need to be done if adding the element
    51                                         // did not succeed. The failure is a result of the same stop
     83                                        // TODO: something may need to be done if adding the
     84                                        // element
     85                                        // did not succeed. The failure is a result of the same
     86                                        // stop
    5287                                        // having >1 stop_position, platform or stop_area.
    5388                                } else {
     
    5893                                }
    5994
    60                         } else {
     95                        } else if (RouteUtils.isPTWay(member)) {
     96
    6197                                PTWay ptway = new PTWay(member);
    6298                                ptways.add(ptway);
     99
     100                        } else {
     101                                this.failedMembers.add(member);
    63102                        }
     103
    64104                }
    65105        }
    66        
     106
     107        /**
     108         * Calculates the squared distance between the centers of bounding boxes of
     109         * two relation members (which are supposed to be platforms or
     110         * stop_positions)
     111         *
     112         * @param member1
     113         * @param member2
     114         * @return Squared distance between the centers of the bounding boxes of the
     115         *         given relation members
     116         */
     117        private double calculateDistanceSq(RelationMember member1, RelationMember member2) {
     118                LatLon coord1 = member1.getMember().getBBox().getCenter();
     119                LatLon coord2 = member2.getMember().getBBox().getCenter();
     120                return coord1.distanceSq(coord2);
     121        }
     122
    67123        /**
    68124         * Assigns the given way to a PTWay of this route relation.
    69          * @param inputWay Way to be assigned to a PTWAy of this route relation
    70          * @return PTWay that contains the geometry of the inputWay, null if not found
     125         *
     126         * @param inputWay
     127         *            Way to be assigned to a PTWAy of this route relation
     128         * @return PTWay that contains the geometry of the inputWay, null if not
     129         *         found
    71130         */
    72131        public PTWay getPTWay(Way inputWay) {
    73                
    74                 for (PTWay curr: ptways) {
    75                        
     132
     133                for (PTWay curr : ptways) {
     134
    76135                        if (curr.isWay() && curr.getWays().get(0) == inputWay) {
    77136                                return curr;
    78137                        }
    79                        
     138
    80139                        if (curr.isRelation()) {
    81                                 for (RelationMember rm: curr.getRelation().getMembers()) {
     140                                for (RelationMember rm : curr.getRelation().getMembers()) {
    82141                                        Way wayInNestedRelation = rm.getWay();
    83142                                        if (wayInNestedRelation == inputWay) {
     
    87146                        }
    88147                }
    89                
     148
    90149                return null; // if not found
    91150        }
    92        
     151
    93152        public List<PTStop> getPTStops() {
    94153                return this.ptstops;
    95154        }
    96        
     155
    97156        public List<PTWay> getPTWays() {
    98157                return this.ptways;
    99158        }
    100        
     159
    101160        public int getPTStopCount() {
    102161                return ptstops.size();
    103162        }
    104        
     163
    105164        public int getPTWayCount() {
    106165                return this.ptways.size();
    107166        }
    108        
     167
    109168        public PTStop getFirstStop() {
    110169                if (this.ptstops.isEmpty()) {
     
    113172                return this.ptstops.get(0);
    114173        }
    115        
     174
    116175        public PTStop getLastStop() {
    117176                if (this.ptstops.isEmpty()) {
    118177                        return null;
    119178                }
    120                 return this.ptstops.get(ptstops.size()-1);
     179                return this.ptstops.get(ptstops.size() - 1);
     180        }
     181
     182        public List<RelationMember> getFailedMembers() {
     183                return this.failedMembers;
    121184        }
    122185
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/data/PTStop.java

    r32353 r32367  
    22
    33import java.util.ArrayList;
     4import java.util.Collection;
    45import java.util.List;
    5 import java.util.Set;
    66
     7import org.openstreetmap.josm.Main;
     8import org.openstreetmap.josm.data.coor.LatLon;
     9import org.openstreetmap.josm.data.osm.BBox;
    710import org.openstreetmap.josm.data.osm.Node;
    811import org.openstreetmap.josm.data.osm.OsmPrimitive;
    912import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    10 import org.openstreetmap.josm.data.osm.Relation;
    1113import org.openstreetmap.josm.data.osm.RelationMember;
    1214
     
    1517        private Node stopPosition = null;
    1618        private OsmPrimitive platform = null;
    17        
     19
    1820        private String name = "";
    1921
     
    2224                super(other);
    2325
    24                 if ((other.hasRole("stop") || other.hasRole("stop_entry_only") || other.hasRole("stop_exit_only"))&& other.getType().equals(OsmPrimitiveType.NODE)) {
     26                if ((other.hasRole("stop") || other.hasRole("stop_entry_only") || other.hasRole("stop_exit_only"))
     27                                && other.getType().equals(OsmPrimitiveType.NODE)) {
    2528
    2629                        this.stopPosition = other.getNode();
     
    3437
    3538                } else {
    36                         throw new IllegalArgumentException("The RelationMember type does not match its role");
     39                        throw new IllegalArgumentException("The RelationMember type does not match its role " + other.getMember().getName());
    3740                }
    3841
     
    8285        public Node getStopPosition() {
    8386
    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 
    10287                return this.stopPosition;
    10388        }
     
    11196                return this.platform;
    11297        }
    113        
     98
    11499        public String getName() {
    115100                return this.name;
     
    138123                }
    139124
    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);
     125                // Look for a stop position within 100 m (around 0.002 degrees) of this platform:
     126
     127                LatLon platformCenter = platform.getBBox().getCenter();
     128                Double ax = platformCenter.getX() - 0.002;
     129                Double bx = platformCenter.getX() + 0.002;
     130                Double ay = platformCenter.getY() - 0.002;
     131                Double by = platformCenter.getY() + 0.002;
     132                BBox platformBBox = new BBox(ax, ay, bx, by);
     133
     134                Collection<Node> allNodes = Main.getLayerManager().getEditDataSet().getNodes();
     135                for (Node currentNode : allNodes) {
     136                        if (platformBBox.bounds(currentNode.getBBox()) && currentNode.hasTag("public_transport", "stop_position")) {
     137                                potentialStopPositions.add(currentNode);
    149138                        }
    150139                }
    151140
    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                 }
     141                // // 1) Look for any stop_area relations that this platform
     142                // // belongs to:
     143                // ArrayList<OsmPrimitive> platformList = new
     144                // ArrayList<OsmPrimitive>(1);
     145                // platformList.add(platform);
     146                // Set<Relation> platformParentRelations =
     147                // OsmPrimitive.getParentRelations(platformList);
     148                // ArrayList<Relation> stopAreaList = new ArrayList<Relation>();
     149                // for (Relation platformParentRelation : platformParentRelations) {
     150                // if (platformParentRelation.hasTag("public_transport", "stop_area")) {
     151                // stopAreaList.add(platformParentRelation);
     152                // }
     153                // }
     154                //
     155                // // 2) Get all potential stop_positions from those stop_area
     156                // relations:
     157                // for (Relation stopArea : stopAreaList) {
     158                // for (RelationMember rm : stopArea.getMembers()) {
     159                // if ((rm.hasRole("stop") || rm.hasRole("stop_entry_only") ||
     160                // rm.hasRole("stop_exit_only"))&&
     161                // rm.getType().equals(OsmPrimitiveType.NODE)
     162                // && rm.getNode().hasTag("public_transport", "stop_position")) {
     163                // potentialStopPositions.add(rm.getNode());
     164                // }
     165                // }
     166                // }
    161167
    162168                return potentialStopPositions;
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/data/PTWay.java

    r32353 r32367  
    33import java.util.ArrayList;
    44import java.util.List;
     5
     6import javax.swing.JOptionPane;
    57
    68import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/utils/RouteUtils.java

    r32353 r32367  
    6262                if (rm.getType().equals(OsmPrimitiveType.NODE)) {
    6363
    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;
     64                        if (rm.hasRole("stop") || rm.hasRole("stop_entry_only") || rm.hasRole("stop_exit_only")
     65                                        || rm.hasRole("platform") || rm.hasRole("platform_entry_only")
     66                                        || rm.hasRole("platform_exit_only")) {
     67
     68                                if (rm.getNode().hasTag("public_transport", "stop_position")
     69                                                || rm.getNode().hasTag("highway", "bus_stop")
     70                                                || rm.getNode().hasTag("public_transport", "platform")
     71                                                || rm.getNode().hasTag("public_transport", "platform_entry_only")
     72                                                || rm.getNode().hasTag("public_transport", "platform_exit_only")
     73                                                || rm.getNode().hasTag("highway", "platform")
     74                                                || rm.getNode().hasTag("highway", "platform_entry_only")
     75                                                || rm.getNode().hasTag("highway", "platform_exit_only")
     76                                                || rm.getNode().hasTag("railway", "platform")
     77                                                || rm.getNode().hasTag("railway", "platform_entry_only")
     78                                                || rm.getNode().hasTag("railway", "platform_exit_only")) {
     79                                        return true;
     80                                }
    7581                        }
    76 
    7782                }
    7883
     
    105110        public static boolean isPTWay(RelationMember rm) {
    106111
    107                 return !isPTStop(rm);
     112                if (rm.getType().equals(OsmPrimitiveType.NODE)) {
     113                        return false;
     114                }
    108115
     116                if (rm.getType().equals(OsmPrimitiveType.WAY)) {
     117                        return true;
     118                }
     119
     120                Relation nestedRelation = rm.getRelation();
     121
     122                for (RelationMember nestedRelationMember : nestedRelation.getMembers()) {
     123                        if (!nestedRelationMember.getType().equals(OsmPrimitiveType.WAY)) {
     124                                return false;
     125                        }
     126                }
     127
     128                return true;
    109129        }
    110130
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/PTAssitantValidatorTest.java

    r32353 r32367  
    3434        public static final int ERROR_CODE_END_STOP = 3141;
    3535        public static final int ERROR_CODE_SPLIT_WAY = 3142;
    36        
     36        public static final int ERROR_CODE_RELAITON_MEMBER_ROLES = 3143;
     37
    3738        public PTAssitantValidatorTest() {
    3839                super(tr("Public Transport Assistant tests"),
     
    4344        @Override
    4445        public void visit(Relation r) {
    45                
    4646
    4747                if (!RouteUtils.isTwoDirectionRoute(r)) {
    4848                        return;
    4949                }
    50                
    5150
    5251                // Download incomplete members. If the download does not work, finish.
     
    5756                        }
    5857                }
    59                
     58
    6059                if (r.hasIncompleteMembers()) {
    6160                        return;
     
    6665                WayChecker wayChecker = new WayChecker(r, this);
    6766                this.errors.addAll(wayChecker.getErrors());
    68                
    6967
    7068                if (this.errors.isEmpty()) {
     
    124122                }
    125123
    126 
    127124                ProceedDialog proceedDialog = new ProceedDialog(r.getId(), numberOfDirectionErrors, numberOfRoadTypeErrors);
    128125                int userInput = proceedDialog.getUserSelection();
     
    149146
    150147        }
    151        
    152148
    153149        /**
    154150         * Carries out the second stage of the testing: sorting
     151         *
    155152         * @param r
    156153         */
    157154        private void proceedWithSorting(Relation r) {
    158                
     155
    159156                // Check if the relation is correct, or only has a wrong sorting order:
    160157                RouteChecker routeChecker = new RouteChecker(r, this);
    161158                List<TestError> routeCheckerErrors = routeChecker.getErrors();
    162                
     159
    163160                /*- At this point, there are 3 variants:
    164161                 *
     
    170167                 *
    171168                 * */
    172                
    173                
     169
    174170                if (!routeCheckerErrors.isEmpty()) {
    175171                        // Variant 2
     
    178174                        return;
    179175                }
    180                
     176
    181177                if (!routeChecker.getHasGap()) {
    182178                        // Variant 1
    183                         // TODO: add the segments of this route to the list correct route segments             
    184                 }
    185                
     179                        // TODO: add the segments of this route to the list correct route
     180                        // segments
     181                }
     182
    186183                // Variant 3:
    187184                proceedAfterSorting(r);
    188                
    189                
    190         }
    191        
    192        
     185
     186        }
     187
    193188        private void proceedAfterSorting(Relation r) {
    194                
    195                
    196                
     189
    197190                SegmentChecker segmentChecker = new SegmentChecker(r, this);
     191
     192                // Check if the creation of the route data model in the segment checker
     193                // worked. If it did not, it means the roles in the route relation do
     194                // not match the tags of the route members.
     195                if (!segmentChecker.getErrors().isEmpty()) {
     196                        this.errors.addAll(segmentChecker.getErrors());
     197                }
     198
    198199                segmentChecker.performFirstStopTest();
    199200                segmentChecker.performLastStopTest();
     201
    200202                // TODO: perform segment test
    201203                this.errors.addAll(segmentChecker.getErrors());
     
    249251        private void fixErrorFromPlugin(List<TestError> testErrors) {
    250252
    251                        
    252                         // run fix task asynchronously
    253                         FixTask fixTask = new FixTask(testErrors);
    254 //                      Main.worker.submit(fixTask);
    255                        
    256                         Thread t = new Thread(fixTask);
    257                         t.start();
    258                         try {
    259                                 t.join();
    260                                 errors.removeAll(testErrors);
    261 
    262                         } catch (InterruptedException e) {
    263                                 JOptionPane.showMessageDialog(null, "Error occurred during fixing");
    264                         }
    265 
    266 
     253                // run fix task asynchronously
     254                FixTask fixTask = new FixTask(testErrors);
     255                // Main.worker.submit(fixTask);
     256
     257                Thread t = new Thread(fixTask);
     258                t.start();
     259                try {
     260                        t.join();
     261                        errors.removeAll(testErrors);
     262
     263                } catch (InterruptedException e) {
     264                        JOptionPane.showMessageDialog(null, "Error occurred during fixing");
     265                }
    267266
    268267        }
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/SegmentChecker.java

    r32353 r32367  
    99import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1010import org.openstreetmap.josm.data.osm.Relation;
     11import org.openstreetmap.josm.data.osm.RelationMember;
    1112import org.openstreetmap.josm.data.osm.Way;
    1213import org.openstreetmap.josm.data.validation.Severity;
     
    3435        private PTRouteDataManager manager;
    3536
    36         /* Assigns PTStops to nearest PTWays and stores that correspondense */
     37        /* Assigns PTStops to nearest PTWays and stores that correspondence */
    3738        private StopToWayAssigner assigner;
    3839
     
    4041
    4142                super(relation, test);
     43
     44                this.manager = new PTRouteDataManager(relation);
    4245               
    43                 this.manager = new PTRouteDataManager(relation);
     46                for (RelationMember rm: manager.getFailedMembers()) {
     47                        List<Relation> primitives = new ArrayList<>(1);
     48                        primitives.add(relation);
     49                        List<OsmPrimitive> highlighted = new ArrayList<>(1);
     50                        highlighted.add(rm.getMember());
     51                        TestError e = new TestError(this.test, Severity.WARNING, tr("PT: Relation member roles do not match tags"),
     52                                        PTAssitantValidatorTest.ERROR_CODE_RELAITON_MEMBER_ROLES, primitives, highlighted);
     53                        this.errors.add(e);
     54                }
     55
     56
     57               
    4458                this.assigner = new StopToWayAssigner(manager.getPTWays());
    45                
     59
    4660        }
    4761
     
    5973
    6074        private void performEndStopTest(PTStop endStop) {
     75
     76                if (endStop == null) {
     77                        return;
     78                }
    6179
    6280                /*
     
    96114                                return;
    97115                        }
    98                        
     116
    99117                        if (stopPositionsOfThisRoute.size() == 1) {
    100118                                endStop.setStopPosition(stopPositionsOfThisRoute.get(0));
     
    115133
    116134                } else {
    117                        
     135
    118136                        // if the stop_position is known:
    119137                        int belongsToWay = this.belongsToAWayOfThisRoute(endStop.getStopPosition());
    120                        
     138
    121139                        if (belongsToWay == 1) {
    122                                
     140
    123141                                List<Relation> primitives = new ArrayList<>(1);
    124142                                primitives.add(relation);
Note: See TracChangeset for help on using the changeset viewer.