Changeset 31846 in osm for applications/editors/josm/plugins/seachart/src/s57/S57map.java
- Timestamp:
- 2015-12-21T16:57:17+01:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/seachart/src/s57/S57map.java
r31738 r31846 153 153 public boolean forward; // Direction of vector used (LINEs & AREAs) 154 154 public boolean outer; // Exterior/Interior boundary (AREAs) 155 public boolean trunc; // Cell limit truncation 155 156 public Prim() { 156 id = 0; forward = true; outer = true; 157 id = 0; forward = true; outer = true; trunc = false; 157 158 } 158 159 public Prim(long i) { 159 id = i; forward = true; outer = true; 160 id = i; forward = true; outer = true; trunc = false; 160 161 } 161 162 public Prim(long i, boolean o) { 162 id = i; forward = true; outer = o; 163 id = i; forward = true; outer = o; trunc = false; 163 164 } 164 165 public Prim(long i, boolean f, boolean o) { 165 id = i; forward = f; outer = o; 166 id = i; forward = f; outer = o; trunc = false; 167 } 168 public Prim(long i, boolean f, boolean o, boolean t) { 169 id = i; forward = f; outer = o; trunc = t; 166 170 } 167 171 } … … 191 195 public Geom(Pflag p) { 192 196 prim = p; 193 elems = new ArrayList< Prim>();197 elems = new ArrayList<>(); 194 198 outers = inners = 0; 195 comps = new ArrayList< Comp>();199 comps = new ArrayList<>(); 196 200 area = 0; 197 201 length = 0; … … 548 552 } 549 553 550 enum Ext {I, N, W, S, E }551 552 554 public void mapDone() { 553 class Land { 554 long first; 555 Snode start; 556 Ext sbound; 557 long last; 558 Snode end; 559 Ext ebound; 560 Feature land; 561 Land (Feature l) { 562 land = l; 563 first = last = 0; 564 start = end = null; 565 sbound = ebound = Ext.I; 566 } 567 } 568 if (features.get(Obj.COALNE) != null) { 569 ArrayList<Feature> coasts = new ArrayList<Feature>(); 570 ArrayList<Land> lands = new ArrayList<Land>(); 571 if (features.get(Obj.LNDARE) == null) { 572 features.put(Obj.LNDARE, new ArrayList<Feature>()); 573 } 574 for (Feature feature : features.get(Obj.COALNE)) { 575 Feature land = new Feature(); 576 land.id = ++xref; 577 land.type = Obj.LNDARE; 578 land.reln = Rflag.MASTER; 579 land.objs.put(Obj.LNDARE, new ObjTab()); 580 land.objs.get(Obj.LNDARE).put(0, new AttMap()); 581 if (feature.geom.prim == Pflag.AREA) { 582 land.geom = feature.geom; 583 features.get(Obj.LNDARE).add(land); 584 } else if (feature.geom.prim == Pflag.LINE) { 585 land.geom.prim = Pflag.LINE; 586 land.geom.elems.addAll(feature.geom.elems); 587 coasts.add(land); 588 } 589 } 590 while (coasts.size() > 0) { 591 Feature land = coasts.remove(0); 592 Edge fedge = edges.get(land.geom.elems.get(0).id); 593 long first = fedge.first; 594 long last = edges.get(land.geom.elems.get(land.geom.elems.size() - 1).id).last; 595 if (coasts.size() > 0) { 596 boolean added = true; 597 while (added) { 598 added = false; 599 for (int i = 0; i < coasts.size(); i++) { 600 Feature coast = coasts.get(i); 601 Edge edge = edges.get(coast.geom.elems.get(0).id); 602 if (edge.first == last) { 603 land.geom.elems.add(coast.geom.elems.get(0)); 604 last = edge.last; 605 coasts.remove(i--); 606 added = true; 607 } else if (edge.last == first) { 608 land.geom.elems.add(0, coast.geom.elems.get(0)); 609 first = edge.first; 610 coasts.remove(i--); 611 added = true; 612 } 613 } 614 } 615 } 616 lands.add(new Land(land)); 617 } 618 ArrayList<Land> islands = new ArrayList<Land>(); 619 for (Land land : lands) { 620 sortGeom(land.land); 621 if (land.land.geom.prim == Pflag.AREA) { 622 islands.add(land); 623 features.get(Obj.LNDARE).add(land.land); 624 } 625 } 626 for (Land island : islands) { 627 lands.remove(island); 628 } 629 for (Land land : lands) { 630 GeomIterator git = new GeomIterator(land.land.geom); 631 Snode prev = null; 632 Ext bprev = Ext.I; 633 Ext ext; 634 land.ebound = land.sbound = Ext.I; 635 while (git.hasComp()) { 636 git.nextComp(); 637 while (git.hasEdge()) { 638 git.nextEdge(); 639 while (git.hasNode()) { 640 long ref = git.nextRef(false); 641 Snode node = nodes.get(ref); 642 if (node == null) continue; 643 if (land.first == 0) { 644 land.first = ref; 645 } 646 if (prev == null) { 647 prev = node; 648 } 649 if ((node.lat >= bounds.maxlat) && (node.lon < bounds.maxlon)) { 650 ext = Ext.N; 651 } else if (node.lon <= bounds.minlon) { 652 ext = Ext.W; 653 } else if (node.lat <= bounds.minlat) { 654 ext = Ext.S; 655 } else if (node.lon >= bounds.maxlon) { 656 ext = Ext.E; 657 } else { 658 ext = Ext.I; 659 } 660 if (ext == Ext.I) { 661 if (land.start == null) { 662 land.start = prev; 663 land.sbound = bprev; 664 } 665 land.end = null; 666 land.ebound = Ext.I; 667 } else { 668 if ((land.start != null) && (land.end == null)) { 669 land.end = node; 670 land.ebound = ext; 671 } 672 } 673 prev = node; 674 bprev = ext; 675 land.last = ref; 676 } 677 } 678 } 679 } 680 islands = new ArrayList<Land>(); 681 for (Land land : lands) { 682 if ((land.sbound == Ext.I) || (land.ebound == Ext.I)) { 683 islands.add(land); 684 } 685 } 686 for (Land island : islands) { 687 lands.remove(island); 688 } 689 while (lands.size() > 0) { 690 Land land = lands.get(0); 691 Edge nedge = new Edge(); 692 nedge.first = land.last; 693 Ext bound = land.ebound; 694 Snode last = land.end; 695 double delta = Math.PI; 696 int idx = -1; 697 Land next = null; 698 while (idx < 0) { 699 for (int i = 0; i < lands.size(); i++) { 700 next = lands.get(i); 701 if (next.sbound == bound) { 702 double diff = -Math.PI; 703 switch (bound) { 704 case N: 705 diff = last.lon - next.start.lon; 706 break; 707 case W: 708 diff = last.lat - next.start.lat; 709 break; 710 case S: 711 diff = next.start.lon - last.lon; 712 break; 713 case E: 714 diff = next.start.lat - last.lat; 715 break; 716 default: 717 continue; 718 } 719 if ((diff >= 0.0) && (diff < delta)) { 720 delta = diff; 721 idx = i; 722 } 723 } 724 } 725 if (idx < 0) { 726 long ref = (long)bound.ordinal(); 727 last = nodes.get(ref); 728 nedge.nodes.add(ref); 729 ref = ref < 4 ? ++ref : 1; 730 for (Ext e : Ext.values()) { 731 if (ref == e.ordinal()) { 732 bound = e; 733 break; 734 } 735 } 736 } 737 } 738 next = lands.get(idx); 739 nedge.last = next.first; 740 edges.put(++xref, nedge); 741 land.land.geom.elems.add(new Prim(xref)); 742 if (next != land) { 743 land.land.geom.elems.addAll(next.land.geom.elems); 744 land.ebound = next.ebound; 745 land.end = next.end; 746 land.last = next.last; 747 lands.remove(idx); 748 } 749 sortGeom(land.land); 750 if (land.land.geom.prim == Pflag.AREA) { 751 features.get(Obj.LNDARE).add(land.land); 752 lands.remove(land); 753 } 754 } 755 } 756 return; 757 } 758 555 if (!sea) { 556 S57box.bBox(this); 557 } 558 } 559 759 560 // Utility methods 760 561 … … 836 637 if (ie == 0) feature.geom.area = Math.abs(area) * 3444 * 3444; 837 638 if (((ie == 0) && (area < 0.0)) || ((ie > 0) && (area >= 0.0))) { 838 ArrayList<Prim> tmp = new ArrayList< Prim>();639 ArrayList<Prim> tmp = new ArrayList<>(); 839 640 for (int i = 0; i < feature.geom.comps.get(ic).size; i++) { 840 641 Prim p = feature.geom.elems.remove(ie);
Note:
See TracChangeset
for help on using the changeset viewer.
