Ignore:
Timestamp:
2017-08-22T11:11:28+02:00 (7 years ago)
Author:
giackserva
Message:

[pt_assistant] #josm15176 - same name stops handled + comments on the code

File:
1 edited

Legend:

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

    r33511 r33512  
    105105        }
    106106
     107        //first loop trough all the members and remove the roles
    107108        List<RelationMember> members = new ArrayList<>();
    108109        List<RelationMember> oldMembers = rel.getMembers();
     
    115116            rel.removeMember(0);
    116117        }
     118
     119        //sort the members with the built in sorting function in order to get
     120        //the continuity of the ways
    117121        members = new RelationSorter().sortMembers(members);
    118122
     123        //divide stops and ways
    119124        List<RelationMember> stops = new ArrayList<>();
    120125        List<RelationMember> wayMembers = new ArrayList<>();
     
    131136        }
    132137
    133         Map<String, PTStop> stopsByName = new HashMap<>();
     138        //couple together stop positions and platforms that are part of the same
     139        //stop. the only way used to determine whether they are part of the same
     140        //stop or not is the name. this should be improved by using also the
     141        //distance
     142        Map<String, List<PTStop>> stopsByName = new HashMap<>();
    134143        List<PTStop> unnamed = new ArrayList<>();
    135144        stops.forEach(rm -> {
     
    137146            if (name != null) {
    138147                if (!stopsByName.containsKey(name))
    139                     stopsByName.put(name, new PTStop(rm));
    140                 else
    141                     stopsByName.get(name).addStopElement(rm);
     148                    stopsByName.put(name, new ArrayList<>());
     149                List<PTStop> ls = stopsByName.get(name);
     150                if (ls.isEmpty()) {
     151                    ls.add(new PTStop(rm));
     152                } else {
     153                    PTStop stp = ls.get(ls.size() - 1);
     154                    if (!stp.addStopElement(rm)) {
     155                        ls.add(new PTStop(rm));
     156                    }
     157                }
    142158            } else {
    143159                unnamed.add(new PTStop(rm));
     
    145161        });
    146162
     163        //assign to each stop the corresponding way. if none is found add already
     164        //the stop to the relation since it is not possible to reason on the order
    147165        StopToWayAssigner assigner = new StopToWayAssigner(ways);
    148         List<PTStop> ptstops = new ArrayList<>(stopsByName.values());
     166        List<PTStop> ptstops = new ArrayList<>();
     167        stopsByName.values().forEach(ptstops::addAll);
    149168        Map<Way, List<PTStop>> wayStop = new HashMap<>();
    150169        ptstops.forEach(stop -> {
     
    168187        });
    169188
     189        //based on the order of the ways, add the stops to the relation
    170190        for (int i = 0; i < wayMembers.size(); i++) {
    171191            RelationMember wm = wayMembers.get(i);
     
    187207                List<PTStop> stps = wayStop.get(curr);
    188208                if (stps != null) {
     209                    //if for one way there are more than one stop assigned to it,
     210                    //another sorting step is needed
    189211                    if (stps.size() > 1)
    190212                        stps = sortSameWayStops(stps, curr, prev, next);
     
    208230    }
    209231
     232    //sorts the stops that are assigned to the same way. this is done based on
     233    //the distance from the previous way.
    210234    private static List<PTStop> sortSameWayStops(List<PTStop> stps, Way way, Way prev, Way next) {
    211235        Map<Node, List<PTStop>> closeNodes = new HashMap<>();
Note: See TracChangeset for help on using the changeset viewer.