Changeset 33403 in osm
- Timestamp:
- 2017-06-16T09:20:29+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/actions/SplitRoundaboutAction.java
r33399 r33403 80 80 81 81 //save the position of the roundabout inside each relation 82 Map<Relation, Integer> savedPositions = getSavedPositions(roundabout); 83 84 //split the roundabout on the designed nodes 85 List<Node> splitNodes = getSplitNodes(roundabout); 86 getLayerManager().getEditDataSet().setSelected(splitNodes); 87 new SplitWayAction().actionPerformed(null); 88 Collection<OsmPrimitive> splitWays = getLayerManager().getEditDataSet().getSelected(); 89 90 //update the relations. 91 savedPositions.forEach((r, i) -> { 92 Way previous = r.getMember(i-1).getWay(); 93 Way subsequent = r.getMember(i).getWay(); 94 Node entryNode; 95 Node exitNode; 96 97 //checking if the previous way enters the roundabout and the 98 //subsequent exits it 99 if(splitNodes.contains(previous.lastNode())) 100 entryNode = previous.lastNode(); 101 else if(splitNodes.contains(previous.firstNode())) 102 entryNode = previous.firstNode(); 103 else 104 entryNode = null; 105 106 if(splitNodes.contains(subsequent.firstNode())) 107 exitNode = subsequent.firstNode(); 108 else if (splitNodes.contains(subsequent.lastNode())) 109 exitNode = subsequent.lastNode(); 110 else 111 exitNode = null; 112 113 //if not, exit 114 if(entryNode == null || exitNode == null) 115 return; 116 117 //starting from the entry node, add split ways until the 118 //exit node is reached 119 List<Way> parents = entryNode.getParentWays(); 120 parents.removeIf(w -> !w.firstNode().equals(entryNode)); 121 parents.removeIf(w -> w.equals(previous)); 122 123 Way curr = parents.get(0); 124 int j = 0; 125 126 while(!curr.lastNode().equals(exitNode)) { 127 r.addMember(i + j++, new RelationMember(null, curr)); 128 parents = curr.lastNode().getParentWays(); 129 parents.remove(curr); 130 parents.removeIf(w -> !splitWays.contains(w)); 131 curr = parents.get(0); 132 } 133 r.addMember(i + j++, new RelationMember(null, curr)); 134 }); 135 } 136 137 //split only on the nodes which might be the 138 //entry or exit point for some public transport route 139 private List<Node> getSplitNodes(Way roundabout) { 140 List<Node> splitNodes = roundabout.getNodes(); 141 splitNodes.removeIf(n -> { 142 List<Way> parents = n.getParentWays(); 143 if(parents.size() == 1) 144 return true; 145 parents.remove(roundabout); 146 for(Way parent: parents) { 147 for(OsmPrimitive prim : parent.getReferrers()) { 148 if(prim.getType() == OsmPrimitiveType.RELATION && 149 RouteUtils.isTwoDirectionRoute((Relation) prim)) 150 return false; 151 } 152 } 153 154 return true; 155 }); 156 return splitNodes; 157 } 158 159 //save the position of the roundabout inside each public transport route 160 //it is contained in 161 private Map<Relation, Integer> getSavedPositions(Way roundabout) { 162 82 163 Map<Relation, Integer> savedPositions = new HashMap<>(); 83 164 List <OsmPrimitive> referrers = roundabout.getReferrers(); … … 95 176 } 96 177 97 //split the roundabout 98 List<Node> splitNodes = roundabout.getNodes(); 99 splitNodes.removeIf(n -> n.getParentWays().size() != 2); 100 getLayerManager().getEditDataSet().setSelected(splitNodes); 101 new SplitWayAction().actionPerformed(null); 102 Collection<OsmPrimitive> splittedWays = getLayerManager().getEditDataSet().getSelected(); 103 104 //update the relations 105 savedPositions.forEach((r, i) -> { 106 Way previous = r.getMember(i-1).getWay(); 107 Way next = r.getMember(i).getWay(); 108 if(splitNodes.contains(previous.lastNode()) && splitNodes.contains(next.firstNode())) { 109 //lucky case: the ways were in order and the whole left by 110 //removing the roundabout can be easily filled with the splitted 111 //segment(s) that has as the first and last node the two just checked 112 113 List<Way> parents = previous.lastNode().getParentWays(); 114 parents.removeIf(w -> !w.firstNode().equals(previous.lastNode())); 115 116 Way curr = parents.get(0); 117 int j = 0; 118 119 while(!curr.lastNode().equals(next.firstNode())) { 120 r.addMember(i + j++, new RelationMember(null, curr)); 121 parents = curr.lastNode().getParentWays(); 122 parents.remove(curr); 123 parents.removeIf(w -> !splittedWays.contains(w)); 124 curr = parents.get(0); 125 } 126 r.addMember(i + j++, new RelationMember(null, curr)); 127 } 128 }); 178 return savedPositions; 129 179 } 130 180
Note:
See TracChangeset
for help on using the changeset viewer.