Ignore:
Timestamp:
2014-01-19T14:52:39+01:00 (11 years ago)
Author:
malcolmh
Message:

new model structure

File:
1 edited

Legend:

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

    r30189 r30215  
    1111
    1212import java.io.*;
    13 
     13import java.util.Map;
     14
     15import s57.S57obj;
     16import s57.S57att;
     17import s57.S57att.*;
     18import s57.S57val;
     19import s57.S57val.*;
    1420import s57.S57dat;
    1521import s57.S57dat.*;
     
    3440                int len;
    3541                int pos;
     42                boolean inFeature = false;
    3643               
    3744                double comf = 1;
     
    3946                long name = 0;
    4047                S57map.Nflag nflag = Nflag.ANON;
     48                S57map.Pflag prim = S57map.Pflag.NOSP;
     49                long objl = 0;
    4150                S57map map = new S57map();
    4251                double minlat = 90, minlon = 180, maxlat = -90, maxlon = -180;
     
    6776                                                }
    6877                                                break;
    69                                         case "DSID":
    70                                                 break;
    71                                         case "DSSI":
    72                                                 break;
    7378                                        case "DSPM":
    7479                                                comf = (double) (Long) S57dat.getSubf(record, fields + pos, S57field.DSPM, S57subf.COMF);
     
    7681                                                break;
    7782                                        case "FRID":
     83                                                inFeature = true;
     84                                                switch ((int)((long)S57dat.getSubf(record, fields + pos, S57field.FRID, S57subf.PRIM))) {
     85                                                case 1:
     86                                                        prim = S57map.Pflag.POINT;
     87                                                        break;
     88                                                case 2:
     89                                                        prim = S57map.Pflag.LINE;
     90                                                        break;
     91                                                case 3:
     92                                                        prim = S57map.Pflag.AREA;
     93                                                        break;
     94                                                default:
     95                                                        prim = S57map.Pflag.NOSP;
     96                                                }
     97                                                objl = (long)S57dat.getSubf(S57subf.OBJL);
    7898                                                break;
    7999                                        case "FOID":
     100                                                name = (long) S57dat.getSubf(record, fields + pos, S57field.FOID, S57subf.LNAM);
     101                                                map.newFeature(name, prim, objl);
    80102                                                break;
    81103                                        case "ATTF":
    82                                                 break;
    83                                         case "NATF":
    84                                                 break;
    85                                         case "FFPC":
     104                                                S57dat.setField(record, fields + pos, S57field.ATTF, len);
     105                                                do {
     106                                                        long attl = (long) S57dat.getSubf(S57subf.ATTL);
     107                                                        String atvl = (String) S57dat.getSubf(S57subf.ATVL);
     108                                                        map.newAtt(attl, atvl);
     109                                                } while (S57dat.more());
    86110                                                break;
    87111                                        case "FFPT":
    88                                                 break;
    89                                         case "FSPC":
     112                                                name = (long) S57dat.getSubf(record, fields + pos, S57field.FFPT, S57subf.LNAM);
     113                                                int rind = ((Long) S57dat.getSubf(S57subf.RIND)).intValue();
     114                                                map.newObj(name, rind);
    90115                                                break;
    91116                                        case "FSPT":
     117                                                S57dat.setField(record, fields + pos, S57field.FSPT, len);
     118                                                do {
     119                                                        name = (Long) S57dat.getSubf(S57subf.NAME) << 16;
     120                                                        map.newPrim(name, (long) S57dat.getSubf(S57subf.ORNT), (long) S57dat.getSubf(S57subf.USAG));
     121                                                } while (S57dat.more());
    92122                                                break;
    93123                                        case "VRID":
    94                                                 name = (Long) S57dat.getSubf(record, fields + pos, S57field.VRID, S57subf.RCNM);
     124                                                inFeature = false;
     125                                                name = (long) S57dat.getSubf(record, fields + pos, S57field.VRID, S57subf.RCNM);
    95126                                                switch ((int) name) {
    96127                                                case 110:
     
    105136                                                }
    106137                                                name <<= 32;
    107                                                 name += (Long) S57dat.getSubf(record, fields + pos, S57field.VRID, S57subf.RCID);
     138                                                name += (Long) S57dat.getSubf(S57subf.RCID);
    108139                                                name <<= 16;
    109140                                                if (nflag == Nflag.ANON) {
     
    111142                                                }
    112143                                                break;
    113                                         case "ATTV":
    114                                                 break;
    115                                         case "VRPC":
    116                                                 break;
    117144                                        case "VRPT":
    118                                                 name = (Long) S57dat.getSubf(record, fields + pos, S57field.VRPT, S57subf.NAME) << 16;
    119                                                 int topi = ((Long) S57dat.getSubf(S57subf.TOPI)).intValue();
    120                                                 map.addConn(name, topi);
    121                                                 name = (Long) S57dat.getSubf(S57subf.NAME) << 16;
    122                                                 topi = ((Long) S57dat.getSubf(S57subf.TOPI)).intValue();
    123                                                 map.addConn(name, topi);
    124                                                 break;
    125                                         case "SGCC":
     145                                                S57dat.setField(record, fields + pos, S57field.VRPT, len);
     146                                                do {
     147                                                        name = (Long) S57dat.getSubf(S57subf.NAME) << 16;
     148                                                        int topi = ((Long) S57dat.getSubf(S57subf.TOPI)).intValue();
     149                                                        map.addConn(name, topi);
     150                                                } while (S57dat.more());
    126151                                                break;
    127152                                        case "SG2D":
    128153                                                S57dat.setField(record, fields + pos, S57field.SG2D, len);
    129                                                 while (S57dat.more()) {
     154                                                do {
    130155                                                        double lat = (double) ((Long) S57dat.getSubf(S57subf.YCOO)) / comf;
    131156                                                        double lon = (double) ((Long) S57dat.getSubf(S57subf.XCOO)) / comf;
     
    143168                                                        if (lon > maxlon)
    144169                                                                maxlon = lon;
    145                                                 }
     170                                                } while (S57dat.more());
    146171                                                break;
    147172                                        case "SG3D":
    148173                                                S57dat.setField(record, fields + pos, S57field.SG3D, len);
    149                                                 while (S57dat.more()) {
     174                                                do {
    150175                                                        double lat = (double) ((Long) S57dat.getSubf(S57subf.YCOO)) / comf;
    151176                                                        double lon = (double) ((Long) S57dat.getSubf(S57subf.XCOO)) / comf;
     
    160185                                                        if (lon > maxlon)
    161186                                                                maxlon = lon;
    162                                                 }
     187                                                } while (S57dat.more());
    163188                                                break;
    164189                                        }
    165190                                }
    166                         }
    167                 }
     191                                if (inFeature) {
     192                                        map.endFeature();
     193                                        inFeature = false;
     194                                }
     195                        }
     196                }
     197                map.endFile();
    168198                in.close();
    169199               
     
    172202                out.println("<bounds minlat='" + minlat +"' minlon='" + minlon + "' maxlat='" + maxlat + "' maxlon='" + maxlon + "'/>");
    173203               
     204                for (long id : map.index.keySet()) {
     205                        Feature feature = map.index.get(id);
     206                        if (feature.reln != Rflag.SLAVE) {
     207                                if (feature.geom.prim == Pflag.POINT) {
     208                                        Snode node = map.nodes.get(feature.geom.elems.get(0).id);
     209                                        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));
     211                                        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()));
     214                                        }
     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                                                        }
     222                                                }
     223                                        }
     224                                        out.format("  </node>%n");
     225                                }
     226                        }
     227                }
     228/*             
    174229                for (long id : map.nodes.keySet()) {
    175230                        Snode node = map.nodes.get(id);
     
    194249                        out.format("  </way>%n");
    195250                }
    196                
     251*/             
    197252                out.println("</osm>\n");
    198253        }
Note: See TracChangeset for help on using the changeset viewer.