Changeset 34982 in osm for applications/editors


Ignore:
Timestamp:
2019-04-20T10:11:28+02:00 (6 years ago)
Author:
gerdp
Message:

fix #17625: IAE: "Node is already deleted" at buildings_tools.MergeAddrPointsAction.actionPerformed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/buildings_tools/src/org/openstreetmap/josm/plugins/buildings_tools/MergeAddrPointsAction.java

    r34850 r34982  
    77import java.awt.event.ActionEvent;
    88import java.awt.event.KeyEvent;
    9 import java.util.AbstractMap;
    109import java.util.Collection;
    1110import java.util.Collections;
    1211import java.util.HashMap;
     12import java.util.HashSet;
    1313import java.util.LinkedList;
    1414import java.util.List;
     15import java.util.Map;
    1516import java.util.Map.Entry;
     17import java.util.Set;
    1618
    1719import javax.swing.JOptionPane;
     
    5658        List<Node> addrNodes = new LinkedList<>();
    5759        List<Way> buildings = new LinkedList<>();
    58         scanSelection:
    5960        for (OsmPrimitive p : selection) {
    6061            if (p.getType() == OsmPrimitiveType.NODE) {
     62                boolean refsOK = true;
    6163                for (OsmPrimitive r : p.getReferrers()) {
    62                     if (r.getType() == OsmPrimitiveType.WAY)
    63                        continue scanSelection; // Don't use nodes if they're referenced by ways
     64                    if (r.getType() == OsmPrimitiveType.WAY) {
     65                        // Don't use nodes if they're referenced by ways
     66                        refsOK = false;
     67                        break;
     68                    }
    6469                }
     70                if (!refsOK)
     71                    continue;
    6572                for (String key : p.getKeys().keySet()) {
    6673                    if (key.startsWith("addr:")) {
     
    8289            return;
    8390        }
     91
     92        // find nodes covered by more than one building, see #17625
     93        Map<Node, Way> nodeToWayMap = new HashMap<>();
     94        Set<Way> overlappingWays = new HashSet<>();
     95        for (Way w : buildings) {
     96            for (Node n : addrNodes) {
     97                if (Geometry.nodeInsidePolygon(n, w.getNodes())) {
     98                    Way old = nodeToWayMap.put(n, w);
     99                    if (old != null) {
     100                        overlappingWays.add(w);
     101                        overlappingWays.add(old);
     102                    }
     103                }
     104            }
     105        }
     106        buildings.removeAll(overlappingWays);
     107
    84108        List<Command> cmds = new LinkedList<>();
    85109        int multi = 0;
    86110        int conflicts = 0;
    87         buildingsLoop: for (Way w : buildings) {
     111
     112        for (Way w : buildings) {
    88113            Node mergeNode = null;
     114            int oldMulti = multi;
    89115            for (Node n : addrNodes) {
    90116                if (Geometry.nodeInsidePolygon(n, w.getNodes()))
     
    93119                        // Multiple address nodes inside one building --
    94120                        // skipping
    95                         continue buildingsLoop;
     121                        break;
    96122                    } else
    97123                        mergeNode = n;
    98124            }
     125            if (oldMulti != multi)
     126                continue;
    99127            if (mergeNode != null) {
    100128                boolean hasConflicts = false;
    101                 AbstractMap<String, String> tags = new HashMap<>();
     129                Map<String, String> tags = new HashMap<>();
    102130                for (Entry<String, String> entry : mergeNode.getKeys().entrySet()) {
    103131                    String newValue = entry.getValue();
     
    141169                            "There are {0} buildings with address conflicts", conflicts, conflicts))
    142170                    .setIcon(JOptionPane.WARNING_MESSAGE).show();
    143         if (cmds.isEmpty() && multi == 0 && conflicts == 0)
     171        if (!overlappingWays.isEmpty())
     172            new Notification(tr("There are {0} buildings covering the same address node", overlappingWays.size()))
     173                    .setIcon(JOptionPane.WARNING_MESSAGE).show();
     174        if (cmds.isEmpty() && multi == 0 && conflicts == 0 && overlappingWays.isEmpty())
    144175            new Notification(tr("No address nodes inside buildings found"))
    145176                    .setIcon(JOptionPane.INFORMATION_MESSAGE).show();
Note: See TracChangeset for help on using the changeset viewer.