Changeset 33512 in osm for applications/editors/josm/plugins/pt_assistant/src
- Timestamp:
- 2017-08-22T11:11:28+02:00 (7 years ago)
- 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 105 105 } 106 106 107 //first loop trough all the members and remove the roles 107 108 List<RelationMember> members = new ArrayList<>(); 108 109 List<RelationMember> oldMembers = rel.getMembers(); … … 115 116 rel.removeMember(0); 116 117 } 118 119 //sort the members with the built in sorting function in order to get 120 //the continuity of the ways 117 121 members = new RelationSorter().sortMembers(members); 118 122 123 //divide stops and ways 119 124 List<RelationMember> stops = new ArrayList<>(); 120 125 List<RelationMember> wayMembers = new ArrayList<>(); … … 131 136 } 132 137 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<>(); 134 143 List<PTStop> unnamed = new ArrayList<>(); 135 144 stops.forEach(rm -> { … … 137 146 if (name != null) { 138 147 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 } 142 158 } else { 143 159 unnamed.add(new PTStop(rm)); … … 145 161 }); 146 162 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 147 165 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); 149 168 Map<Way, List<PTStop>> wayStop = new HashMap<>(); 150 169 ptstops.forEach(stop -> { … … 168 187 }); 169 188 189 //based on the order of the ways, add the stops to the relation 170 190 for (int i = 0; i < wayMembers.size(); i++) { 171 191 RelationMember wm = wayMembers.get(i); … … 187 207 List<PTStop> stps = wayStop.get(curr); 188 208 if (stps != null) { 209 //if for one way there are more than one stop assigned to it, 210 //another sorting step is needed 189 211 if (stps.size() > 1) 190 212 stps = sortSameWayStops(stps, curr, prev, next); … … 208 230 } 209 231 232 //sorts the stops that are assigned to the same way. this is done based on 233 //the distance from the previous way. 210 234 private static List<PTStop> sortSameWayStops(List<PTStop> stps, Way way, Way prev, Way next) { 211 235 Map<Node, List<PTStop>> closeNodes = new HashMap<>();
Note:
See TracChangeset
for help on using the changeset viewer.