Ticket #6696: merge.patch
File merge.patch, 2.7 KB (added by , 13 years ago) |
---|
-
src/org/openstreetmap/josm/actions/MergeNodesAction.java
93 93 * @return the coordinates of this node are later used for the target 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; 100 105 } 101 106 return targetNode; 102 107 } 108 case 1: { 109 double lat = 0, lon = 0; 110 for (final Node n : candidates) { 111 lat += n.getCoor().lat(); 112 lon += n.getCoor().lon(); 113 } 103 114 104 double lat = 0, lon = 0; 105 for (final Node n : candidates) { 106 lat += n.getCoor().lat(); 107 lon += n.getCoor().lon(); 115 return new Node(new LatLon(lat / size, lon / size)); // TODO: not exact for long distances 108 116 } 117 case 2: { 118 class WeightCoord { 119 LatLon latLon; 120 double weight; 121 } 109 122 110 return new Node(new LatLon(lat / candidates.size(), lon / candidates.size())); 123 List<WeightCoord> wcl = new ArrayList<WeightCoord>(); 124 double weight = 0; 125 for (int i = 0; i < size; i++) { 126 for (int j = i + 1; j < size; j++) { 127 final LatLon c1 = candidates.get(i).getCoor(); 128 final LatLon c2 = candidates.get(j).getCoor(); 129 130 WeightCoord wc = new WeightCoord(); 131 wc.latLon = c1.interpolate(c2, 0.5); 132 wc.weight = c1.greatCircleDistance(c2); 133 wcl.add(wc); 134 weight += wc.weight; 135 } 136 } 137 138 double lat = 0, lon = 0; 139 for (final WeightCoord wc : wcl) { 140 lat += wc.latLon.lat() * wc.weight; 141 lon += wc.latLon.lon() * wc.weight; 142 } 143 144 return new Node(new LatLon(lat / weight, lon / weight)); // TODO: not exact for long distances 145 } 146 default: 147 throw new RuntimeException("unacceptable merge-nodes.mode"); 148 } 149 150 111 151 } 112 152 113 153 /**