Ignore:
Timestamp:
2014-01-25T17:56:23+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

    r30215 r30226  
    2525public class Js57toosm {
    2626       
     27        static FileInputStream in;
     28        static PrintStream out;
     29        static S57map map;
     30       
    2731        public static void main(String[] args) throws IOException {
    2832
    29                 FileInputStream in = new FileInputStream("/Users/mherring/boatsw/oseam/josm/plugins/smed2/js57toosm/tst.000");
    30                 PrintStream out = System.out;
     33                in = new FileInputStream("/Users/mherring/boatsw/oseam/josm/plugins/smed2/js57toosm/tst.000");
     34                out = System.out;
     35                map = new S57map();
    3136
    3237                S57dat.rnum = 0;
     
    4853                S57map.Pflag prim = S57map.Pflag.NOSP;
    4954                long objl = 0;
    50                 S57map map = new S57map();
    5155                double minlat = 90, minlon = 180, maxlat = -90, maxlon = -180;
    5256
     
    206210                        if (feature.reln != Rflag.SLAVE) {
    207211                                if (feature.geom.prim == Pflag.POINT) {
    208                                         Snode node = map.nodes.get(feature.geom.elems.get(0).id);
     212                                        long ref = feature.geom.elems.get(0).id;
     213                                        Snode node = map.nodes.get(ref);
    209214                                        String type = S57obj.stringType(feature.type);
    210                                         out.format("  <node id='%d' lat='%f' lon='%f' version='1'>%n",-id,  Math.toDegrees(node.lat), Math.toDegrees(node.lon));
     215                                        out.format("  <node id='%d' lat='%f' lon='%f' version='1'>%n", -ref,  Math.toDegrees(node.lat), Math.toDegrees(node.lon));
    211216                                        out.format("    <tag k='seamark:type' v=\"%s\"/>%n", type);
    212                                         for (Map.Entry<Att, AttVal<?>> item : feature.atts.entrySet()) {
    213                                                 out.format("    <tag k='seamark:%s:%s' v=\"%s\"/>%n", type, S57att.stringAttribute(item.getKey()), S57val.stringValue(item.getValue()));
     217                                        writeAtts(feature, type);
     218                                        out.format("  </node>%n");
     219                                        map.nodes.remove(ref);
     220                                }
     221                        }
     222                }
     223               
     224                for (long id : map.index.keySet()) {
     225                        Feature feature = map.index.get(id);
     226                        if (feature.reln != Rflag.SLAVE) {
     227                                if (feature.geom.prim == Pflag.LINE) {
     228                                        GeomIterator git = map.new GeomIterator(feature.geom);
     229                                        while (git.hasMore()) {
     230                                                git.more();
     231                                                while (git.hasNext()) {
     232                                                        long ref = git.nextRef();
     233                                                        Snode node = map.nodes.get(ref);
     234                                                        if (node != null) {
     235                                                                out.format("  <node id='%d' lat='%f' lon='%f' version='1'/>%n", -ref, Math.toDegrees(node.lat), Math.toDegrees(node.lon));
     236                                                                map.nodes.remove(ref);
     237                                                        }
     238                                                }
    214239                                        }
    215                                         for (Reln rel : feature.rels) {
    216                                                 if (rel.reln == Rflag.SLAVE) {
    217                                                         Feature slave = map.index.get(rel.id);
    218                                                         type = S57obj.stringType(slave.type);
    219                                                         for (Map.Entry<Att, AttVal<?>> item : slave.atts.entrySet()) {
    220                                                                 out.format("    <tag k='seamark:%s:%s' v=\"%s\"/>%n", type, S57att.stringAttribute(item.getKey()), S57val.stringValue(item.getValue()));
    221                                                         }
     240                                        out.format("  <way id='%d' version='1'>%n", -id);
     241                                        git = map.new GeomIterator(feature.geom);
     242                                        while (git.hasMore()) {
     243                                                git.more();
     244                                                while (git.hasNext()) {
     245                                                        long ref = git.nextRef();
     246                                                        out.format("    <nd ref='%d'/>%n", -ref);
    222247                                                }
    223248                                        }
    224                                         out.format("  </node>%n");
    225                                 }
    226                         }
    227                 }
    228 /*             
    229                 for (long id : map.nodes.keySet()) {
     249                                        String type = S57obj.stringType(feature.type);
     250                                        out.format("    <tag k='seamark:type' v=\"%s\"/>%n", type);
     251                                        writeAtts(feature, type);
     252                                        out.format("  </way>%n");
     253                                }
     254                        }
     255                }
     256/*              for (long id : map.nodes.keySet()) {
    230257                        Snode node = map.nodes.get(id);
    231258                        if (node.flg == S57map.Nflag.DPTH) {
     
    234261                                out.format("    <tag k='seamark:sounding:depth' v='%.1f'/>%n", ((Dnode)node).val);
    235262                                out.format("  </node>%n");
    236                         } else {
    237                                 out.format("  <node id='%d' lat='%f' lon='%f' version='1'/>%n",-id,  Math.toDegrees(node.lat), Math.toDegrees(node.lon));
     263                                map.nodes.remove(id);
    238264                        }
    239265                }
     
    252278                out.println("</osm>\n");
    253279        }
     280       
     281        static void writeAtts(Feature feature, String type) {
     282                for (Map.Entry<Att, AttVal<?>> item : feature.atts.entrySet()) {
     283                        String attstr = S57att.stringAttribute(item.getKey());
     284                        String valstr = S57val.stringValue(item.getValue());
     285                        if (!attstr.isEmpty() && !valstr.isEmpty())
     286                                out.format("    <tag k='seamark:%s:%s' v=\"%s\"/>%n", type, attstr, valstr);
     287                }
     288                for (Reln rel : feature.rels) {
     289                        if (rel.reln == Rflag.SLAVE) {
     290                                Feature slave = map.index.get(rel.id);
     291                                type = S57obj.stringType(slave.type);
     292                                for (Map.Entry<Att, AttVal<?>> item : slave.atts.entrySet()) {
     293                                        String attstr = S57att.stringAttribute(item.getKey());
     294                                        String valstr = S57val.stringValue(item.getValue());
     295                                        if (!attstr.isEmpty() && !valstr.isEmpty())
     296                                                out.format("    <tag k='seamark:%s:%s' v=\"%s\"/>%n", type, attstr, valstr);
     297                                }
     298                        }
     299                }
     300
     301        }
    254302
    255303}
Note: See TracChangeset for help on using the changeset viewer.