Changeset 20548 in osm for applications/editors/josm


Ignore:
Timestamp:
2010-03-18T22:12:11+01:00 (14 years ago)
Author:
pieren
Message:

nodes consolidation added

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/Buildings.java

    r20484 r20548  
    163163                        Node nearestNode = getNearestNode(way2.getNode(i));
    164164                        if (nearestNode == null) {
     165                            // check if we can join new node to existing ways
    165166                            List<WaySegment> wss = getNearestWaySegments(way2.getNode(i));
    166167                            wayToAdd.addNode(way2.getNode(i));
    167168                            cmds.add(new AddCommand(way2.getNode(i)));
    168                             if (wss.size() > 0)
     169                            if (wss.size() > 0) {
    169170                                cmds.add(new MoveCommand(way2.getNode(i), dx, dy));
    170171                                joinNodeToExistingWays(wss, way2.getNode(i), cmds);
    171                         } else {// reuse the existing node
     172                            }
     173                        } else {
     174                            // replace new node by an existing nearest node
    172175                            wayToAdd.addNode(nearestNode);
    173176                            cmds.add(new MoveCommand(nearestNode, dx, dy));
    174177                        }
    175                         if (i>0)
    176                             joinExistingNodesInNewSegment(way2.getNode(i-1), way2.getNode(i));
    177                     }
    178                     wayToAdd.addNode(wayToAdd.getNode(0));
     178                    }
     179                    wayToAdd.addNode(wayToAdd.getNode(0)); // close the polygon !
     180                    for (int i = 1; i < wayToAdd.getNodesCount(); i++) {
     181                        List<Node> nodesToJoin = existingNodesInNewSegment(wayToAdd.getNode(i-1), wayToAdd.getNode(i));
     182                        // check if we join new way to existing nodes
     183                        while (nodesToJoin != null && nodesToJoin.size() > 0) {
     184                            List<WaySegment> wss = new LinkedList<WaySegment>();
     185                            wss.add(new WaySegment(wayToAdd, i-1));
     186                            wayToAdd = joinNodeToExistingWays(wss, nodesToJoin.get(0), cmds);
     187                            nodesToJoin = existingNodesInNewSegment(wayToAdd.getNode(i-1), wayToAdd.getNode(i));
     188                        }
     189                    }
    179190                    cmds.add(new AddCommand(wayToAdd));
    180191                    if (clickOnBuilding)
     
    413424    }
    414425   
    415     private void joinExistingNodesInNewSegment(Node n1, Node n2) {
    416         // TODO
    417         double minx = Math.min(n1.getEastNorth().getX(), n2.getEastNorth().getX());
    418         double miny = Math.min(n1.getEastNorth().getY(), n2.getEastNorth().getY());
    419         double maxx = Math.max(n1.getEastNorth().getX(), n2.getEastNorth().getX());
    420         double maxy = Math.max(n1.getEastNorth().getY(), n2.getEastNorth().getY());
    421         BBox bbox = new BBox(minx-snapDistance, miny-snapDistance, maxx+snapDistance, maxy+snapDistance);
     426    private List<Node> existingNodesInNewSegment(Node n1, Node n2) {
     427        double minx = Math.min(n1.getEastNorth().getX(), n2.getEastNorth().getX())*100;
     428        double miny = Math.min(n1.getEastNorth().getY(), n2.getEastNorth().getY())*100;
     429        double maxx = Math.max(n1.getEastNorth().getX(), n2.getEastNorth().getX())*100;
     430        double maxy = Math.max(n1.getEastNorth().getY(), n2.getEastNorth().getY())*100;
     431        if ((maxx-minx)/2 < snapDistance && (maxy-miny)/2 < snapDistance) {
     432            return null;
     433        }
     434        BBox bbox = new BBox( Main.proj.eastNorth2latlon(new EastNorth((minx+snapDistance)/100, (miny+snapDistance)/100)),
     435                Main.proj.eastNorth2latlon(new EastNorth((maxx-snapDistance)/100, (maxy-snapDistance)/100)));
    422436        DataSet ds = getCurrentDataSet();
    423437        if (ds == null)
    424             return;
    425         List<Node> ln = ds.searchNodes(bbox);
    426         int i=0;
    427         for (Node n:ln)
     438            return null;
     439        List<Node> ret = new ArrayList<Node>();
     440        for (Node n:ds.searchNodes(bbox))
    428441            if (n.isUsable())
    429                 i++;
    430         System.out.println("usable nodes in boxe="+i);
    431     }
    432    
    433     private void joinNodeToExistingWays(List<WaySegment> wss, Node newNode, Collection<Command> cmds) {
     442                ret.add(n);
     443        System.out.println("Join "+ret.size()+" nodes to new segment");
     444        return ret;
     445    }
     446   
     447    private Way joinNodeToExistingWays(List<WaySegment> wss, Node newNode, Collection<Command> cmds) {
    434448        HashMap<Way, List<Integer>> insertPoints = new HashMap<Way, List<Integer>>();
    435449        for (WaySegment ws : wss) {
     
    442456            }
    443457
    444             if (ws.way.getNode(ws.lowerIndex) != newNode
    445                     && ws.way.getNode(ws.lowerIndex+1) != newNode) {
     458            if (ws.way.getNode(ws.lowerIndex) != newNode && ws.way.getNode(ws.lowerIndex+1) != newNode) {
    446459                is.add(ws.lowerIndex);
    447460            }
    448461        }
    449462       
     463        Way wnew = null;
    450464        for (Map.Entry<Way, List<Integer>> insertPoint : insertPoints.entrySet()) {
    451465            List<Integer> is = insertPoint.getValue();
     
    459473                nodesToAdd.add(i+1, newNode);
    460474            }
    461             Way wnew = new Way(w);
     475            wnew = new Way(w);
    462476            wnew.setNodes(nodesToAdd);
    463477            cmds.add(new ChangeCommand(w, wnew));
    464         }       
     478        }
     479        return wnew;
    465480    }
    466481   
Note: See TracChangeset for help on using the changeset viewer.