Changeset 31014 in osm for applications/editors/josm/plugins/seachart/src/s57
- Timestamp:
- 2015-02-17T14:05:54+01:00 (10 years ago)
- Location:
- applications/editors/josm/plugins/seachart/src/s57
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/seachart/src/s57/S57att.java
r30992 r31014 10 10 package s57; 11 11 12 import java.util.EnumMap; 13 import java.util.HashMap; 14 import java.util.Map; 12 import java.util.*; 15 13 16 14 import s57.S57obj.*; -
applications/editors/josm/plugins/seachart/src/s57/S57map.java
r30996 r31014 27 27 public double maxlon; 28 28 public MapBounds() { 29 minlat = 90;30 minlon = 180;31 maxlat = -90;32 maxlon = -180;29 minlat = Math.toRadians(90); 30 minlon = Math.toRadians(180); 31 maxlat = Math.toRadians(-90); 32 maxlon = Math.toRadians(-180); 33 33 } 34 34 } … … 221 221 } 222 222 } 223 224 class OSMtag { 225 String key; 226 String val; 227 OSMtag(String k, String v) { 228 key = k; 229 val = v; 230 } 231 } 232 233 ArrayList<OSMtag> osmtags; 223 234 224 235 public NodeTab nodes; … … 227 238 public FtrMap features; 228 239 public FtrTab index; 229 230 public long ref; 240 241 public MapBounds bounds; 242 243 public long cref; 244 public long xref; 231 245 private Feature feature; 232 246 private Edge edge; … … 238 252 features = new FtrMap(); // All features in map, grouped by type 239 253 index = new FtrTab(); // Feature look-up table 240 ref = 0x0000ffffffff0000L;// Compound reference generator 254 bounds = new MapBounds(); 255 cref = 0x0000ffffffff0000L;// Compound reference generator 256 xref = 0x0fff000000000000L;// Extras reference generator 241 257 } 242 258 … … 371 387 feature.geom.prim = Pflag.POINT; 372 388 feature.geom.elems.add(new Prim(id)); 389 osmtags = new ArrayList<OSMtag>(); 373 390 edge = null; 374 391 } … … 379 396 feature.geom.prim = Pflag.LINE; 380 397 feature.geom.elems.add(new Prim(id)); 398 osmtags = new ArrayList<OSMtag>(); 381 399 edge = new Edge(); 382 400 } … … 398 416 feature.reln = Rflag.UNKN; 399 417 feature.geom.prim = Pflag.AREA; 418 osmtags = new ArrayList<OSMtag>(); 400 419 edge = null; 401 420 } … … 457 476 } 458 477 } 478 } else { 479 osmtags.add(new OSMtag(key, val)); 459 480 } 460 481 } 461 482 462 483 public void tagsDone(long id) { 484 if (feature.type == Obj.UNKOBJ) { 485 for (OSMtag tag : osmtags) { 486 Obj obj = S57obj.OSMobj(tag.key, tag.val); 487 if (obj != Obj.UNKOBJ) { 488 feature.type = obj; 489 ObjTab objs = feature.objs.get(obj); 490 if (objs == null) { 491 objs = new ObjTab(); 492 feature.objs.put(obj, objs); 493 } 494 AttMap atts = objs.get(0); 495 if (atts == null) { 496 atts = new AttMap(); 497 objs.put(0, atts); 498 } 499 AttVal<?> attval = S57val.OSMatt(tag.key, tag.val); 500 if (attval.att != Att.UNKATT) { 501 atts.put(attval.att, attval); 502 } 503 break; 504 } 505 } 506 } 463 507 switch (feature.geom.prim) { 464 508 case POINT: … … 490 534 } 491 535 } 536 537 public void mapDone() { 538 ArrayList<Feature> coasts = new ArrayList<Feature>(); 539 ArrayList<Feature> lands = new ArrayList<Feature>(); 540 if (features.get(Obj.LNDARE) == null) { 541 features.put(Obj.LNDARE, new ArrayList<Feature>()); 542 } 543 for (Feature feature : features.get(Obj.COALNE)) { 544 Feature land = new Feature(); 545 land.type = Obj.LNDARE; 546 land.reln = Rflag.MASTER; 547 land.objs.put(Obj.LNDARE, new ObjTab()); 548 if (feature.geom.prim == Pflag.AREA) { 549 land.geom = feature.geom; 550 features.get(Obj.LNDARE).add(land); 551 } else if (feature.geom.prim == Pflag.LINE) { 552 land.geom.prim = Pflag.LINE; 553 for (int i = 0; i < feature.geom.elems.size(); i++) { 554 land.geom.elems.add(feature.geom.elems.get(i)); 555 } 556 coasts.add(land); 557 } 558 } 559 while (coasts.size() > 0) { 560 Feature land = coasts.remove(0); 561 Edge fedge = edges.get(land.geom.elems.get(0).id); 562 long first = fedge.first; 563 long last = edges.get(land.geom.elems.get(land.geom.elems.size() - 1).id).last; 564 if (coasts.size() > 0) { 565 boolean added = true; 566 while (added) { 567 added = false; 568 for (int i = 0; i < coasts.size(); i++) { 569 Feature coast = coasts.get(i); 570 Edge edge = edges.get(coast.geom.elems.get(0).id); 571 if (edge.first == last) { 572 land.geom.elems.add(coast.geom.elems.get(0)); 573 last = edge.last; 574 coasts.remove(i--); 575 added = true; 576 } else if (edge.last == first) { 577 land.geom.elems.add(0, coast.geom.elems.get(0)); 578 first = edge.first; 579 coasts.remove(i--); 580 added = true; 581 } 582 } 583 } 584 } 585 lands.add(land); 586 } 587 for (Feature land : lands) { 588 long first = edges.get(land.geom.elems.get(0).id).first; 589 long last = edges.get(land.geom.elems.get(land.geom.elems.size()-1).id).last; 590 Ext fext = outsideBounds(first); 591 Ext lext = outsideBounds(last); 592 Edge nedge = new Edge(); 593 nedge.first = last; 594 nedge.last = first; 595 switch (lext) { 596 case NE: 597 case N: 598 if ((fext != Ext.NE) && (fext != Ext.N)) { 599 nedge.nodes.add(1L); 600 if ((fext != Ext.NW) && (fext != Ext.W)) { 601 nedge.nodes.add(2L); 602 if ((fext != Ext.SW) && (fext != Ext.S)) { 603 nedge.nodes.add(3L); 604 if ((fext != Ext.SE) && (fext != Ext.W)) { 605 nedge.nodes.add(4L); 606 } 607 } 608 } 609 } 610 break; 611 case NW: 612 case W: 613 if ((fext != Ext.NW) && (fext != Ext.W)) { 614 nedge.nodes.add(2L); 615 if ((fext != Ext.SW) && (fext != Ext.S)) { 616 nedge.nodes.add(3L); 617 if ((fext != Ext.SE) && (fext != Ext.E)) { 618 nedge.nodes.add(4L); 619 if ((fext != Ext.NE) && (fext != Ext.N)) { 620 nedge.nodes.add(1L); 621 } 622 } 623 } 624 } 625 break; 626 case SW: 627 case S: 628 if ((fext != Ext.SW) && (fext != Ext.S)) { 629 nedge.nodes.add(3L); 630 if ((fext != Ext.SE) && (fext != Ext.E)) { 631 nedge.nodes.add(4L); 632 if ((fext != Ext.NE) && (fext != Ext.N)) { 633 nedge.nodes.add(1L); 634 if ((fext != Ext.NW) && (fext != Ext.W)) { 635 nedge.nodes.add(2L); 636 } 637 } 638 } 639 } 640 break; 641 case SE: 642 case E: 643 if ((fext != Ext.SE) && (fext != Ext.E)) { 644 nedge.nodes.add(4L); 645 if ((fext != Ext.NE) && (fext != Ext.N)) { 646 nedge.nodes.add(1L); 647 if ((fext != Ext.NW) && (fext != Ext.W)) { 648 nedge.nodes.add(2L); 649 if ((fext != Ext.SW) && (fext != Ext.S)) { 650 nedge.nodes.add(3L); 651 } 652 } 653 } 654 } 655 break; 656 default: 657 } 658 edges.put(++xref, nedge); 659 land.geom.elems.add(new Prim(xref)); 660 sortGeom(land); 661 features.get(Obj.LNDARE).add(land); 662 } 663 } 492 664 493 665 // Utility methods 666 667 enum Ext {I, N, NW, W, SW, S, SE, E, NE } 668 Ext outsideBounds(long ref) { 669 Snode node = nodes.get(ref); 670 if (node.lat >= bounds.maxlat) { 671 if (node.lon <= bounds.minlon) { 672 return Ext.NW; 673 } else if (node.lon >= bounds.maxlon) { 674 return Ext.NE; 675 } 676 return Ext.N; 677 } 678 if (node.lat <= bounds.minlat) { 679 if (node.lon <= bounds.minlon) { 680 return Ext.SW; 681 } else if (node.lon >= bounds.maxlon) { 682 return Ext.SE; 683 } 684 return Ext.S; 685 } 686 if (node.lon >= bounds.maxlon) { 687 if (node.lat <= bounds.minlat) { 688 return Ext.SE; 689 } else if (node.lat >= bounds.maxlat) { 690 return Ext.NE; 691 } 692 return Ext.E; 693 } 694 if (node.lon <= bounds.minlon) { 695 if (node.lat <= bounds.minlat) { 696 return Ext.SW; 697 } else if (node.lat >= bounds.maxlat) { 698 return Ext.NW; 699 } 700 return Ext.W; 701 } 702 return Ext.I; 703 } 494 704 495 705 public boolean sortGeom(Feature feature) { … … 526 736 sort.inners++; 527 737 } 528 comp = new Comp( ref++, 1);738 comp = new Comp(cref++, 1); 529 739 sort.refs.add(comp); 530 740 } else { -
applications/editors/josm/plugins/seachart/src/s57/S57obj.java
r30992 r31014 10 10 package s57; 11 11 12 import java.util.EnumMap; 13 import java.util.HashMap; 14 import java.util.Map; 12 import java.util.*; 15 13 16 14 public class S57obj { … … 179 177 return Obj.UNKOBJ; 180 178 } 179 180 private static final HashMap<String, Obj> OSMtags = new HashMap<String, Obj>(); 181 static { 182 OSMtags.put("natural=coastline", Obj.COALNE); OSMtags.put("natural=water", Obj.LAKARE); 183 OSMtags.put("waterway=riverbank", Obj.RIVBNK); OSMtags.put("waterway=river", Obj.RIVERS); OSMtags.put("waterway=canal", Obj.CANALS); 184 OSMtags.put("wetland=tidalflat", Obj.DEPARE); 185 } 186 187 public static Obj OSMobj(String key, String val) { 188 Obj obj = OSMtags.get(key + "=" + val); 189 if (obj != null) { 190 return obj; 191 } 192 return Obj.UNKOBJ; 193 } 181 194 182 195 } -
applications/editors/josm/plugins/seachart/src/s57/S57val.java
r30992 r31014 10 10 package s57; 11 11 12 import java.util.ArrayList; 13 import java.util.EnumMap; 12 import java.util.*; 14 13 15 14 import s57.S57att.*; … … 1243 1242 } 1244 1243 1244 static class KeyVal { 1245 Att key; 1246 Object val; 1247 KeyVal(Att k, Object v) { 1248 key = k; 1249 val = v; 1250 } 1251 } 1252 1253 private static final HashMap<String, KeyVal> OSMtags = new HashMap<String, KeyVal>(); 1254 static { 1255 OSMtags.put("wetland=tidalflat", new KeyVal(Att.DRVAL2, (double)0)); 1256 } 1257 1258 public static AttVal OSMatt(String key, String val) { 1259 KeyVal att = OSMtags.get(key + "=" + val); 1260 if (att != null) { 1261 return new AttVal(att.key, Conv.F, att.val); 1262 } 1263 return new AttVal(Att.UNKATT, Conv.A, null); 1264 } 1265 1245 1266 }
Note:
See TracChangeset
for help on using the changeset viewer.