Changeset 17361 in osm for applications/editors
- Timestamp:
- 2009-08-30T17:49:38+02:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/utilsplugin
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/utilsplugin/build.xml
r16687 r17361 25 25 <attribute name="Plugin-Date" value="${version.entry.commit.date}"/> 26 26 <attribute name="Plugin-Description" value="Several utilities that make your life easier: e.g. simplify way, join areas, jump to position."/> 27 <attribute name="Plugin-Mainversion" value=" 1823"/>27 <attribute name="Plugin-Mainversion" value="2012"/> 28 28 <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/> 29 29 </manifest> -
applications/editors/josm/plugins/utilsplugin/src/UtilsPlugin/JoinAreasAction.java
r16735 r17361 142 142 143 143 // This is copied from SimplifyAction and should be probably ported to tools 144 for (Node node : way. nodes) {144 for (Node node : way.getNodes()) { 145 145 if(askedAlready) break; 146 146 boolean isInsideOneBoundingBox = false; … … 327 327 private ArrayList<OsmPrimitive> addIntersections(Way a, Way b) { 328 328 boolean same = a.equals(b); 329 int nodesSizeA = a. nodes.size();330 int nodesSizeB = b. nodes.size();329 int nodesSizeA = a.getNodesCount(); 330 int nodesSizeB = b.getNodesCount(); 331 331 332 332 // We use OsmPrimitive here instead of Node because we later need to split a way at these nodes. … … 339 339 for (int j = (same ? i + 2 : 0); j < nodesSizeB - 1; j++) { 340 340 // Avoid re-adding nodes that already exist on (some) intersections 341 if(a. nodes.get(i).equals(b.nodes.get(j)) || a.nodes.get(i+1).equals(b.nodes.get(j))) {342 nodes.add(b. nodes.get(j));341 if(a.getNode(i).equals(b.getNode(j)) || a.getNode(i+1).equals(b.getNode(j))) { 342 nodes.add(b.getNode(j)); 343 343 continue; 344 344 } else 345 if(a. nodes.get(i).equals(b.nodes.get(j+1)) || a.nodes.get(i+1).equals(b.nodes.get(j+1))) {346 nodes.add(b. nodes.get(j+1));345 if(a.getNode(i).equals(b.getNode(j+1)) || a.getNode(i+1).equals(b.getNode(j+1))) { 346 nodes.add(b.getNode(j+1)); 347 347 continue; 348 348 } 349 349 LatLon intersection = getLineLineIntersection( 350 a. nodes.get(i) .getEastNorth().east(), a.nodes.get(i) .getEastNorth().north(),351 a. nodes.get(i+1).getEastNorth().east(), a.nodes.get(i+1).getEastNorth().north(),352 b. nodes.get(j) .getEastNorth().east(), b.nodes.get(j) .getEastNorth().north(),353 b. nodes.get(j+1).getEastNorth().east(), b.nodes.get(j+1).getEastNorth().north());350 a.getNode(i) .getEastNorth().east(), a.getNode(i) .getEastNorth().north(), 351 a.getNode(i+1).getEastNorth().east(), a.getNode(i+1).getEastNorth().north(), 352 b.getNode(j) .getEastNorth().east(), b.getNode(j) .getEastNorth().north(), 353 b.getNode(j+1).getEastNorth().east(), b.getNode(j+1).getEastNorth().north()); 354 354 if(intersection == null) continue; 355 355 … … 359 359 nodes.add(n); 360 360 // The distance is needed to sort and add the nodes in direction of the way 361 nodesA.add(new NodeToSegs(i, n, a. nodes.get(i).getCoor()));361 nodesA.add(new NodeToSegs(i, n, a.getNode(i).getCoor())); 362 362 if(same) 363 nodesA.add(new NodeToSegs(j, n, a. nodes.get(j).getCoor()));363 nodesA.add(new NodeToSegs(j, n, a.getNode(j).getCoor())); 364 364 else 365 nodesB.add(new NodeToSegs(j, n, b. nodes.get(j).getCoor()));365 nodesB.add(new NodeToSegs(j, n, b.getNode(j).getCoor())); 366 366 } 367 367 } … … 508 508 private Collection<Node> getNodesFromWays(Collection<Way> ways) { 509 509 Collection<Node> allNodes = new ArrayList<Node>(); 510 for(Way w: ways) allNodes.addAll(w. nodes);510 for(Way w: ways) allNodes.addAll(w.getNodes()); 511 511 return allNodes; 512 512 } … … 524 524 for(Way w: multigonWays) { 525 525 Polygon poly = new Polygon(); 526 for(Node n: (w). nodes) poly.addPoint(latlonToXY(n.getCoor().lat()), latlonToXY(n.getCoor().lon()));526 for(Node n: (w).getNodes()) poly.addPoint(latlonToXY(n.getCoor().lat()), latlonToXY(n.getCoor().lon())); 527 527 528 528 for(Node n: multigonNodes) { 529 if(!(w). nodes.contains(n) && poly.contains(latlonToXY(n.getCoor().lat()), latlonToXY(n.getCoor().lon()))) {529 if(!(w).containsNode(n) && poly.contains(latlonToXY(n.getCoor().lat()), latlonToXY(n.getCoor().lon()))) { 530 530 getWaysByNode(innerWays, multigonWays, n); 531 531 } … … 549 549 private void getWaysByNode(Collection<Way> innerWays, Collection<Way> w, Node n) { 550 550 for(Way way : w) { 551 if(!(way). nodes.contains(n)) continue;551 if(!(way).containsNode(n)) continue; 552 552 if(!innerWays.contains(way)) innerWays.add(way); // Will need this later for multigons 553 553 } … … 566 566 if(innerWays.contains(w)) continue; 567 567 568 if(w. nodes.size() <= 2)568 if(w.getNodesCount() <= 2) 569 569 cmds.add(new DeleteCommand(w)); 570 570 else … … 608 608 continue; 609 609 } 610 if(a. nodes.get(0).equals(b.nodes.get(0)) ||611 a. nodes.get(a.nodes.size()-1).equals(b.nodes.get(b.nodes.size()-1))) {610 if(a.getNode(0).equals(b.getNode(0)) || 611 a.getNode(a.getNodesCount()-1).equals(b.getNode(b.getNodesCount()-1))) { 612 612 Main.main.getCurrentDataSet().setSelected(b); 613 613 new ReverseWayAction().actionPerformed(null); … … 634 634 private ArrayList<Way> fixMultigons(Collection<Way> uninterestingWays, Way outerWay) { 635 635 Collection<Node> innerNodes = getNodesFromWays(uninterestingWays); 636 Collection<Node> outerNodes = outerWay. nodes;636 Collection<Node> outerNodes = outerWay.getNodes(); 637 637 638 638 // The newly created inner ways. uninterestingWays is passed by reference and therefore modified in-place … … 646 646 wayIterator: for(Way w : uninterestingWays) { 647 647 boolean hasInnerNodes = false; 648 for(Node n : w. nodes) {648 for(Node n : w.getNodes()) { 649 649 if(outerNodes.contains(n)) continue wayIterator; 650 650 if(!hasInnerNodes && innerNodes.contains(n)) hasInnerNodes = true; 651 651 } 652 if(!hasInnerNodes || w. nodes.size() < 2) continue;652 if(!hasInnerNodes || w.getNodesCount() < 2) continue; 653 653 possibleWays.add(w); 654 654 } … … 703 703 for(int j=i+1; j < ways.size(); j++) { 704 704 Way b = ways.get(j); 705 List<Node> revNodes = new ArrayList<Node>(b. nodes);705 List<Node> revNodes = new ArrayList<Node>(b.getNodes()); 706 706 Collections.reverse(revNodes); 707 if(a. nodes.equals(b.nodes) || a.nodes.equals(revNodes)) {707 if(a.getNodes().equals(b.getNodes()) || a.getNodes().equals(revNodes)) { 708 708 removables.add(a); 709 709 continue outer; … … 745 745 */ 746 746 private boolean wayIsCollapsed(Way w) { 747 if(w. nodes.size() <= 3) return true;747 if(w.getNodesCount() <= 3) return true; 748 748 749 749 // If a way contains more than one node twice, it must be collapsed (only start/end node may be the same) 750 750 Way x = new Way(w); 751 751 int count = 0; 752 for(Node n : w. nodes) {753 x. nodes.remove(n);754 if(x. nodes.contains(n)) count++;752 for(Node n : w.getNodes()) { 753 x.removeNode(n); 754 if(x.containsNode(n)) count++; 755 755 if(count == 2) return true; 756 756 } … … 767 767 if(w1.equals(w2)) return false; 768 768 769 if(w1. nodes.get(0).equals(w2.nodes.get(0))) return true;770 if(w1. nodes.get(0).equals(w2.nodes.get(w2.nodes.size()-1))) return true;771 772 if(w1. nodes.get(w1.nodes.size()-1).equals(w2.nodes.get(0))) return true;773 if(w1. nodes.get(w1.nodes.size()-1).equals(w2.nodes.get(w2.nodes.size()-1))) return true;769 if(w1.getNode(0).equals(w2.getNode(0))) return true; 770 if(w1.getNode(0).equals(w2.getNode(w2.getNodesCount()-1))) return true; 771 772 if(w1.getNode(w1.getNodesCount()-1).equals(w2.getNode(0))) return true; 773 if(w1.getNode(w1.getNodesCount()-1).equals(w2.getNode(w2.getNodesCount()-1))) return true; 774 774 775 775 return false; … … 839 839 if(!newRel.members.contains(rm)) newRel.members.add(rm); 840 840 // Add tags 841 for (String key : r.rel.key s.keySet()) {842 newRel.put(key, r.rel. keys.get(key));841 for (String key : r.rel.keySet()) { 842 newRel.put(key, r.rel.get(key)); 843 843 } 844 844 // Delete old relation … … 862 862 */ 863 863 private void stripTags(Way x) { 864 if(x. keys== null) return;864 if(x.getKeys() == null) return; 865 865 Way y = new Way(x); 866 for (String key : x.key s.keySet())866 for (String key : x.keySet()) 867 867 y.remove(key); 868 868 cmds.add(new ChangeCommand(x, y)); -
applications/editors/josm/plugins/utilsplugin/src/UtilsPlugin/SimplifyWayAction.java
r16628 r17361 11 11 import java.util.HashSet; 12 12 import java.util.LinkedList; 13 import java.util.List; 13 14 14 15 import javax.swing.JOptionPane; … … 52 53 // bounding box. Otherwise nodes may get deleted that are necessary by 53 54 // unloaded ways (see Ticket #1594) 54 for (Node node : way. nodes) {55 for (Node node : way.getNodes()) { 55 56 boolean isInsideOneBoundingBox = false; 56 57 for (Bounds b : bounds) { … … 105 106 Way wnew = new Way(w); 106 107 107 int toI = wnew. nodes.size() - 1;108 for (int i = wnew. nodes.size() - 1; i >= 0; i--) {108 int toI = wnew.getNodesCount() - 1; 109 for (int i = wnew.getNodesCount() - 1; i >= 0; i--) { 109 110 CollectBackReferencesVisitor backRefsV = new CollectBackReferencesVisitor(Main.main.getCurrentDataSet(), false); 110 backRefsV.visit(wnew. nodes.get(i));111 backRefsV.visit(wnew.getNode(i)); 111 112 boolean used = false; 112 113 if (backRefsV.data.size() == 1) { 113 used = Collections.frequency(w. nodes, wnew.nodes.get(i)) > 1;114 used = Collections.frequency(w.getNodes(), wnew.getNode(i)) > 1; 114 115 } else { 115 116 backRefsV.data.remove(w); … … 117 118 } 118 119 if (!used) 119 used = wnew. nodes.get(i).isTagged();120 used = wnew.getNode(i).isTagged(); 120 121 121 122 if (used) { … … 127 128 128 129 HashSet<Node> delNodes = new HashSet<Node>(); 129 delNodes.addAll(w. nodes);130 delNodes.removeAll(wnew. nodes);131 132 if (wnew. nodes.size() != w.nodes.size()) {130 delNodes.addAll(w.getNodes()); 131 delNodes.removeAll(wnew.getNodes()); 132 133 if (wnew.getNodesCount() != w.getNodesCount()) { 133 134 Collection<Command> cmds = new LinkedList<Command>(); 134 135 cmds.add(new ChangeCommand(w, wnew)); … … 143 144 ArrayList<Node> ns = new ArrayList<Node>(); 144 145 simplifyWayRange(wnew, from, to, ns, thr); 145 for (int j = to - 1; j > from; j--) 146 wnew.nodes.remove(j); 147 wnew.nodes.addAll(from + 1, ns); 146 List<Node> nodes = wnew.getNodes(); 147 for (int j = to - 1; j > from; j--) { 148 nodes.remove(j); 149 } 150 nodes.addAll(from + 1, ns); 151 wnew.setNodes(nodes); 148 152 } 149 153 } … … 154 158 */ 155 159 public void simplifyWayRange(Way wnew, int from, int to, ArrayList<Node> ns, double thr) { 156 Node fromN = wnew. nodes.get(from), toN = wnew.nodes.get(to);160 Node fromN = wnew.getNode(from), toN = wnew.getNode(to); 157 161 158 162 int imax = -1; 159 163 double xtemax = 0; 160 164 for (int i = from + 1; i < to; i++) { 161 Node n = wnew. nodes.get(i);165 Node n = wnew.getNode(i); 162 166 double xte = Math.abs(EARTH_RAD 163 167 * xtd(fromN.getCoor().lat() * Math.PI / 180, fromN.getCoor().lon() * Math.PI / 180, toN.getCoor().lat() * Math.PI … … 172 176 if (imax != -1 && xtemax >= thr) { 173 177 simplifyWayRange(wnew, from, imax, ns, thr); 174 ns.add(wnew. nodes.get(imax));178 ns.add(wnew.getNode(imax)); 175 179 simplifyWayRange(wnew, imax, to, ns, thr); 176 180 }
Note:
See TracChangeset
for help on using the changeset viewer.