Ignore:
Timestamp:
2014-02-09T19:58:46+01:00 (11 years ago)
Author:
malcolmh
Message:

save

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/smed2/js57toosm/src/js57toosm/Js57toosm.java

    r30230 r30269  
    115115                                                break;
    116116                                        case "FFPT":
    117                                                 name = (long) S57dat.getSubf(record, fields + pos, S57field.FFPT, S57subf.LNAM);
    118                                                 int rind = ((Long) S57dat.getSubf(S57subf.RIND)).intValue();
    119                                                 map.newObj(name, rind);
     117                                                S57dat.setField(record, fields + pos, S57field.FFPT, len);
     118                                                do {
     119                                                        name = (long) S57dat.getSubf(S57subf.LNAM);
     120                                                        int rind = ((Long) S57dat.getSubf(S57subf.RIND)).intValue();
     121                                                        S57dat.getSubf(S57subf.COMT);
     122                                                        map.newObj(name, rind);
     123                                                } while (S57dat.more());
    120124                                                break;
    121125                                        case "FSPT":
     
    124128                                                        name = (Long) S57dat.getSubf(S57subf.NAME) << 16;
    125129                                                        map.newPrim(name, (long) S57dat.getSubf(S57subf.ORNT), (long) S57dat.getSubf(S57subf.USAG));
     130                                                        S57dat.getSubf(S57subf.MASK);
    126131                                                } while (S57dat.more());
    127132                                                break;
     
    153158                                                        int topi = ((Long) S57dat.getSubf(S57subf.TOPI)).intValue();
    154159                                                        map.addConn(name, topi);
     160                                                        S57dat.getSubf(S57subf.MASK);
    155161                                                } while (S57dat.more());
    156162                                                break;
     
    209215                for (long id : map.index.keySet()) {
    210216                        Feature feature = map.index.get(id);
    211                         if (feature.reln != Rflag.SLAVE) {
    212                                 if (feature.geom.prim == Pflag.POINT) {
    213                                         for (Prim prim : feature.geom.elems) {
    214                                                 long ref = prim.id;
    215                                                 Snode node = map.nodes.get(ref);
    216                                                 out.format("  <node id='%d' lat='%f' lon='%f' version='1'>%n", -ref, Math.toDegrees(node.lat), Math.toDegrees(node.lon));
    217                                                 String type = S57obj.stringType(feature.type);
    218                                                 out.format("    <tag k='seamark:type' v=\"%s\"/>%n", type);
    219                                                 if ((feature.type == Obj.SOUNDG) && (node.flg == S57map.Nflag.DPTH))
    220                                                         out.format("    <tag k='seamark:sounding:depth' v='%.1f'/>%n", ((Dnode)node).val);
    221                                                 writeAtts(feature, type);
    222                                                 out.format("  </node>%n");
    223                                                 map.nodes.remove(ref);
     217                        String type = S57obj.stringType(feature.type);
     218                        if (!type.isEmpty()) {
     219                                if (feature.reln == Rflag.MASTER) {
     220                                        if (feature.geom.prim == Pflag.POINT) {
     221                                                for (Prim prim : feature.geom.elems) {
     222                                                        long ref = prim.id;
     223                                                        Snode node;
     224                                                        while ((node = map.nodes.get(ref)) != null) {
     225                                                                out.format("  <node id='%d' lat='%.8f' lon='%.8f' version='1'>%n", -ref, Math.toDegrees(node.lat), Math.toDegrees(node.lon));
     226                                                                out.format("    <tag k='seamark:type' v=\"%s\"/>%n", type);
     227                                                                if ((feature.type == Obj.SOUNDG) && (node.flg == S57map.Nflag.DPTH))
     228                                                                        out.format("    <tag k='seamark:sounding:depth' v='%.1f'/>%n", ((Dnode) node).val);
     229                                                                writeAtts(feature, type);
     230                                                                out.format("  </node>%n");
     231                                                                map.nodes.remove(ref++);
     232                                                        }
     233                                                }
    224234                                        }
    225235                                }
     
    227237                }
    228238               
     239//int i = 256;
    229240                for (long id : map.index.keySet()) {
     241//if (i-- == 0) break;
    230242                        Feature feature = map.index.get(id);
    231                         if (feature.reln != Rflag.SLAVE) {
    232                                 if ((feature.geom.prim == Pflag.LINE) || ((feature.geom.prim == Pflag.AREA) && (feature.geom.outers == 1) && (feature.geom.inners == 0))) {
    233                                         GeomIterator git = map.new GeomIterator(feature.geom);
    234                                         while (git.hasMore()) {
    235                                                 git.getMore();
    236                                                 while (git.hasNext()) {
    237                                                         long ref = git.nextRef();
    238                                                         Snode node = map.nodes.get(ref);
    239                                                         if (node != null) {
    240                                                                 out.format("  <node id='%d' lat='%f' lon='%f' version='1'/>%n", -ref, Math.toDegrees(node.lat), Math.toDegrees(node.lon));
    241                                                                 map.nodes.remove(ref);
     243                        String type = S57obj.stringType(feature.type);
     244                        if (!type.isEmpty()) {
     245                                if (feature.reln == Rflag.MASTER) {
     246                                        if ((feature.geom.prim == Pflag.LINE) || ((feature.geom.prim == Pflag.AREA) && (feature.geom.outers == 1) && (feature.geom.inners == 0))) {
     247                                                GeomIterator git = map.new GeomIterator(feature.geom);
     248                                                while (git.hasMore()) {
     249                                                        git.getMore();
     250                                                        while (git.hasNext()) {
     251                                                                long ref = git.nextRef();
     252                                                                Snode node = map.nodes.get(ref);
     253                                                                if (node != null) {
     254                                                                        out.format("  <node id='%d' lat='%.8f' lon='%.8f' version='1'/>%n", -ref, Math.toDegrees(node.lat), Math.toDegrees(node.lon));
     255                                                                        map.nodes.remove(ref);
     256                                                                }
    242257                                                        }
    243258                                                }
     259                                                git = map.new GeomIterator(feature.geom);
     260                                                while (git.hasMore()) {
     261                                                        long way = git.getMore();
     262                                                        out.format("  <way id='%d' version='1'>%n", -way);
     263                                                        while (git.hasNext()) {
     264                                                                long ref = git.nextRef();
     265                                                                out.format("    <nd ref='%d'/>%n", -ref);
     266                                                        }
     267                                                        out.format("    <tag k='seamark:type' v=\"%s\"/>%n", type);
     268                                                        writeAtts(feature, type);
     269                                                        out.format("  </way>%n");
     270                                                }
     271                                        } else if (feature.geom.prim == Pflag.AREA) {
     272
    244273                                        }
    245                                         git = map.new GeomIterator(feature.geom);
    246                                         while (git.hasMore()) {
    247                                                 long way = git.getMore();
    248                                                 out.format("  <way id='%d' version='1'>%n", -way);
    249                                                 while (git.hasNext()) {
    250                                                         long ref = git.nextRef();
    251                                                         out.format("    <nd ref='%d'/>%n", -ref);
    252                                                 }
    253                                                 String type = S57obj.stringType(feature.type);
    254                                                 out.format("    <tag k='seamark:type' v=\"%s\"/>%n", type);
    255                                                 writeAtts(feature, type);
    256                                                 out.format("  </way>%n");
    257                                         }
    258                                 } else if (feature.geom.prim == Pflag.AREA) {
    259                                        
    260274                                }
    261275                        }
     
    271285                                out.format("    <tag k='seamark:%s:%s' v=\"%s\"/>%n", type, attstr, valstr);
    272286                }
    273                 for (Reln rel : feature.rels) {
    274                         if (rel.reln == Rflag.SLAVE) {
    275                                 Feature slave = map.index.get(rel.id);
    276                                 type = S57obj.stringType(slave.type);
    277                                 for (Map.Entry<Att, AttVal<?>> item : slave.atts.entrySet()) {
     287                for (Obj obj : feature.objs.keySet()) {
     288                        ObjTab tab = feature.objs.get(obj);
     289                        for (int ix : tab.keySet()) {
     290                                type = S57obj.stringType(obj);
     291                                AttMap atts = tab.get(ix);
     292                                for (Map.Entry<Att, AttVal<?>> item : atts.entrySet()) {
    278293                                        String attstr = S57att.stringAttribute(item.getKey());
    279294                                        String valstr = S57val.stringValue(item.getValue());
    280                                         if (!attstr.isEmpty() && !valstr.isEmpty())
    281                                                 out.format("    <tag k='seamark:%s:%s' v=\"%s\"/>%n", type, attstr, valstr);
     295                                        if (!attstr.isEmpty() && !valstr.isEmpty()) {
     296                                                if ((ix == 0) && (tab.size() == 1)) {
     297                                                        out.format("    <tag k='seamark:%s:%s' v=\"%s\"/>%n", type, attstr, valstr);
     298                                                } else {
     299                                                        out.format("    <tag k='seamark:%s:%d:%s' v=\"%s\"/>%n", type, ix + 1, attstr, valstr);
     300                                                }
     301                                        }
    282302                                }
    283303                        }
    284304                }
    285 
    286305        }
    287306
Note: See TracChangeset for help on using the changeset viewer.