Changeset 20585 in osm for applications/editors
- Timestamp:
- 2010-03-21T18:16:45+01:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/Buildings.java
r20548 r20585 73 73 74 74 private static final int cMaxnode = 10000; 75 private static final double cDistanceForOptimization = 0.7; 75 76 private int[] dirsX = new int[] {1,1,0,-1,-1,-1,0,1}; 76 77 private int[] dirsY = new int[] {0,1,1,1,0,-1,-1,-1}; … … 121 122 return; 122 123 selectedImage = null; 123 // boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0; 124 // ctrl = do not merge the new polygon with adjacent elements 125 boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0; 126 // shift = do not use the parcel as a separator 127 boolean shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0; 124 128 // boolean alt = (e.getModifiers() & ActionEvent.ALT_MASK) != 0; 125 boolean shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0;126 129 for (Layer layer : Main.map.mapView.getAllLayers()) { 127 130 if (layer.isVisible() && layer instanceof WMSLayer && ((WMSLayer)layer).isBuildingsOnly() ) { … … 158 161 way2.addNode(way2.getNode(0)); 159 162 new SimplifyWay().simplifyWay(way2, 0.2); 163 simplifyAngles(way2); 160 164 Way wayToAdd = new Way(); 161 165 Collection<Command> cmds = new LinkedList<Command>(); 162 for (int i = 0; i < way2.getNodesCount()-1; i++) { 163 Node nearestNode = getNearestNode(way2.getNode(i)); 164 if (nearestNode == null) { 165 // check if we can join new node to existing ways 166 List<WaySegment> wss = getNearestWaySegments(way2.getNode(i)); 166 if (ctrl) { 167 for (int i = 0; i < way2.getNodesCount()-1; i++) { 167 168 wayToAdd.addNode(way2.getNode(i)); 168 cmds.add(new AddCommand(way2.getNode(i))); 169 if (wss.size() > 0) { 170 cmds.add(new MoveCommand(way2.getNode(i), dx, dy)); 171 joinNodeToExistingWays(wss, way2.getNode(i), cmds); 169 cmds.add(new AddCommand(wayToAdd.getNode(i))); 170 } 171 wayToAdd.addNode(wayToAdd.getNode(0)); // close the polygon ! 172 } else { 173 for (int i = 0; i < way2.getNodesCount()-1; i++) { 174 Node nearestNode = getNearestNode(way2.getNode(i)); 175 if (nearestNode == null) { 176 // check if we can join new node to existing ways 177 List<WaySegment> wss = getNearestWaySegments(way2.getNode(i)); 178 wayToAdd.addNode(way2.getNode(i)); 179 cmds.add(new AddCommand(way2.getNode(i))); 180 if (wss.size() > 0) { 181 cmds.add(new MoveCommand(way2.getNode(i), dx, dy)); 182 joinNodeToExistingWays(wss, way2.getNode(i), cmds); 183 } 184 } else { 185 // replace new node by an existing nearest node 186 wayToAdd.addNode(nearestNode); 187 cmds.add(new MoveCommand(nearestNode, dx, dy)); 172 188 } 173 } else {174 // replace new node by an existing nearest node175 wayToAdd.addNode(nearestNode);176 cmds.add(new MoveCommand(nearestNode, dx, dy));177 189 } 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)); 190 wayToAdd.addNode(wayToAdd.getNode(0)); // close the polygon ! 191 for (int i = 1; i < wayToAdd.getNodesCount(); i++) { 192 Node nodeToJoin = existingNodesInNewSegment(wayToAdd.getNode(i-1), wayToAdd.getNode(i), wayToAdd); 193 // check if we join new way to existing nodes 194 if (nodeToJoin != null) { 195 List<WaySegment> wss = new LinkedList<WaySegment>(); 196 wss.add(new WaySegment(wayToAdd, i-1)); 197 wayToAdd = joinNodeToExistingWays(wss, nodeToJoin, cmds); 198 cmds.add(new MoveCommand(nodeToJoin, dx, dy)); 199 i--; // re-assess the new segment (perhaps several nodes to join) 200 } 188 201 } 189 202 } … … 322 335 } 323 336 324 private Point getPointInC entimeters(Node n) {337 private Point getPointInCm(Node n) { 325 338 return new Point(new Double(n.getEastNorth().getX()*100).intValue(), 326 339 new Double(n.getEastNorth().getY()*100).intValue()); … … 328 341 329 342 public Node getNearestNode(Node newNode) { 330 Point newP = getPointInCentimeters(newNode);343 Point newPoint = getPointInCm(newNode); 331 344 DataSet ds = getCurrentDataSet(); 332 345 if (ds == null) … … 341 354 Point sp = new Point(new Double(n.getEastNorth().getX()*100).intValue(), 342 355 new Double(n.getEastNorth().getY()*100).intValue()); 343 double dist = newP .distanceSq(sp); // in centimeter !356 double dist = newPoint.distanceSq(sp); // in centimeter ! 344 357 if (dist < minDistanceSq) { 345 358 minDistanceSq = dist; … … 361 374 362 375 private List<WaySegment> getNearestWaySegments(Node newNode) { 363 Point newP = new Point(new Double(newNode.getEastNorth().getX()*100).intValue(),376 Point newPoint = new Point(new Double(newNode.getEastNorth().getX()*100).intValue(), 364 377 new Double(newNode.getEastNorth().getY()*100).intValue()); 365 378 TreeMap<Double, List<WaySegment>> nearest = new TreeMap<Double, List<WaySegment>>(); … … 384 397 } 385 398 386 Point A = getPointInC entimeters(lastN);387 Point B = getPointInC entimeters(n);399 Point A = getPointInCm(lastN); 400 Point B = getPointInCm(n); 388 401 double c = A.distanceSq(B); 389 double a = newP .distanceSq(B);390 double b = newP .distanceSq(A);391 double perDist = a - (a - b + c) * (a - b + c) / 4 / c; // perpendicular distance squared402 double a = newPoint.distanceSq(B); 403 double b = newPoint.distanceSq(A); 404 double perDist = a - (a - b + c) * (a - b + c) / 4 / c; 392 405 if (perDist < snapDistanceSq && a < c + snapDistanceSq && b < c + snapDistanceSq) { 393 406 if (ds.isSelected(w)) { … … 401 414 nearest.put(perDist, l); 402 415 } 403 Point pivot = A; 404 double startAngle = Math.atan2(B.x-pivot.x, B.y-pivot.y); 405 double endAngle = Math.atan2(newP.x-pivot.x, newP.y-pivot.y); 406 double angle = endAngle - startAngle; 407 double ratio = A.distance(newP)/A.distance(B);//).intValue(); 416 double ratio = A.distance(newPoint)/A.distance(B); 408 417 Point perP = new Point(A.x+new Double((B.x-A.x)*ratio).intValue(), 409 418 A.y+new Double((B.y-A.y)*ratio).intValue()); 410 dx = (perP.x-newP .x)/200.0; // back to meters this time and whole distance by two411 dy = (perP.y-newP .y)/200.0;412 System.out.println(angle+","+ ratio+","+perP );419 dx = (perP.x-newPoint.x)/200.0; // back to meters this time and whole distance by two 420 dy = (perP.y-newPoint.y)/200.0; 421 // System.out.println(angle+","+ ratio+","+perP ); 413 422 l.add(new WaySegment(w, i)); 414 423 } … … 424 433 } 425 434 426 private List<Node> existingNodesInNewSegment(Node n1, Node n2) {435 private Node existingNodesInNewSegment(Node n1, Node n2, Way way) { 427 436 double minx = Math.min(n1.getEastNorth().getX(), n2.getEastNorth().getX())*100; 428 437 double miny = Math.min(n1.getEastNorth().getY(), n2.getEastNorth().getY())*100; 429 438 double maxx = Math.max(n1.getEastNorth().getX(), n2.getEastNorth().getX())*100; 430 439 double maxy = Math.max(n1.getEastNorth().getY(), n2.getEastNorth().getY())*100; 431 if ((maxx-minx)/2 < snapDistance && (maxy-miny)/2 < snapDistance) { 440 // if ((maxx-minx)/2 < snapDistance && (maxy-miny)/2 < snapDistance) { 441 // return null; 442 // } 443 BBox bbox = new BBox( Main.proj.eastNorth2latlon(new EastNorth((minx-snapDistance)/100, (miny-snapDistance)/100)), 444 Main.proj.eastNorth2latlon(new EastNorth((maxx+snapDistance)/100, (maxy+snapDistance)/100))); 445 DataSet ds = getCurrentDataSet(); 446 if (ds == null) { 432 447 return null; 433 448 } 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))); 436 DataSet ds = getCurrentDataSet(); 437 if (ds == null) 438 return null; 439 List<Node> ret = new ArrayList<Node>(); 440 for (Node n:ds.searchNodes(bbox)) 441 if (n.isUsable()) 442 ret.add(n); 443 System.out.println("Join "+ret.size()+" nodes to new segment"); 449 Node ret = null; 450 List<Node> nodesInBbox = ds.searchNodes(bbox); 451 for (Node n:nodesInBbox) { 452 Point A = getPointInCm(n1); 453 Point B = getPointInCm(n2); 454 Point existingPoint = getPointInCm(n); 455 double c = A.distanceSq(B); 456 double a = existingPoint.distanceSq(B); 457 double b = existingPoint.distanceSq(A); 458 double perDist = a - (a - b + c) * (a - b + c) / 4 / c; 459 if (perDist < snapDistanceSq && a < c + snapDistanceSq && b < c + snapDistanceSq 460 && n.isUsable() && !way.getNodes().contains(n)) { 461 ret = n; 462 // shift the existing node to the half distance of the joined new segment 463 double ratio = A.distance(existingPoint)/A.distance(B); 464 Point perP = new Point(A.x+new Double((B.x-A.x)*ratio).intValue(), 465 A.y+new Double((B.y-A.y)*ratio).intValue()); 466 dx = (perP.x-existingPoint.x)/200.0; // back to meters this time and whole distance by two 467 dy = (perP.y-existingPoint.y)/200.0; 468 break; 469 } 470 } 471 // System.out.println("Found "+nodesInBbox.size()+", join node "+ret+" to new segment; "+Main.proj.latlon2eastNorth(bbox.getBottomRight())+","+Main.proj.latlon2eastNorth(bbox.getTopLeft())); 444 472 return ret; 445 473 } … … 492 520 Collections.reverse(is); 493 521 } 494 522 523 /* 524 * The standard simplifier leaves sometimes closed nodes at buildings corners. 525 * We remove here the node not altering the building angle. 526 */ 527 private void simplifyAngles(Way way){ 528 for (int i=1; i<way.getNodes().size(); i++){ 529 Node n1 = way.getNode(i-1); 530 Node n2 = way.getNode(i); 531 double dist = getPointInCm(n1).distance(getPointInCm(n2))/100; 532 // System.out.println("dist="+dist+":"+(dist < cDistanceForOptimization)); 533 if (dist < cDistanceForOptimization) { 534 Node n0, n3; 535 if (i > 1) 536 n0 = way.getNode(i-2); 537 else 538 n0 = way.getNode(way.getNodes().size()-1); 539 if (i < way.getNodes().size()-1) 540 n3 = way.getNode(i+1); 541 else 542 n3 = way.getNode(0); 543 double angle1 = AngleOfView(n1.getCoor().getX(), n1.getCoor().getY(), 544 n0.getCoor().getX(), n0.getCoor().getY(), 545 n2.getCoor().getX(), n2.getCoor().getY()); 546 System.out.println("angle n0,n1,n2="+(angle1*180/Math.PI)); 547 double angle2 = AngleOfView(n2.getCoor().getX(), n2.getCoor().getY(), 548 n1.getCoor().getX(), n1.getCoor().getY(), 549 n3.getCoor().getX(), n3.getCoor().getY()); 550 System.out.println("angle n1,n2,n3="+(angle2*180/Math.PI)); 551 if (angle1 > Math.PI*0.9 && angle1 < Math.PI*1.1) { 552 way.removeNode(n1); 553 System.out.println("remove n1"); 554 } else if (angle2 > Math.PI*0.9 && angle2 < Math.PI*1.1) { 555 way.removeNode(n2); 556 System.out.println("remove n2"); 557 } else 558 System.out.println("no angle near PI"); 559 } 560 } 561 } 562 563 private double AngleOfView ( double ViewPt_X, double ViewPt_Y, 564 double Pt1_X, double Pt1_Y, 565 double Pt2_X, double Pt2_Y ) { 566 double a1, b1, a2, b2, a, b, t, cosinus ; 567 a1 = Pt1_X - ViewPt_X ; 568 a2 = Pt1_Y - ViewPt_Y ; 569 b1 = Pt2_X - ViewPt_X ; 570 b2 = Pt2_Y - ViewPt_Y ; 571 a = Math.sqrt( (a1*a1) + (a2*a2) ); 572 b = Math.sqrt ( (b1*b1) + (b2*b2) ); 573 if ( (a == 0.0) || (b == 0.0) ) 574 return (0.0) ; 575 cosinus = (a1*b1+a2*b2) / (a*b) ; 576 t = Math.acos ( cosinus ); 577 //t = t * 180.0 / Math.PI ; 578 return (t); 579 } 580 581 /* 582 * coming from SimplifyWayAction 583 */ 584 // private boolean isRequiredNode(Way way, Node node) { 585 // boolean isRequired = Collections.frequency(way.getNodes(), node) > 1; 586 // if (! isRequired) { 587 // List<OsmPrimitive> parents = new LinkedList<OsmPrimitive>(); 588 // parents.addAll(node.getReferrers()); 589 // parents.remove(way); 590 // isRequired = !parents.isEmpty(); 591 // } 592 // if (!isRequired) { 593 // isRequired = node.isTagged(); 594 // } 595 // return isRequired; 596 // } 495 597 } -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionNewLocation.java
r20390 r20585 40 40 String codeCommune = ""; 41 41 boolean changeInterface = false; 42 JLabel labelSectionNewLocation = new JLabel(tr("Add a new layer"));42 JLabel labelSectionNewLocation = new JLabel(tr("Add a new municipality layer")); 43 43 JPanel p = new JPanel(new GridBagLayout()); 44 JLabel labelLocation = new JLabel(tr(" Location"));44 JLabel labelLocation = new JLabel(tr("Commune")); 45 45 final JTextField inputTown = new JTextField( Main.pref.get("cadastrewms.location") ); 46 46 inputTown.setToolTipText(tr("<html>Enter the town,village or city name.<br>" -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/SimplifyWay.java
r20390 r20585 17 17 Way wnew = new Way(w); 18 18 19 // int toI = wnew.getNodesCount() - 1;20 // List<OsmPrimitive> parents = new ArrayList<OsmPrimitive>();21 // for (int i = wnew.getNodesCount() - 1; i >= 0; i--) {22 // //CollectBackReferencesVisitor backRefsV = new CollectBackReferencesVisitor(dataSet, false);23 // //backRefsV.visit(wnew.getNode(i));24 // parents.addAll(w.getNode(i).getReferrers());25 // boolean used = false;26 // if (parents.size() == 1) {27 // used = Collections.frequency(w.getNodes(), wnew.getNode(i)) > 1;28 // } else {29 // //backRefsV.getData().remove(w);30 // parents.remove(w);31 // used = !parents.isEmpty();32 // }33 // if (!used)34 // used = wnew.getNode(i).isTagged();35 //36 // if (used) {37 // simplifyWayRange(wnew, i, toI, threshold);38 // toI = i;39 // }40 // }41 19 simplifyWayRange(wnew, 0, wnew.getNodesCount() - 1, threshold); 42 20 w.setNodes(wnew.getNodes()); 43 // HashSet<Node> delNodes = new HashSet<Node>();44 // delNodes.addAll(w.getNodes());45 // delNodes.removeAll(wnew.getNodes());46 47 // if (wnew.getNodesCount() != w.getNodesCount()) {48 // Collection<Command> cmds = new LinkedList<Command>();49 // cmds.add(new ChangeCommand(w, wnew));50 // cmds.add(new DeleteCommand(delNodes));51 // Main.main.undoRedo.add(new SequenceCommand(trn("Simplify Way (remove {0} node)", "Simplify Way (remove {0} nodes)", delNodes.size(), delNodes.size()), cmds));52 // Main.map.repaint();53 // }54 21 } 55 22
Note:
See TracChangeset
for help on using the changeset viewer.