Ticket #5531: merge-node-averaging.patch

File merge-node-averaging.patch, 1.5 KB (added by *Martin*, 16 years ago)
  • src/org/openstreetmap/josm/actions/MergeNodesAction.java

     
    2525import org.openstreetmap.josm.command.Command;
    2626import org.openstreetmap.josm.command.DeleteCommand;
    2727import org.openstreetmap.josm.command.SequenceCommand;
     28import org.openstreetmap.josm.data.coor.LatLon;
    2829import org.openstreetmap.josm.data.osm.Node;
    2930import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3031import org.openstreetmap.josm.data.osm.RelationToChildReference;
     
    8788     * @return the coordinates of this node are later used for the target node
    8889     */
    8990    public static Node selectTargetLocationNode(LinkedHashSet<Node> candidates) {
    90         Node targetNode = null;
    91         for (Node n : candidates) { // pick last one
    92             targetNode = n;
     91        if (!Main.pref.getBoolean("merge.average-location", false)) {
     92            Node targetNode = null;
     93            for (final Node n : candidates) { // pick last one
     94                targetNode = n;
     95            }
     96            return targetNode;
    9397        }
    94         return targetNode;
     98
     99        double lat = 0, lon = 0;
     100        for (final Node n : candidates) {
     101            lat += n.getCoor().lat();
     102            lon += n.getCoor().lon();
     103        }
     104
     105        return new Node(new LatLon(lat / candidates.size(), lon / candidates.size()));
    95106    }
    96107
    97108    /**