Changeset 30186 in osm


Ignore:
Timestamp:
2014-01-06T16:26:41+01:00 (11 years ago)
Author:
malcolmh
Message:

save

Location:
applications/editors/josm/plugins/smed2
Files:
4 edited

Legend:

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

    r30184 r30186  
    1919public class Js57toosm {
    2020       
     21        public static int rnum = 0;
     22
    2123        public static void main(String[] args) throws IOException {
    2224
    23                 FileInputStream in = new FileInputStream("/Users/mherring/boatsw/oseam/openseamap/renderer/js57toosm/tst.000");
     25                FileInputStream in = new FileInputStream("/Users/mherring/boatsw/oseam/josm/plugins/smed2/js57toosm/tst.000");
    2426                PrintStream out = System.out;
    2527
     
    3638                double somf = 1;
    3739                long name = 0;
    38                 S57map map = new S57map();;
     40                S57map.Nflag nflag = Nflag.ANON;
     41                S57map map = new S57map();
     42                double minlat = 90, minlon = 180, maxlat = -90, maxlon = -180;
    3943
    4044                while (in.read(leader) == 24) {
     
    5559                                if (!ddr) switch (tag) {
    5660                                case "0001":
    57                                         out.println("Record: " + (long)S57dat.getSubf(record, fields+pos, S57field.I8RI, S57subf.I8RN));
     61                                        int i8rn = (int)(long)S57dat.getSubf(record, fields+pos, S57field.I8RI, S57subf.I8RN);
     62                                        if (i8rn != ++rnum) {
     63                                                out.println("Out of order record ID");
     64                                                in.close();
     65                                                System.exit(-1);
     66                                        }
    5867                                        break;
    5968                                case "DSID":
     
    8291                                        break;
    8392                                case "VRID":
    84                                         name = (long)S57dat.getSubf(record, fields+pos, S57field.VRID, S57subf.RCNM) << 32;
     93                                        name = (long)S57dat.getSubf(record, fields+pos, S57field.VRID, S57subf.RCNM);
     94                                        switch ((int)name) {
     95                                        case 110:
     96                                                nflag = Nflag.ISOL;
     97                                                break;
     98                                        case 120:
     99                                                nflag = Nflag.CONN;
     100                                                break;
     101                                        default:
     102                                                nflag = Nflag.ANON;
     103                                                break;
     104                                        }
     105                                        name <<= 32;
    85106                                        name += (long)S57dat.getSubf(record, fields+pos, S57field.VRID, S57subf.RCID);
    86107                                        name <<= 16;
     108                                        if (nflag == Nflag.ANON) {
     109                                                map.newEdge(name);
     110                                        }
    87111                                        break;
    88112                                case "ATTV":
     
    91115                                        break;
    92116                                case "VRPT":
     117                                        name = (long)S57dat.getSubf(record, fields+pos, S57field.VRPT, S57subf.NAME) << 16;
     118                                        int topi = (int)((long)S57dat.getSubf(S57subf.TOPI));
     119                                        map.addConn(name, topi);
     120                                        name = (long)S57dat.getSubf(S57subf.NAME) << 16;
     121                                        topi = (int)((long)S57dat.getSubf(S57subf.TOPI));
     122                                        map.addConn(name, topi);
    93123                                        break;
    94124                                case "SGCC":
     
    99129                                                double lat = (double) ((long) S57dat.getSubf(S57subf.YCOO)) / comf;
    100130                                                double lon = (double) ((long) S57dat.getSubf(S57subf.XCOO)) / comf;
    101                                                 map.addNode(name++, lat, lon);
     131                                                if (nflag == Nflag.ANON) {
     132                                                        map.newNode(++name, lat, lon, nflag);
     133                                                } else {
     134                                                        map.newNode(name, lat, lon, nflag);
     135                                                }
     136                                                if (lat < minlat) minlat = lat;
     137                                                if (lat > maxlat) maxlat = lat;
     138                                                if (lon < minlon) minlon = lon;
     139                                                if (lon > maxlon) maxlon = lon;
    102140                                        }
    103141                                        break;
     
    108146                                                double lon = (double) ((long) S57dat.getSubf(S57subf.XCOO)) / comf;
    109147                                                double depth = (double) ((long) S57dat.getSubf(S57subf.VE3D)) / somf;
    110                                                 map.addNode(name++, lat, lon, depth);
     148                                                map.newNode(name++, lat, lon, depth);
     149                                                if (lat < minlat) minlat = lat;
     150                                                if (lat > maxlat) maxlat = lat;
     151                                                if (lon < minlon) minlon = lon;
     152                                                if (lon > maxlon) maxlon = lon;
    111153                                        }
    112154                                        break;
     
    114156                        }
    115157                }
    116                 int a = 0; int i = 0; int c = 0; int d = 0;
    117                 for (Snode node : map.nodes.values()) {
    118                         switch (node.flg) {
    119                         case ANON: a++; break;
    120                         case ISOL: i++; break;
    121                         case CONN: c++; break;
    122                         case DPTH: d++; break;
     158                in.close();
     159               
     160                out.println("<?xml version='1.0' encoding='UTF-8'?>");
     161                out.println("<osm version='0.6' generator='js57toosm'>");
     162                out.println("<bounds minlat='" + minlat +"' minlon='" + minlon + "' maxlat='" + maxlat + "' maxlon='" + maxlon + "'/>");
     163               
     164                for (long id : map.nodes.keySet()) {
     165                        Snode node = map.nodes.get(id);
     166                        if (node.flg == S57map.Nflag.DPTH) {
     167                                out.format("  <node id='%d' lat='%f' lon='%f' version='1'>%n", -id, Math.toDegrees(node.lat), Math.toDegrees(node.lon));
     168                                out.format("    <tag k='seamark:type' v='sounding'/>%n");
     169                                out.format("    <tag k='seamark:sounding:depth' v='%.1f'/>%n", ((Dnode)node).val);
     170                                out.format("  </node>%n");
     171                        } else {
     172                                out.format("  <node id='%d' lat='%f' lon='%f' version='1'/>%n",-id,  Math.toDegrees(node.lat), Math.toDegrees(node.lon));
    123173                        }
    124174                }
    125                 out.println("Anon " + a);
    126                 out.println("Isol " + i);
    127                 out.println("Conn " + c);
    128                 out.println("Dpth " + d);
    129                 in.close();
     175               
     176                for (long id : map.edges.keySet()) {
     177                        Edge edge = map.edges.get(id);
     178                        out.format("  <way id='%d' version='1'>%n", -id);
     179                        out.format("    <nd ref='%d'/>%n", -edge.first);
     180                        for (long anon : edge.nodes) {
     181                                out.format("    <nd ref='%d'/>%n", -anon);
     182                        }
     183                        out.format("    <nd ref='%d'/>%n", -edge.last);
     184                        out.format("  </way>%n");
     185                }
     186               
     187                out.println("</osm>\n");
    130188        }
    131189
  • applications/editors/josm/plugins/smed2/src/render/Renderer.java

    r30184 r30186  
    198198                switch (feature.flag) {
    199199                case LINE:
    200                         Edge edge = map.edges.get(feature.id);
     200                        Edge edge = map.edges.get(feature.refs);
    201201                        area = map.new Area();
    202202                        area.add(map.new Bound(map.new Side(edge, true), true));
    203203                        break;
    204204                case AREA:
    205                         area = map.areas.get(feature.id);
     205                        area = map.areas.get(feature.refs);
    206206                        break;
    207207                default:
     
    288288                switch (feature.flag) {
    289289                case LINE:
    290                         EdgeIterator eit = map.new EdgeIterator(map.edges.get(feature.id), true);
     290                        EdgeIterator eit = map.new EdgeIterator(map.edges.get(feature.refs), true);
    291291                        point = context.getPoint(eit.next());
    292292                        p.moveTo(point.getX(), point.getY());
     
    297297                        break;
    298298                case AREA:
    299                         for (Bound bound : map.areas.get(feature.id)) {
     299                        for (Bound bound : map.areas.get(feature.refs)) {
    300300                                BoundIterator bit = map.new BoundIterator(bound);
    301301                                point = context.getPoint(bit.next());
     
    373373                        break;
    374374                case AREA:
    375                         for (Bound bound : map.areas.get(feature.id)) {
     375                        for (Bound bound : map.areas.get(feature.refs)) {
    376376                                BoundIterator bit = map.new BoundIterator(bound);
    377377                                point = context.getPoint(bit.next());
     
    506506                switch (feature.flag) {
    507507                case LINE:
    508                         Edge edge = map.edges.get(feature.id);
     508                        Edge edge = map.edges.get(feature.refs);
    509509                        area = map.new Area();
    510510                        area.add(map.new Bound(map.new Side(edge, true), true));
    511511                        break;
    512512                case AREA:
    513                         area = map.areas.get(feature.id);
     513                        area = map.areas.get(feature.refs);
    514514                        break;
    515515                default:
  • applications/editors/josm/plugins/smed2/src/s57/S57dat.java

    r30183 r30186  
    44import java.util.Arrays;
    55import java.util.EnumMap;
     6
     7import js57toosm.Js57toosm;
    68
    79public class S57dat {
     
    2729        static {
    2830                convs.put(S57subf.I8RN, new S57conv(5,2,Dom.INT));
    29                 convs.put(S57subf.RCNM, new S57conv(2,1,Dom.AN)); convs.put(S57subf.RCID, new S57conv(10,4,Dom.INT)); convs.put(S57subf.EXPP, new S57conv(1,1,Dom.AN));
     31                convs.put(S57subf.RCNM, new S57conv(2,1,Dom.AN)); convs.put(S57subf.RCID, new S57conv(10,32,Dom.INT)); convs.put(S57subf.EXPP, new S57conv(1,1,Dom.AN));
    3032                convs.put(S57subf.INTU, new S57conv(1,1,Dom.INT)); convs.put(S57subf.DSNM, new S57conv(0,0,Dom.BT)); convs.put(S57subf.EDTN, new S57conv(0,0,Dom.BT));
    3133                convs.put(S57subf.UPDN, new S57conv(0,0,Dom.BT)); convs.put(S57subf.UADT, new S57conv(8,0,Dom.DATE)); convs.put(S57subf.ISDT, new S57conv(8,0,Dom.DATE));
     
    4951                convs.put(S57subf.LFIL, new S57conv(0,0,Dom.BT)); convs.put(S57subf.VOLM, new S57conv(0,0,Dom.BT)); convs.put(S57subf.IMPL, new S57conv(3,0,Dom.AN));
    5052                convs.put(S57subf.SLAT, new S57conv(0,0,Dom.REAL)); convs.put(S57subf.WLON, new S57conv(0,0,Dom.REAL)); convs.put(S57subf.NLAT, new S57conv(0,0,Dom.REAL));
    51                 convs.put(S57subf.ELON, new S57conv(0,0,Dom.REAL)); convs.put(S57subf.CRCS, new S57conv(0,0,Dom.HEX)); convs.put(S57subf.NAM1, new S57conv(12,5,Dom.AN));
    52                 convs.put(S57subf.NAM2, new S57conv(12,5,Dom.AN)); convs.put(S57subf.OORA, new S57conv(1,1,Dom.AN)); convs.put(S57subf.OAAC, new S57conv(6,0,Dom.BT));
     53                convs.put(S57subf.ELON, new S57conv(0,0,Dom.REAL)); convs.put(S57subf.CRCS, new S57conv(0,0,Dom.HEX)); convs.put(S57subf.NAM1, new S57conv(12,40,Dom.AN));
     54                convs.put(S57subf.NAM2, new S57conv(12,40,Dom.AN)); convs.put(S57subf.OORA, new S57conv(1,1,Dom.AN)); convs.put(S57subf.OAAC, new S57conv(6,0,Dom.BT));
    5355                convs.put(S57subf.OACO, new S57conv(5,2,Dom.INT)); convs.put(S57subf.OALL, new S57conv(0,0,Dom.BT)); convs.put(S57subf.OATY, new S57conv(1,1,Dom.AN));
    5456                convs.put(S57subf.DEFN, new S57conv(0,0,Dom.BT)); convs.put(S57subf.AUTH, new S57conv(2,2,Dom.AN)); convs.put(S57subf.RFTP, new S57conv(2,1,Dom.AN));
     
    6062                convs.put(S57subf.FIDN, new S57conv(10,4,Dom.INT)); convs.put(S57subf.FIDS, new S57conv(5,2,Dom.INT)); convs.put(S57subf.ATTL, new S57conv(5,2,Dom.INT));
    6163                convs.put(S57subf.ATVL, new S57conv(0,0,Dom.GT)); convs.put(S57subf.FFUI, new S57conv(1,1,Dom.AN)); convs.put(S57subf.FFIX, new S57conv(0,2,Dom.INT));
    62                 convs.put(S57subf.NFPT, new S57conv(0,2,Dom.INT)); convs.put(S57subf.LNAM, new S57conv(17,8,Dom.AN)); convs.put(S57subf.RIND, new S57conv(0,1,Dom.AN));
     64                convs.put(S57subf.NFPT, new S57conv(0,2,Dom.INT)); convs.put(S57subf.LNAM, new S57conv(17,64,Dom.AN)); convs.put(S57subf.RIND, new S57conv(0,1,Dom.AN));
    6365                convs.put(S57subf.FSUI, new S57conv(1,1,Dom.AN)); convs.put(S57subf.FSIX, new S57conv(0,2,Dom.INT)); convs.put(S57subf.NSPT, new S57conv(0,2,Dom.INT));
    64                 convs.put(S57subf.NAME, new S57conv(12,5,Dom.AN)); convs.put(S57subf.ORNT, new S57conv(1,1,Dom.AN)); convs.put(S57subf.USAG, new S57conv(1,1,Dom.AN));
     66                convs.put(S57subf.NAME, new S57conv(12,40,Dom.AN)); convs.put(S57subf.ORNT, new S57conv(1,1,Dom.AN)); convs.put(S57subf.USAG, new S57conv(1,1,Dom.AN));
    6567                convs.put(S57subf.MASK, new S57conv(1,1,Dom.AN)); convs.put(S57subf.VPUI, new S57conv(1,1,Dom.AN)); convs.put(S57subf.VPIX, new S57conv(0,2,Dom.INT));
    6668                convs.put(S57subf.NVPT, new S57conv(0,2,Dom.INT)); convs.put(S57subf.TOPI, new S57conv(1,1,Dom.AN)); convs.put(S57subf.CCUI, new S57conv(1,1,Dom.AN));
     
    166168        public static Object getSubf(S57subf subf) {
    167169                ArrayList<S57subf> subs = fields.get(field);
    168                 if (index == subs.size())
    169                         index = 0;
    170                 while (index < subs.size()) {
     170                boolean wrap = false;
     171                while (true) {
     172                        if (index == subs.size()) {
     173                                if (!wrap) {
     174                                        index = 0;
     175                                        wrap = true;
     176                                } else {
     177                                        System.out.println("ERROR: Subfield not found " + subf.name() + " in " + field.name() + " in record " + Js57toosm.rnum);
     178                                        System.exit(-1);
     179                                }
     180                        }
    171181                        S57subf sub = subs.get(index++);
    172182                        S57conv conv = convs.get(sub);
    173183                        if (sub == subf) {
    174184                                if (conv.bin == 0) {
     185                                        String str = "";
    175186                                        if (conv.asc == 0) {
    176                                                 String str = "";
    177187                                                while (buffer[offset] != 0x1f) {
    178188                                                        str += buffer[offset++];
    179189                                                }
    180                                                 offset += (conv.bin != 0) ? Math.abs(conv.bin) : conv.asc;
    181                                                 return str;
    182                                         } else
    183                                                 return new String(buffer, offset, conv.asc);
     190                                        } else {
     191                                                str = new String(buffer, offset, conv.asc);
     192                                                offset += conv.asc;
     193                                        }
     194                                        return str;
    184195                                } else {
    185                                         int i = Math.abs(conv.bin);
    186                                         long val = buffer[offset + --i];
    187                                         if (conv.bin > 0)
    188                                                 val &= 0xff;
    189                                         while (i > 0) {
    190                                                 val = (val << 8) + (buffer[offset + --i] & 0xff);
     196                                        int f = Math.abs(conv.bin);
     197                                        if (f < 8) {
     198                                                long val = buffer[offset + --f];
     199                                                if (conv.bin > 0)
     200                                                        val &= 0xff;
     201                                                while (f > 0) {
     202                                                        val = (val << 8) + (buffer[offset + --f] & 0xff);
     203                                                }
     204                                                offset += Math.abs(conv.bin);
     205                                                return val;
     206                                        } else {
     207                                                f /= 8;
     208                                                long val = 0;
     209                                                for (int i = 0; i < f; i++) {
     210                                                        val = (val << 8) + (buffer[offset++] & 0xff);
     211                                                }
     212                                                return val;
    191213                                        }
    192                                         offset += (conv.bin != 0) ? Math.abs(conv.bin) : conv.asc;
    193                                         return val;
    194214                                }
    195215                        } else {
    196                                 offset += (conv.bin != 0) ? Math.abs(conv.bin) : conv.asc;
     216                                offset += (conv.bin != 0) ? ((conv.bin < 8) ? Math.abs(conv.bin) : conv.bin / 8) : conv.asc;
    197217                        }
    198218                }
    199                 return null;
    200219        }
    201220
  • applications/editors/josm/plugins/smed2/src/s57/S57map.java

    r30183 r30186  
    174174        public class Feature {
    175175                public Fflag flag;
    176                 public long id;
     176                public long refs;
    177177                public Obj type;
    178178                public AttMap atts;
     
    184184                Feature() {
    185185                        flag = Fflag.UNKN;
    186                         id = 0;
     186                        refs = 0;
    187187                        type = Obj.UNKOBJ;
    188188                        atts = new AttMap();
     
    304304                nodes.put(id, new Snode(Math.toRadians(lat), Math.toRadians(lon)));
    305305                feature = new Feature();
    306                 feature.id = id;
     306                feature.refs = id;
    307307                feature.flag = Fflag.POINT;
    308308                edge = null;
    309309        }
    310310
    311         public void addNode(long id, double lat, double lon, double depth) {
     311        public void newNode(long id, double lat, double lon, Nflag flag) {
     312                nodes.put(id, new Snode(Math.toRadians(lat), Math.toRadians(lon), flag));
     313                if (flag == Nflag.ANON) {
     314                        edge.nodes.add(id);
     315                }
     316        }
     317
     318        public void newNode(long id, double lat, double lon, double depth) {
    312319                nodes.put(id, new Dnode(Math.toRadians(lat), Math.toRadians(lon), depth));
    313                 feature = new Feature();
    314                 feature.id = id;
    315                 feature.flag = Fflag.POINT;
    316                 edge = null;
     320        }
     321
     322        public void newEdge(long id) {
     323                edge = new Edge();
     324                edges.put(id, edge);
     325        }
     326
     327        public void addConn(long id, int topi) {
     328                if (topi == 1) {
     329                        edge.first = id;
     330                } else {
     331                        edge.last = id;
     332                }
    317333        }
    318334
    319335        public void addEdge(long id) {
    320336                feature = new Feature();
    321                 feature.id = id;
     337                feature.refs = id;
    322338                feature.flag = Fflag.LINE;
    323339                edge = new Edge();
     
    337353        public void addArea(long id) {
    338354                feature = new Feature();
    339                 feature.id = id;
     355                feature.refs = id;
    340356                feature.flag = Fflag.AREA;
    341357                outers = new ArrayList<Long>();
     
    530546                switch (feature.flag) {
    531547                case POINT:
    532                         return nodes.get(feature.id);
     548                        return nodes.get(feature.refs);
    533549                case LINE:
    534                         Edge edge = edges.get(feature.id);
     550                        Edge edge = edges.get(feature.refs);
    535551                        EdgeIterator eit = new EdgeIterator(edge, true);
    536552                        while (eit.hasNext()) {
     
    567583                        return new Snode(llat + ((lat - llat) * harc / sarc), llon + ((lon - llon) * harc / sarc));
    568584                case AREA:
    569                         Bound bound = areas.get(feature.id).get(0);
     585                        Bound bound = areas.get(feature.refs).get(0);
    570586                        BoundIterator bit = new BoundIterator(bound);
    571587                        while (bit.hasNext()) {
Note: See TracChangeset for help on using the changeset viewer.