Changeset 20548 in osm for applications/editors
- Timestamp:
- 2010-03-18T22:12:11+01:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/Buildings.java
r20484 r20548 163 163 Node nearestNode = getNearestNode(way2.getNode(i)); 164 164 if (nearestNode == null) { 165 // check if we can join new node to existing ways 165 166 List<WaySegment> wss = getNearestWaySegments(way2.getNode(i)); 166 167 wayToAdd.addNode(way2.getNode(i)); 167 168 cmds.add(new AddCommand(way2.getNode(i))); 168 if (wss.size() > 0) 169 if (wss.size() > 0) { 169 170 cmds.add(new MoveCommand(way2.getNode(i), dx, dy)); 170 171 joinNodeToExistingWays(wss, way2.getNode(i), cmds); 171 } else {// reuse the existing node 172 } 173 } else { 174 // replace new node by an existing nearest node 172 175 wayToAdd.addNode(nearestNode); 173 176 cmds.add(new MoveCommand(nearestNode, dx, dy)); 174 177 } 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 } 179 190 cmds.add(new AddCommand(wayToAdd)); 180 191 if (clickOnBuilding) … … 413 424 } 414 425 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))); 422 436 DataSet ds = getCurrentDataSet(); 423 437 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)) 428 441 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) { 434 448 HashMap<Way, List<Integer>> insertPoints = new HashMap<Way, List<Integer>>(); 435 449 for (WaySegment ws : wss) { … … 442 456 } 443 457 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) { 446 459 is.add(ws.lowerIndex); 447 460 } 448 461 } 449 462 463 Way wnew = null; 450 464 for (Map.Entry<Way, List<Integer>> insertPoint : insertPoints.entrySet()) { 451 465 List<Integer> is = insertPoint.getValue(); … … 459 473 nodesToAdd.add(i+1, newNode); 460 474 } 461 Waywnew = new Way(w);475 wnew = new Way(w); 462 476 wnew.setNodes(nodesToAdd); 463 477 cmds.add(new ChangeCommand(w, wnew)); 464 } 478 } 479 return wnew; 465 480 } 466 481
Note:
See TracChangeset
for help on using the changeset viewer.