Changeset 30231 in osm for applications/editors/josm/plugins/smed2/src
- Timestamp:
- 2014-01-26T19:10:42+01:00 (11 years ago)
- Location:
- applications/editors/josm/plugins/smed2/src/s57
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/smed2/src/s57/S57map.java
r30226 r30231 141 141 142 142 public class Prim { // Spatial element 143 public long id; // ID143 public long id; // Snode ID for POINTs, Edge ID for LINEs & AREAs) 144 144 public boolean forward; // Direction of vector used (LINEs & AREAs) 145 145 public boolean outer; // Exterior/Interior boundary (AREAs) … … 158 158 } 159 159 160 public class Comp { 161 public long ref; 162 public int size; 163 public Comp(long r, int s) { 164 ref = r; 165 size = s; 166 } 167 } 168 160 169 public enum Pflag { 161 170 NOSP, POINT, LINE, AREA … … 165 174 public Pflag prim; // Geometry type 166 175 public ArrayList<Prim> elems; // Ordered list of elements 176 public int outers; // Number of outers 177 public int inners; // Number of inners 178 public ArrayList<Comp> refs; // Ordered list of compounds 167 179 public Geom(Pflag p) { 168 180 prim = p; 169 181 elems = new ArrayList<Prim>(); 182 outers = inners = 0; 183 refs = new ArrayList<Comp>(); 170 184 } 171 185 } … … 203 217 private Feature feature; 204 218 private Edge edge; 219 private long ref; 205 220 206 221 public S57map() { … … 210 225 features = new FtrMap(); // All features in map, grouped by type 211 226 index = new FtrTab(); // Feature look-up table 227 ref = 0x0000ffffffff0000L;// Compound reference generator 212 228 } 213 229 … … 458 474 long first = 0; 459 475 long last = 0; 476 Comp comp = null; 460 477 boolean next = true; 461 478 if ((geom.prim == Pflag.LINE) || (geom.prim == Pflag.AREA)) { … … 474 491 } 475 492 sort.elems.add(prim); 493 if (prim.outer) { 494 sort.outers++; 495 } else { 496 sort.inners++; 497 } 498 comp = new Comp(ref++, 1); 499 sort.refs.add(comp); 476 500 } else { 477 501 if (prim.forward) { … … 479 503 sort.elems.add(prim); 480 504 last = edge.last; 505 comp.size++; 481 506 } else if (edge.last == first) { 482 507 sort.elems.add(0, prim); 483 508 first = edge.first; 509 comp.size++; 484 510 } else { 485 511 geom.elems.add(prim); … … 489 515 sort.elems.add(prim); 490 516 last = edge.first; 517 comp.size++; 491 518 } else if (edge.first == first) { 492 519 sort.elems.add(0, prim); 493 520 first = edge.last; 521 comp.size++; 494 522 } else { 495 523 geom.elems.add(prim); … … 517 545 ArrayList<Prim> closed = null; 518 546 sort = new Geom(geom.prim); 547 sort.outers = feature.geom.outers; 548 sort.inners = feature.geom.inners; 549 sort.refs = feature.geom.refs; 519 550 next = true; 520 551 while (!sorting.isEmpty()) { … … 620 651 EdgeIterator eit; 621 652 ListIterator<S57map.Prim> it; 622 long first;623 long last;653 int cc, ec; 654 Comp comp; 624 655 625 656 public GeomIterator(Geom g) { 626 657 geom = g; 627 658 eit = null; 628 first= 0;629 last = -1;659 cc = ec = 0; 660 comp = null; 630 661 if ((geom.prim != Pflag.NOSP) && (geom.prim != Pflag.POINT)) { 631 662 it = geom.elems.listIterator(); … … 636 667 637 668 public boolean hasMore() { 638 return ( it != null) && it.hasNext();669 return (cc < geom.refs.size()); 639 670 } 640 671 641 public boolean more() { 642 if ((it != null) && it.hasNext()) { 643 prim = it.next(); 644 eit = new EdgeIterator(edges.get(prim.id), prim.forward); 645 return prim.outer; 646 } 647 return false; 672 public long getMore() { 673 comp = geom.refs.get(cc++); 674 ec = 0; 675 return comp.ref; 648 676 } 649 677 650 678 public boolean hasNext() { 651 return (first != last) && (it.hasNext() || eit.hasNext()); 679 if (eit == null) { 680 return (ec < comp.size); 681 } else { 682 return (eit.hasNext()); 683 } 652 684 } 653 685 654 686 public long nextRef() { 655 if ((eit == null) || !eit.hasNext()) { 656 if (it.hasNext()) { 657 prim = it.next(); 658 eit = new EdgeIterator(edges.get(prim.id), prim.forward); 659 } else { 660 return 0; 661 } 687 if ((eit == null) && (ec < comp.size)) { 688 prim = geom.elems.get(ec++); 689 eit = new EdgeIterator(edges.get(prim.id), prim.forward); 662 690 } 663 691 long ref = eit.nextRef(); 664 if (ref == last) 665 ref = eit.nextRef(); 666 if (first == 0) { 667 first = ref; 668 last = 0; 669 } else { 670 last = ref; 692 if (!eit.hasNext()) { 693 eit = null; 671 694 } 672 695 return ref; … … 683 706 lat = lon = llon = llat = 0; 684 707 double sigma = 0; 685 /* BoundIterator it = new BoundIterator(bound); 708 GeomIterator it = new GeomIterator(geom); 709 it.getMore(); 686 710 while (it.hasNext()) { 687 711 llon = lon; … … 692 716 sigma += (lon * Math.sin(llat)) - (llon * Math.sin(lat)); 693 717 } 694 */return sigma / 2.0;718 return sigma / 2.0; 695 719 } 696 720 … … 704 728 705 729 public double calcLength(Geom geom) { 706 /*Snode node;730 Snode node; 707 731 double lat, lon, llon, llat; 708 732 lat = lon = llon = llat = 0; 709 733 double sigma = 0; 710 BoundIterator it = new BoundIterator(bound); 734 GeomIterator it = new GeomIterator(geom); 735 it.getMore(); 711 736 if (it.hasNext()) { 712 737 node = it.next(); … … 723 748 } 724 749 return sigma * 3444; 725 */ return 0;726 750 } 727 751 728 752 public Snode findCentroid(Feature feature) { 729 /*double lat, lon, slat, slon, llat, llon;753 double lat, lon, slat, slon, llat, llon; 730 754 llat = llon = lat = lon = slat = slon = 0; 731 755 double sarc = 0; … … 733 757 switch (feature.geom.prim) { 734 758 case POINT: 735 return nodes.get(feature.geom );759 return nodes.get(feature.geom.elems.get(0).id); 736 760 case LINE: 737 Edge edge = edges.get(feature.geom);738 EdgeIterator eit = new EdgeIterator(edge, true);739 while ( eit.hasNext()) {740 Snode node = eit.next();761 GeomIterator it = new GeomIterator(feature.geom); 762 it.getMore(); 763 while (it.hasNext()) { 764 Snode node = it.next(); 741 765 lat = node.lat; 742 766 lon = node.lon; … … 752 776 sarc = 0; 753 777 first = true; 754 eit = new EdgeIterator(edge, true); 755 while (eit.hasNext()) { 756 Snode node = eit.next(); 778 it = new GeomIterator(feature.geom); 779 while (it.hasNext()) { 780 it.getMore(); 781 Snode node = it.next(); 757 782 lat = node.lat; 758 783 lon = node.lon; … … 770 795 return new Snode(llat + ((lat - llat) * harc / sarc), llon + ((lon - llon) * harc / sarc)); 771 796 case AREA: 772 Bound bound = areas.get(feature.geom).get(0);773 BoundIterator bit = new BoundIterator(bound);797 GeomIterator bit = new GeomIterator(feature.geom); 798 bit.getMore(); 774 799 while (bit.hasNext()) { 775 800 Snode node = bit.next(); … … 790 815 default: 791 816 } 792 */return null;817 return null; 793 818 } 794 819 -
applications/editors/josm/plugins/smed2/src/s57/S57val.java
r30215 r30231 1180 1180 1181 1181 public static String stringValue(AttVal<?> attval) { // Convert OSeaM value object to OSeaM attribute value string 1182 switch (attval.conv) { 1183 case A: 1184 case S: 1185 return (String)attval.val; 1186 case E: 1187 EnumMap<?,?> map = keys.get(attval.att).map; 1188 return ((S57enum)map.get(attval.val)).val; 1189 case L: 1190 String str = ""; 1191 map = keys.get(attval.att).map; 1192 for (Object item : (ArrayList<?>)attval.val) { 1193 if (!str.isEmpty()) str += ";"; 1194 str += ((S57enum)map.get(item)).val; 1182 if (attval != null) { 1183 switch (attval.conv) { 1184 case A: 1185 case S: 1186 return (String) attval.val; 1187 case E: 1188 EnumMap<?, ?> map = keys.get(attval.att).map; 1189 return ((S57enum) map.get(attval.val)).val; 1190 case L: 1191 String str = ""; 1192 map = keys.get(attval.att).map; 1193 for (Object item : (ArrayList<?>) attval.val) { 1194 if (!str.isEmpty()) 1195 str += ";"; 1196 str += ((S57enum) map.get(item)).val; 1197 } 1198 return str; 1199 case I: 1200 return ((Long) attval.val).toString(); 1201 case F: 1202 return ((Double) attval.val).toString(); 1195 1203 } 1196 return str;1197 case I:1198 return ((Long)attval.val).toString();1199 case F:1200 return ((Double)attval.val).toString();1201 1204 } 1202 1205 return "";
Note:
See TracChangeset
for help on using the changeset viewer.