Changeset 30269 in osm for applications/editors/josm/plugins/smed2/src/s57/S57map.java
- Timestamp:
- 2014-02-09T19:58:46+01:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/smed2/src/s57/S57map.java
r30231 r30269 80 80 81 81 public enum Rflag { 82 UNKN, AGGR, MASTER, SLAVE , PEER82 UNKN, AGGR, MASTER, SLAVE 83 83 } 84 84 … … 92 92 } 93 93 94 public class RelTab extends ArrayList<Reln> { 95 public RelTab() { 96 super(); 97 } 98 } 99 100 public class ObjTab extends HashMap<Integer, AttMap> { 101 public ObjTab() { 102 super(); 103 } 104 } 105 106 public class ObjMap extends EnumMap<Obj, ObjTab> { 107 public ObjMap() { 108 super(Obj.class); 109 } 110 } 111 112 public class Aggr { 113 public RelTab rels; 114 public long par; 115 public Aggr() { 116 rels = new RelTab(); 117 par = 0; 118 } 119 } 120 94 121 public class AttMap extends HashMap<Att, AttVal<?>> { 95 122 public AttMap() { 96 123 super(); 97 }98 }99 100 public class RelTab extends ArrayList<Reln> {101 public RelTab() {102 super();103 }104 }105 106 public class ObjTab extends HashMap<Integer, AttMap> {107 public ObjTab() {108 super();109 }110 }111 112 public class ObjMap extends EnumMap<Obj, ObjTab> {113 public ObjMap() {114 super(Obj.class);115 124 } 116 125 } … … 177 186 public int inners; // Number of inners 178 187 public ArrayList<Comp> refs; // Ordered list of compounds 188 public double area; // Area of feature 189 public double length; // Length of feature 190 public Snode centre; // Centre of feature 179 191 public Geom(Pflag p) { 180 192 prim = p; … … 182 194 outers = inners = 0; 183 195 refs = new ArrayList<Comp>(); 196 area = 0; 197 length = 0; 198 centre = new Snode(); 184 199 } 185 200 } … … 190 205 public Obj type; // Feature type 191 206 public AttMap atts; // Feature attributes 192 public RelTab rels; // Related objects 193 public ObjMap objs; // Slave objects 194 public double area; // Area of feature 195 public double length; // Length of feature 196 public Snode centre; // Centre of feature 207 public Aggr aggr; // Related objects 208 public ObjMap objs; // Slave object attributes 197 209 198 210 Feature() { … … 201 213 type = Obj.C_AGGR; 202 214 atts = new AttMap(); 203 rels = new RelTab();215 aggr = new Aggr(); 204 216 objs = new ObjMap(); 205 area = 0;206 length = 0;207 centre = new Snode();208 217 } 209 218 } … … 249 258 feature.geom = new Geom(p); 250 259 feature.type = obj; 251 index.put(id, feature); 260 if (obj != Obj.UNKOBJ) { 261 index.put(id, feature); 262 } 252 263 } 253 264 … … 262 273 break; 263 274 case 3: 264 r = Rflag. PEER;275 r = Rflag.UNKN; 265 276 break; 266 277 } 267 feature. rels.add(new Reln(id, r));278 feature.aggr.rels.add(new Reln(id, r)); 268 279 } 269 280 … … 296 307 297 308 public void endFile() { 309 sortGeom(); 298 310 for (long id : index.keySet()) { 299 311 Feature feature = index.get(id); 300 for (Reln rel : feature.rels) { 301 Feature reln = index.get(rel.id); 302 reln.reln = rel.reln; 303 if (feature.reln == Rflag.UNKN) { 304 switch (rel.reln) { 312 for (Reln reln : feature.aggr.rels) { 313 Feature rel = index.get(reln.id); 314 if (cmpGeoms(feature.geom, rel.geom)) { 315 switch (reln.reln) { 305 316 case MASTER: 306 317 feature.reln = Rflag.AGGR; … … 308 319 case SLAVE: 309 320 feature.reln = Rflag.MASTER; 310 case PEER:311 feature.reln = Rflag.PEER;312 321 break; 313 322 default: 323 feature.reln = Rflag.UNKN; 314 324 break; 315 325 } 316 } 317 ObjTab tab = feature.objs.get(reln.type); 318 if (tab == null) { 319 tab = new ObjTab(); 320 feature.objs.put(reln.type, tab); 321 } 322 tab.put(tab.size(), reln.atts); 326 rel.reln = reln.reln; 327 } else { 328 reln.reln = Rflag.UNKN; 329 } 323 330 } 324 331 } … … 328 335 feature.reln = Rflag.MASTER; 329 336 } 330 if ((feature.type != Obj.UNKOBJ) && ( (feature.reln == Rflag.MASTER) || (feature.reln == Rflag.PEER))) {337 if ((feature.type != Obj.UNKOBJ) && (feature.reln == Rflag.MASTER)) { 331 338 if (features.get(feature.type) == null) { 332 339 features.put(feature.type, new ArrayList<Feature>()); … … 335 342 } 336 343 } 337 sortGeom(); 344 for (long id : index.keySet()) { 345 Feature feature = index.get(id); 346 for (Reln reln : feature.aggr.rels) { 347 Feature rel = index.get(reln.id); 348 if (rel.reln == Rflag.SLAVE) { 349 if (feature.objs.get(rel.type) == null) { 350 feature.objs.put(rel.type, new ObjTab()); 351 } 352 ObjTab tab = feature.objs.get(rel.type); 353 int ix = tab.size(); 354 tab.put(ix, rel.atts); 355 } 356 } 357 } 338 358 } 339 359 … … 401 421 items = new ObjTab(); 402 422 feature.objs.put(obj, items); 403 } 404 AttMap atts = items.get(idx); 405 if (atts == null) { 406 atts = new AttMap(); 407 items.put(idx, atts); 408 } 409 AttVal<?> attval = S57val.convertValue(val, att); 410 if (attval.val != null) 411 atts.put(att, attval); 423 Feature type = new Feature(); 424 type.reln = Rflag.SLAVE; 425 type.type = obj; 426 type.geom = feature.geom; 427 } 428 // AttMap atts = items.get(idx); 429 // if (atts == null) { 430 // atts = new AttMap(); 431 // items.put(idx, atts); 432 // } 433 // AttVal<?> attval = S57val.convertValue(val, att); 434 // if (attval.val != null) 435 // atts.put(att, attval); 412 436 } else { 413 437 if (subkeys[1].equals("type")) { 414 feature.type= S57obj.enumType(val);438 obj = S57obj.enumType(val); 415 439 if (feature.objs.get(feature.type) == null) { 416 440 feature.objs.put(feature.type, new ObjTab()); 441 Feature type = new Feature(); 442 type.reln = Rflag.MASTER; 443 type.type = obj; 444 type.geom = feature.geom; 417 445 } 418 446 } else { … … 435 463 node.flg = Nflag.ISOL; 436 464 } 437 feature. length = 0;438 feature. area = 0;465 feature.geom.length = 0; 466 feature.geom.area = 0; 439 467 break; 440 468 case LINE: … … 442 470 nodes.get(edge.first).flg = Nflag.CONN; 443 471 nodes.get(edge.last).flg = Nflag.CONN; 444 feature. length = calcLength(feature.geom);472 feature.geom.length = calcLength(feature.geom); 445 473 if (edge.first == edge.last) { 446 474 feature.geom.prim = Pflag.AREA; 447 feature. area = calcArea(feature.geom);475 feature.geom.area = calcArea(feature.geom); 448 476 } else { 449 feature. area = 0;477 feature.geom.area = 0; 450 478 } 451 479 break; … … 460 488 features.put(feature.type, new ArrayList<Feature>()); 461 489 } 462 feature.centre = findCentroid(feature);463 490 features.get(feature.type).add(feature); 491 feature.geom.centre = findCentroid(feature); 464 492 } 465 493 } … … 470 498 for (long id : index.keySet()) { 471 499 feature = index.get(id); 472 Geom geom = feature.geom; 473 Geom sort = new Geom(geom.prim); 500 Geom sort = new Geom(feature.geom.prim); 474 501 long first = 0; 475 502 long last = 0; 476 503 Comp comp = null; 477 504 boolean next = true; 478 if (( geom.prim == Pflag.LINE) || (geom.prim == Pflag.AREA)) {479 int sweep = geom.elems.size();480 while (! geom.elems.isEmpty()) {481 Prim prim = geom.elems.remove(0);505 if ((feature.geom.prim == Pflag.LINE) || (feature.geom.prim == Pflag.AREA)) { 506 int sweep = feature.geom.elems.size(); 507 while (!feature.geom.elems.isEmpty()) { 508 Prim prim = feature.geom.elems.remove(0); 482 509 Edge edge = edges.get(prim.id); 483 510 if (next == true) { … … 509 536 comp.size++; 510 537 } else { 511 geom.elems.add(prim);538 feature.geom.elems.add(prim); 512 539 } 513 540 } else { … … 521 548 comp.size++; 522 549 } else { 523 geom.elems.add(prim);550 feature.geom.elems.add(prim); 524 551 } 525 552 } … … 527 554 if (--sweep == 0) { 528 555 next = true; 529 sweep = geom.elems.size(); 530 } 556 sweep = feature.geom.elems.size(); 557 } 558 } 559 if ((sort.prim == Pflag.LINE) && (sort.outers == 1) && (sort.inners == 0) && (first == last)) { 560 sort.prim = Pflag.AREA; 531 561 } 532 562 feature.geom = sort; 533 563 } 534 if ( geom.prim == Pflag.AREA) {564 if (feature.geom.prim == Pflag.AREA) { 535 565 ArrayList<Prim> outers = new ArrayList<Prim>(); 536 566 ArrayList<Prim> inners = new ArrayList<Prim>(); … … 544 574 ArrayList<Prim> sorting = outers; 545 575 ArrayList<Prim> closed = null; 546 sort = new Geom( geom.prim);576 sort = new Geom(feature.geom.prim); 547 577 sort.outers = feature.geom.outers; 548 578 sort.inners = feature.geom.inners; … … 596 626 } 597 627 628 public boolean cmpGeoms (Geom g1, Geom g2) { 629 return ((g1.prim == g2.prim) && (g1.outers == g2.outers) && (g1.inners == g2.inners) && (g1.elems.size() == g2.elems.size())); 630 } 631 598 632 public class EdgeIterator { 599 633 Edge edge; … … 653 687 int cc, ec; 654 688 Comp comp; 689 long lastref; 655 690 656 691 public GeomIterator(Geom g) { … … 659 694 cc = ec = 0; 660 695 comp = null; 696 lastref = 0; 661 697 if ((geom.prim != Pflag.NOSP) && (geom.prim != Pflag.POINT)) { 662 698 it = geom.elems.listIterator(); … … 690 726 } 691 727 long ref = eit.nextRef(); 728 if (ref == lastref) { 729 ref = eit.nextRef(); 730 } 731 lastref = ref; 692 732 if (!eit.hasNext()) { 693 733 eit = null;
Note:
See TracChangeset
for help on using the changeset viewer.