Changeset 30314 in osm for applications/editors/josm/plugins/smed2/src/s57
- Timestamp:
- 2014-03-01T18:57:59+01:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/smed2/src/s57/S57map.java
r30285 r30314 171 171 } 172 172 173 public class Comp { 174 public long ref; 175 public int size; 173 public class Comp { // Composite spatial element 174 public long ref; // ID of Comp 175 public int size; // Number of Prims in this Comp 176 176 public Comp(long r, int s) { 177 177 ref = r; … … 316 316 for (long id : index.keySet()) { 317 317 Feature feature = index.get(id); 318 if ((feature.geom.prim == Pflag.LINE) || (feature.geom.prim == Pflag.AREA)) { 319 feature.geom.outers = 1; 320 feature.geom.inners = 0; 321 feature.geom.refs = new ArrayList<Comp>(); 322 Comp comp = new Comp(ref++, 0); 323 feature.geom.refs.add(comp); 324 ListIterator<S57map.Prim> ite = feature.geom.elems.listIterator(); 325 long first = 0; 326 while (ite.hasNext()) { 327 Prim prim = ite.next(); 328 Edge edge = edges.get(prim.id); 329 if (!prim.outer) { 330 if (first == 0) { 331 feature.geom.inners++; 332 comp = new Comp(ref++, 0); 333 feature.geom.refs.add(comp); 334 first = edge.first; 335 } else { 336 if (edge.last == first) { 337 first = 0; 338 } 339 } 340 } 341 comp.size++; 342 } 343 } 344 } 345 for (long id : index.keySet()) { 346 Feature feature = index.get(id); 318 sortGeom(feature); 347 319 for (Reln reln : feature.rels) { 348 320 Feature rel = index.get(reln.id); … … 426 398 feature.reln = Rflag.UNKN; 427 399 feature.geom.prim = Pflag.AREA; 428 feature.geom.elems.add(new Prim(id));429 400 edge = null; 430 401 } … … 503 474 nodes.get(edge.first).flg = Nflag.CONN; 504 475 nodes.get(edge.last).flg = Nflag.CONN; 505 feature.geom.length = calcLength(feature.geom);506 476 if (edge.first == edge.last) { 507 477 feature.geom.prim = Pflag.AREA; 478 } 479 sortGeom(feature); 480 feature.geom.length = calcLength(feature.geom); 481 if (feature.geom.prim == Pflag.AREA) { 508 482 feature.geom.area = calcArea(feature.geom); 509 483 } else { … … 512 486 break; 513 487 case AREA: 488 sortGeom(feature); 489 feature.geom.length = calcLength(feature.geom); 490 feature.geom.area = calcArea(feature.geom); 514 491 break; 515 492 default: … … 528 505 // Utility methods 529 506 530 public void sortGeom() { 531 for (long id : index.keySet()) { 532 feature = index.get(id); 533 Geom sort = new Geom(feature.geom.prim); 534 long first = 0; 535 long last = 0; 536 Comp comp = null; 537 boolean next = true; 538 if ((feature.geom.prim == Pflag.LINE) || (feature.geom.prim == Pflag.AREA)) { 539 int sweep = feature.geom.elems.size(); 540 while (!feature.geom.elems.isEmpty()) { 541 Prim prim = feature.geom.elems.remove(0); 542 Edge edge = edges.get(prim.id); 543 if (next == true) { 544 next = false; 545 if (prim.forward) { 507 public void sortGeom(Feature feature) { 508 Geom sort = new Geom(feature.geom.prim); 509 long first = 0; 510 long last = 0; 511 Comp comp = null; 512 boolean next = true; 513 if ((feature.geom.prim == Pflag.LINE) || (feature.geom.prim == Pflag.AREA)) { 514 int sweep = feature.geom.elems.size(); 515 while (!feature.geom.elems.isEmpty()) { 516 Prim prim = feature.geom.elems.remove(0); 517 Edge edge = edges.get(prim.id); 518 if (next == true) { 519 next = false; 520 if (prim.forward) { 521 first = edge.first; 522 last = edge.last; 523 } else { 524 first = edge.last; 525 last = edge.first; 526 } 527 sort.elems.add(prim); 528 if (prim.outer) { 529 sort.outers++; 530 } else { 531 sort.inners++; 532 } 533 comp = new Comp(ref++, 1); 534 sort.refs.add(comp); 535 } else { 536 if (prim.forward) { 537 if (edge.first == last) { 538 sort.elems.add(prim); 539 last = edge.last; 540 comp.size++; 541 } else if (edge.last == first) { 542 sort.elems.add(0, prim); 546 543 first = edge.first; 547 last = edge.last;544 comp.size++; 548 545 } else { 549 first = edge.last; 550 last = edge.first; 551 } 552 sort.elems.add(prim); 553 if (prim.outer) { 554 sort.outers++; 555 } else { 556 sort.inners++; 557 } 558 comp = new Comp(ref++, 1); 559 sort.refs.add(comp); 560 } else { 561 if (prim.forward) { 562 if (edge.first == last) { 563 sort.elems.add(prim); 564 last = edge.last; 565 comp.size++; 566 } else if (edge.last == first) { 567 sort.elems.add(0, prim); 568 first = edge.first; 569 comp.size++; 570 } else { 571 feature.geom.elems.add(prim); 572 } 573 } else { 574 if (edge.last == last) { 575 sort.elems.add(prim); 576 last = edge.first; 577 comp.size++; 578 } else if (edge.first == first) { 579 sort.elems.add(0, prim); 580 first = edge.last; 581 comp.size++; 582 } else { 583 feature.geom.elems.add(prim); 584 } 585 } 586 } 587 if (--sweep == 0) { 588 next = true; 589 sweep = feature.geom.elems.size(); 590 } 591 } 592 if ((sort.prim == Pflag.LINE) && (sort.outers == 1) && (sort.inners == 0) && (first == last)) { 593 sort.prim = Pflag.AREA; 594 } 595 feature.geom = sort; 596 } 597 if (feature.geom.prim == Pflag.AREA) { 598 ArrayList<Prim> outers = new ArrayList<Prim>(); 599 ArrayList<Prim> inners = new ArrayList<Prim>(); 600 for (Prim prim : feature.geom.elems) { 601 if (prim.outer) { 602 outers.add(prim); 603 } else { 604 inners.add(prim); 605 } 606 } 607 ArrayList<Prim> sorting = outers; 608 ArrayList<Prim> closed = null; 609 sort = new Geom(feature.geom.prim); 610 sort.outers = feature.geom.outers; 611 sort.inners = feature.geom.inners; 612 sort.refs = feature.geom.refs; 613 next = true; 614 while (!sorting.isEmpty()) { 615 Prim prim = sorting.remove(0); 616 Edge edge = edges.get(prim.id); 617 if (next == true) { 618 next = false; 619 closed = new ArrayList<Prim>(); 620 closed.add(prim); 621 if (prim.forward) { 622 first = edge.first; 623 last = edge.last; 624 } else { 625 first = edge.last; 626 last = edge.first; 546 feature.geom.elems.add(prim); 627 547 } 628 548 } else { 629 if ( prim.forward) {630 if (edge.first == last) {631 last = edge.last;632 closed.add(prim);633 } else{634 sorting.add(0, prim);635 next = true;636 }549 if (edge.last == last) { 550 sort.elems.add(prim); 551 last = edge.first; 552 comp.size++; 553 } else if (edge.first == first) { 554 sort.elems.add(0, prim); 555 first = edge.last; 556 comp.size++; 637 557 } else { 638 if (edge.last == last) { 639 last = edge.first; 640 closed.add(prim); 641 } else { 642 sorting.add(0, prim); 643 next = true; 644 } 558 feature.geom.elems.add(prim); 645 559 } 646 560 } 647 if (first == last) { 648 sort.elems.addAll(closed); 649 next = true; 650 } 651 if (sorting.isEmpty() && sorting == outers) { 652 sorting = inners; 653 next = true; 654 } 655 } 656 feature.geom = sort; 657 } 561 } 562 if (--sweep == 0) { 563 next = true; 564 sweep = feature.geom.elems.size(); 565 } 566 } 567 if ((sort.prim == Pflag.LINE) && (sort.outers == 1) && (sort.inners == 0) && (first == last)) { 568 sort.prim = Pflag.AREA; 569 } 570 feature.geom = sort; 571 } 572 if (feature.geom.prim == Pflag.AREA) { 573 ArrayList<Prim> outers = new ArrayList<Prim>(); 574 ArrayList<Prim> inners = new ArrayList<Prim>(); 575 for (Prim prim : feature.geom.elems) { 576 if (prim.outer) { 577 outers.add(prim); 578 } else { 579 inners.add(prim); 580 } 581 } 582 ArrayList<Prim> sorting = outers.size() > 0 ? outers : inners; 583 ArrayList<Prim> closed = null; 584 sort = new Geom(feature.geom.prim); 585 sort.outers = feature.geom.outers; 586 sort.inners = feature.geom.inners; 587 sort.refs = feature.geom.refs; 588 next = true; 589 while (!sorting.isEmpty()) { 590 Prim prim = sorting.remove(0); 591 Edge edge = edges.get(prim.id); 592 if (next == true) { 593 next = false; 594 closed = new ArrayList<Prim>(); 595 closed.add(prim); 596 if (prim.forward) { 597 first = edge.first; 598 last = edge.last; 599 } else { 600 first = edge.last; 601 last = edge.first; 602 } 603 } else { 604 if (prim.forward) { 605 if (edge.first == last) { 606 last = edge.last; 607 closed.add(prim); 608 } else { 609 sorting.add(0, prim); 610 next = true; 611 } 612 } else { 613 if (edge.last == last) { 614 last = edge.first; 615 closed.add(prim); 616 } else { 617 sorting.add(0, prim); 618 next = true; 619 } 620 } 621 } 622 if (first == last) { 623 sort.elems.addAll(closed); 624 next = true; 625 } 626 if (sorting.isEmpty() && sorting == outers) { 627 sorting = inners; 628 next = true; 629 } 630 } 631 feature.geom = sort; 658 632 } 659 633 } … … 779 753 lat = lon = llon = llat = 0; 780 754 double sigma = 0; 781 GeomIterator it = new GeomIterator(geom); 782 it.nextComp(); 783 while (it.hasNode()) { 784 llon = lon; 785 llat = lat; 786 node = it.next(); 787 lat = node.lat; 788 lon = node.lon; 789 sigma += (lon * Math.sin(llat)) - (llon * Math.sin(lat)); 755 GeomIterator git = new GeomIterator(geom); 756 if (git.hasComp()) { 757 git.nextComp(); 758 while (git.hasEdge()) { 759 git.nextEdge(); 760 while (git.hasNode()) { 761 llon = lon; 762 llat = lat; 763 node = git.next(); 764 lat = node.lat; 765 lon = node.lon; 766 sigma += (lon * Math.sin(llat)) - (llon * Math.sin(lat)); 767 } 768 } 790 769 } 791 770 return sigma / 2.0; … … 805 784 lat = lon = llon = llat = 0; 806 785 double sigma = 0; 807 GeomIterator it = new GeomIterator(geom); 808 it.nextComp(); 809 if (it.hasNode()) { 810 node = it.next(); 811 lat = node.lat; 812 lon = node.lon; 813 while (it.hasNode()) { 814 llon = lon; 815 llat = lat; 816 node = it.next(); 817 lat = node.lat; 818 lon = node.lon; 819 sigma += Math.acos(Math.sin(lat) * Math.sin(llat) + Math.cos(lat) * Math.cos(llat) * Math.cos(llon - lon)); 786 boolean first = true; 787 GeomIterator git = new GeomIterator(geom); 788 while (git.hasComp()) { 789 git.nextComp(); 790 while (git.hasEdge()) { 791 git.nextEdge(); 792 while (git.hasNode()) { 793 node = git.next(); 794 if (first) { 795 first = false; 796 lat = node.lat; 797 lon = node.lon; 798 } else { 799 llat = lat; 800 llon = lon; 801 lat = node.lat; 802 lon = node.lon; 803 sigma += Math.acos(Math.sin(lat) * Math.sin(llat) + Math.cos(lat) * Math.cos(llat) * Math.cos(llon - lon)); 804 } 805 } 820 806 } 821 807 } … … 832 818 return nodes.get(feature.geom.elems.get(0).id); 833 819 case LINE: 834 GeomIterator it = new GeomIterator(feature.geom); 835 it.nextComp(); 836 while (it.hasNode()) { 837 Snode node = it.next(); 838 lat = node.lat; 839 lon = node.lon; 840 if (first) { 841 first = false; 842 } else { 843 sarc += (Math.acos(Math.cos(lon - llon) * Math.cos(lat - llat))); 844 } 845 llat = lat; 846 llon = lon; 820 GeomIterator git = new GeomIterator(feature.geom); 821 while (git.hasComp()) { 822 git.nextComp(); 823 while (git.hasEdge()) { 824 git.nextEdge(); 825 while (git.hasNode()) { 826 Snode node = git.next(); 827 lat = node.lat; 828 lon = node.lon; 829 if (first) { 830 first = false; 831 } else { 832 sarc += (Math.acos(Math.cos(lon - llon) * Math.cos(lat - llat))); 833 } 834 llat = lat; 835 llon = lon; 836 } 837 } 847 838 } 848 839 double harc = sarc / 2; 849 840 sarc = 0; 850 841 first = true; 851 it = new GeomIterator(feature.geom); 852 while (it.hasNode()) { 853 it.nextComp(); 854 Snode node = it.next(); 855 lat = node.lat; 856 lon = node.lon; 857 if (first) { 858 first = false; 859 } else { 860 sarc = (Math.acos(Math.cos(lon - llon) * Math.cos(lat - llat))); 861 if (sarc > harc) 862 break; 863 } 864 harc -= sarc; 865 llat = lat; 866 llon = lon; 842 git = new GeomIterator(feature.geom); 843 while (git.hasComp()) { 844 git.nextComp(); 845 while (git.hasEdge()) { 846 git.nextEdge(); 847 while (git.hasNode()) { 848 git.nextComp(); 849 Snode node = git.next(); 850 lat = node.lat; 851 lon = node.lon; 852 if (first) { 853 first = false; 854 } else { 855 sarc = (Math.acos(Math.cos(lon - llon) * Math.cos(lat - llat))); 856 if (sarc > harc) 857 break; 858 } 859 harc -= sarc; 860 llat = lat; 861 llon = lon; 862 } 863 } 867 864 } 868 865 return new Snode(llat + ((lat - llat) * harc / sarc), llon + ((lon - llon) * harc / sarc)); 869 866 case AREA: 870 GeomIterator bit = new GeomIterator(feature.geom); 871 bit.nextComp(); 872 while (bit.hasNode()) { 873 Snode node = bit.next(); 874 lat = node.lat; 875 lon = node.lon; 876 if (first) { 877 first = false; 878 } else { 879 double arc = (Math.acos(Math.cos(lon - llon) * Math.cos(lat - llat))); 880 slat += ((lat + llat) / 2 * arc); 881 slon += ((lon + llon) / 2 * arc); 882 sarc += arc; 883 } 884 llon = lon; 885 llat = lat; 867 git = new GeomIterator(feature.geom); 868 while (git.hasComp()) { 869 git.nextComp(); 870 while (git.hasEdge()) { 871 git.nextEdge(); 872 while (git.hasNode()) { 873 Snode node = git.next(); 874 lat = node.lat; 875 lon = node.lon; 876 if (first) { 877 first = false; 878 } else { 879 double arc = (Math.acos(Math.cos(lon - llon) * Math.cos(lat - llat))); 880 slat += ((lat + llat) / 2 * arc); 881 slon += ((lon + llon) / 2 * arc); 882 sarc += arc; 883 } 884 llon = lon; 885 llat = lat; 886 } 887 } 886 888 } 887 889 return new Snode((sarc > 0.0 ? slat / sarc : 0.0), (sarc > 0.0 ? slon / sarc : 0.0));
Note:
See TracChangeset
for help on using the changeset viewer.