Changeset 4315 in josm
- Timestamp:
- 2011-08-13T11:19:16+02:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/MergeNodesAction.java
r4310 r4315 2 2 package org.openstreetmap.josm.actions; 3 3 4 import static org.openstreetmap.josm.gui.conflict.tags.TagConflictResolutionUtil.combineTigerTags;5 import static org.openstreetmap.josm.gui.conflict.tags.TagConflictResolutionUtil.completeTagCollectionForEditing;6 import static org.openstreetmap.josm.gui.conflict.tags.TagConflictResolutionUtil.normalizeTagCollectionBeforeEditing;7 4 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 8 5 import static org.openstreetmap.josm.tools.I18n.tr; … … 25 22 import org.openstreetmap.josm.command.DeleteCommand; 26 23 import org.openstreetmap.josm.command.SequenceCommand; 24 import org.openstreetmap.josm.data.coor.EastNorth; 27 25 import org.openstreetmap.josm.data.coor.LatLon; 28 26 import org.openstreetmap.josm.data.osm.Node; … … 35 33 import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec; 36 34 import org.openstreetmap.josm.gui.conflict.tags.CombinePrimitiveResolverDialog; 35 import org.openstreetmap.josm.gui.conflict.tags.TagConflictResolutionUtil; 37 36 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 38 37 import org.openstreetmap.josm.tools.CheckParameterUtil; 39 38 import org.openstreetmap.josm.tools.ImageProvider; 40 39 import org.openstreetmap.josm.tools.Shortcut; 40 41 41 /** 42 42 * Merges a collection of nodes into one node. … … 94 94 */ 95 95 public static Node selectTargetLocationNode(List<Node> candidates) { 96 if (! Main.pref.getBoolean("merge-nodes.average-location", false)) { 97 Node targetNode = null; 96 int size = candidates.size(); 97 if (size == 0) 98 throw new IllegalArgumentException("empty list"); 99 100 switch (Main.pref.getInteger("merge-nodes.mode", 0)) { 101 case 0: { 102 Node targetNode = candidates.get(size - 1); 98 103 for (final Node n : candidates) { // pick last one 99 104 targetNode = n; … … 101 106 return targetNode; 102 107 } 103 104 double lat = 0, lon = 0; 105 for (final Node n : candidates) { 106 lat += n.getCoor().lat(); 107 lon += n.getCoor().lon(); 108 } 109 110 return new Node(new LatLon(lat / candidates.size(), lon / candidates.size())); 108 case 1: { 109 double east = 0, north = 0; 110 for (final Node n : candidates) { 111 east += n.getEastNorth().east(); 112 north += n.getEastNorth().north(); 113 } 114 115 return new Node(new EastNorth(east / size, north / size)); 116 } 117 case 2: { 118 final double[] weights = new double[size]; 119 120 for (int i = 0; i < size; i++) { 121 final LatLon c1 = candidates.get(i).getCoor(); 122 for (int j = i + 1; j < size; j++) { 123 final LatLon c2 = candidates.get(j).getCoor(); 124 final double d = c1.distance(c2); 125 weights[i] += d; 126 weights[j] += d; 127 } 128 } 129 130 double east = 0, north = 0, weight = 0; 131 for (int i = 0; i < size; i++) { 132 final EastNorth en = candidates.get(i).getEastNorth(); 133 final double w = weights[i]; 134 east += en.east() * w; 135 north += en.north() * w; 136 weight += w; 137 } 138 139 return new Node(new EastNorth(east / weight, north / weight)); 140 } 141 default: 142 throw new RuntimeException("unacceptable merge-nodes.mode"); 143 } 144 111 145 } 112 146 … … 231 265 // 232 266 TagCollection nodeTags = TagCollection.unionOfAllPrimitives(nodes); 233 combineTigerTags(nodeTags);234 normalizeTagCollectionBeforeEditing(nodeTags, nodes);267 TagConflictResolutionUtil.combineTigerTags(nodeTags); 268 TagConflictResolutionUtil.normalizeTagCollectionBeforeEditing(nodeTags, nodes); 235 269 TagCollection nodeTagsToEdit = new TagCollection(nodeTags); 236 completeTagCollectionForEditing(nodeTagsToEdit);270 TagConflictResolutionUtil.completeTagCollectionForEditing(nodeTagsToEdit); 237 271 238 272 // launch a conflict resolution dialog, if necessary
Note:
See TracChangeset
for help on using the changeset viewer.