Changeset 15873 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2020-02-17T11:39:42+01:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java
r15854 r15873 20 20 import java.util.Set; 21 21 import java.util.TreeMap; 22 import java.util.stream.Collectors; 22 23 23 24 import javax.swing.JOptionPane; … … 641 642 if (removedDuplicates) { 642 643 hasChanges = true; 644 Set<Node> oldNodes = new LinkedHashSet<>(); 645 allStartingWays.forEach(w -> oldNodes.addAll(w.getNodes())); 643 646 commitCommands(marktr("Removed duplicate nodes")); 647 // remove now unconnected nodes without tags 648 List<Node> toRemove = oldNodes.stream().filter( 649 n -> (n.isNew() || !n.isOutsideDownloadArea()) && !n.hasKeys() && n.getReferrers().isEmpty()) 650 .collect(Collectors.toList()); 651 if (!toRemove.isEmpty()) { 652 cmds.add(new DeleteCommand(toRemove)); 653 commitCommands("Removed nodes"); 654 } 644 655 } 645 656 … … 761 772 762 773 /** 763 * This method removes duplicate points (if any) from the input way .774 * This method removes duplicate points (if any) from the input ways. 764 775 * @param ways the ways to process 765 776 * @return {@code true} if any changes where made 766 777 */ 767 778 private boolean removeDuplicateNodes(List<Way> ways) { 768 //TODO: maybe join nodes with JoinNodesAction, rather than reconnect the ways.769 770 779 Map<Node, Node> nodeMap = new TreeMap<>(new NodePositionComparator()); 771 int total NodesRemoved = 0;780 int totalWaysModified = 0; 772 781 773 782 for (Way way : ways) { … … 776 785 } 777 786 778 int nodesRemoved = 0;779 787 List<Node> newNodes = new ArrayList<>(); 780 788 Node prevNode = null; 789 boolean modifyWay = false; 781 790 782 791 for (Node node : way.getNodes()) { 783 if (!nodeMap.containsKey(node)) { 792 Node representator = nodeMap.get(node); 793 if (representator == null) { 784 794 //new node 785 795 nodeMap.put(node, node); 786 787 //avoid duplicate nodes 788 if (prevNode != node) { 789 newNodes.add(node); 790 } else { 791 nodesRemoved++; 792 } 796 representator = node; 793 797 } else { 794 798 //node with same coordinates already exists, substitute with existing node 795 Node representator = nodeMap.get(node);796 797 799 if (representator != node) { 798 nodesRemoved++;800 modifyWay = true; 799 801 } 800 801 //avoid duplicate node 802 if (prevNode != representator) { 803 newNodes.add(representator); 804 } 805 } 806 prevNode = node; 807 } 808 809 if (nodesRemoved > 0) { 802 } 803 //avoid duplicate node 804 if (prevNode != representator) { 805 newNodes.add(representator); 806 prevNode = representator; 807 } else { 808 modifyWay = true; 809 } 810 } 811 812 if (modifyWay) { 810 813 811 814 if (newNodes.size() == 1) { //all nodes in the same coordinate - add one more node, to have closed way. … … 816 819 newWay.setNodes(newNodes); 817 820 cmds.add(new ChangeCommand(way, newWay)); 818 totalNodesRemoved += nodesRemoved; 819 } 820 } 821 822 return totalNodesRemoved > 0; 821 ++totalWaysModified; 822 } 823 } 824 return totalWaysModified > 0; 823 825 } 824 826
Note:
See TracChangeset
for help on using the changeset viewer.