Ignore:
Timestamp:
2015-11-08T09:49:14+01:00 (11 years ago)
Author:
malcolmh
Message:

[seachart] update

Location:
applications/editors/josm/plugins/seachart/src/s57
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/seachart/src/s57/S57dat.java

    r31731 r31735  
    262262        public static byte[] encSubf(S57subf subf, Object val) {
    263263                S57conv conv = convs.get(subf);
    264                 if (conv.bin == 0) {
     264                if ((conv.bin == 0) || asc) {
    265265                        String sval = "";
    266266                        if (val instanceof String) {
    267267                                sval = (String) val;
     268                        } else if (val instanceof Integer) {
     269                                sval = ((Integer)val).toString();
    268270                        } else if (val instanceof Long) {
    269271                                sval = ((Long)val).toString();
    … …  
    328330        };
    329331
     332        static boolean asc = false;
     333       
     334        public static byte[] encRecord(String i8rn, ArrayList<Fparams> fparams) {
     335                asc = true;
     336                return encRecord(Integer.parseInt(i8rn), fparams);
     337        }
     338       
    330339        public static byte[] encRecord(int i8rn, ArrayList<Fparams> fparams) {
    331340                ArrayList<Index> index = new ArrayList<Index>();
    … …  
    380389                System.arraycopy(String.format("%05d", fbuf.length).getBytes(), 0, fbuf, 0, 5);
    381390                System.arraycopy(String.format("%05d", (leader.length + ibuf.length)).getBytes(), 0, fbuf, 12, 5);
     391                asc = false;
    382392                return fbuf;
    383393        }
  • applications/editors/josm/plugins/seachart/src/s57/S57enc.java

    r31731 r31735  
    3030
    3131        private static final byte[] header = {
     32               
    3233                '0', '1', '5', '7', '6', '3', 'L', 'E', '1', ' ', '0', '9', '0', '0', '2', '0', '1', ' ', '!', ' ', '3', '4', '0', '4', // Leader
    3334                '0', '0', '0', '0', '1', '2', '3', '0', '0', '0', '0', '0', '0', '0', '1', '0', '4', '7', '0', '1', '2', '3',
    … …  
    126127
    127128        public static int encodeChart(S57map map, HashMap<String, String> meta, byte[] buf) throws IndexOutOfBoundsException, UnsupportedEncodingException {
     129               
     130                //M_COVR & MNSYS in BB if not in map
     131                if (!map.features.containsKey(Obj.M_COVR)) {
     132                        S57osm.OSMmeta(map);
     133                }
    128134
    129135                byte[] record;
    … …  
    132138                String date = new SimpleDateFormat("yyyyMMdd").format(Calendar.getInstance().getTime());
    133139                ArrayList<Fparams> ds = new ArrayList<Fparams>();
    134                 ds.add(new Fparams(S57field.DSID, new Object[]{ 10, 1, 1, 4, "0S000000.000", 1, 0, date, date, "03.1", 1, "ENC", "", 1, agen, "Generated by OpenSeaMap.org" }));
    135                 ds.add(new Fparams(S57field.DSSI, new Object[]{ 2, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0 }));
     140                ds.add(new Fparams(S57field.DSID, new Object[] { 10, 1, 1, 4, "0S000000.000", 1, 0, date, date, "03.1", 1, "ENC", "", 1, agen, "Generated by OpenSeaMap.org" }));
     141                ds.add(new Fparams(S57field.DSSI, new Object[] { 2, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0 }));
    136142                ArrayList<Fparams> dp = new ArrayList<Fparams>();
    137                 dp.add(new Fparams(S57field.DSPM, new Object[]{ 20, 2, 2, 23, 23, cscl, 1, 1, 1, 1, 10000000, 10, "" }));
    138                
     143                dp.add(new Fparams(S57field.DSPM, new Object[] { 20, 2, 2, 23, 23, cscl, 1, 1, 1, 1, 10000000, 10, "" }));
     144
    139145                isols = conns = metas = geos = edges = 0;
    140146                System.arraycopy(header, 0, buf, 0, header.length);
    … …  
    147153                idx += record.length;
    148154                recs = 3;
    149                
     155
    150156                // Depths
    151157                Object[] depths = new Object[0];
    … …  
    153159                        S57map.Snode node = entry.getValue();
    154160                        if (node.flg == Nflag.DPTH) {
    155                                 Object[] dval = new Object[]{ (Math.toDegrees(node.lat) * COMF), (Math.toDegrees(node.lon) * COMF), (node.val * SOMF) };
     161                                Object[] dval = new Object[] { (Math.toDegrees(node.lat) * COMF), (Math.toDegrees(node.lon) * COMF), (node.val * SOMF) };
    156162                                depths = Arrays.copyOf(depths, (depths.length + dval.length));
    157163                                System.arraycopy(dval, 0, depths, (depths.length - dval.length), dval.length);
    … …  
    160166                if (depths.length > 0) {
    161167                        fields = new ArrayList<Fparams>();
    162                         fields.add(new Fparams(S57field.VRID, new Object[]{ 110, -2, 1, 1 }));
     168                        fields.add(new Fparams(S57field.VRID, new Object[] { 110, -2, 1, 1 }));
    163169                        fields.add(new Fparams(S57field.SG3D, depths));
    164170                        record = S57dat.encRecord(recs++, fields);
    … …  
    173179                        if (node.flg == Nflag.ISOL) {
    174180                                fields = new ArrayList<Fparams>();
    175                                 fields.add(new Fparams(S57field.VRID, new Object[]{ 110, hash(entry.getKey()), 1, 1 }));
    176                                 fields.add(new Fparams(S57field.SG2D, new Object[]{ (Math.toDegrees(node.lat) * COMF), (Math.toDegrees(node.lon) * COMF) }));
     181                                fields.add(new Fparams(S57field.VRID, new Object[] { 110, hash(entry.getKey()), 1, 1 }));
     182                                fields.add(new Fparams(S57field.SG2D, new Object[] { (Math.toDegrees(node.lat) * COMF), (Math.toDegrees(node.lon) * COMF) }));
    177183                                record = S57dat.encRecord(recs++, fields);
    178184                                System.arraycopy(record, 0, buf, idx, record.length);
    … …  
    181187                        }
    182188                }
    183                
     189
    184190                // Connected nodes
    185191                for (Map.Entry<Long, S57map.Snode> entry : map.nodes.entrySet()) {
    … …  
    187193                        if (node.flg == Nflag.CONN) {
    188194                                fields = new ArrayList<Fparams>();
    189                                 fields.add(new Fparams(S57field.VRID, new Object[]{ 120, hash(entry.getKey()), 1, 1 }));
    190                                 fields.add(new Fparams(S57field.SG2D, new Object[]{ (Math.toDegrees(node.lat) * COMF), (Math.toDegrees(node.lon) * COMF) }));
     195                                fields.add(new Fparams(S57field.VRID, new Object[] { 120, hash(entry.getKey()), 1, 1 }));
     196                                fields.add(new Fparams(S57field.SG2D, new Object[] { (Math.toDegrees(node.lat) * COMF), (Math.toDegrees(node.lon) * COMF) }));
    191197                                record = S57dat.encRecord(recs++, fields);
    192198                                System.arraycopy(record, 0, buf, idx, record.length);
    … …  
    195201                        }
    196202                }
    197                
     203
    198204                // Edges
    199205                for (Map.Entry<Long, S57map.Edge> entry : map.edges.entrySet()) {
    200206                        S57map.Edge edge = entry.getValue();
    201207                        fields = new ArrayList<Fparams>();
    202                         fields.add(new Fparams(S57field.VRID, new Object[]{ 130, hash(entry.getKey()), 1, 1 }));
    203                         fields.add(new Fparams(S57field.VRPT, new Object[]{ (((hash(edge.first) & 0xffffffff) << 8) + 120l), 255, 255, 1, 255, (((hash(edge.last) & 0xffffffff) << 8) + 120l), 255, 255, 2, 255 }));
     208                        fields.add(new Fparams(S57field.VRID, new Object[] { 130, hash(entry.getKey()), 1, 1 }));
     209                        fields.add(new Fparams(S57field.VRPT, new Object[] { (((hash(edge.first) & 0xffffffff) << 8) + 120l), 255, 255, 1, 255, (((hash(edge.last) & 0xffffffff) << 8) + 120l), 255, 255, 2, 255 }));
    204210                        Object[] nodes = new Object[0];
    205211                        for (long ref : edge.nodes) {
    206                                 Object[] nval = new Object[]{ (Math.toDegrees(map.nodes.get(ref).lat) * COMF), (Math.toDegrees(map.nodes.get(ref).lon) * COMF) };
     212                                Object[] nval = new Object[] { (Math.toDegrees(map.nodes.get(ref).lat) * COMF), (Math.toDegrees(map.nodes.get(ref).lon) * COMF) };
    207213                                nodes = Arrays.copyOf(nodes, (nodes.length + nval.length));
    208214                                System.arraycopy(nval, 0, nodes, (nodes.length - nval.length), nval.length);
    … …  
    216222                        edges++;
    217223                }
    218                
     224
    219225                // Meta & Geo objects
     226                boolean soundings = false;
    220227                for (Entry<Obj, ArrayList<Feature>> entry : map.features.entrySet()) {
    221228                        Obj obj = entry.getKey();
    222229                        for (Feature feature : entry.getValue()) {
     230                                if (obj == Obj.SOUNDG) {
     231                                        if (soundings) {
     232                                                continue;
     233                                        } else {
     234                                                soundings = true;
     235                                        }
     236                                }
    223237                                int prim = feature.geom.prim.ordinal();
    224238                                prim = (prim == 0) ? 255 : prim;
    225239                                int grup = ((obj == Obj.DEPARE) || (obj == Obj.DRGARE) || (obj == Obj.FLODOC) || (obj == Obj.HULKES) || (obj == Obj.LNDARE) || (obj == Obj.PONTON) || (obj == Obj.UNSARE)) ? 1 : 2;
    226                                
     240
    227241                                ArrayList<Fparams> geom = new ArrayList<Fparams>();
    228                                 int outers = feature.geom.outers;
     242                                int outers = (feature.geom.prim == Pflag.POINT) ? 1 : feature.geom.comps.get(0).size;
    229243                                for (Prim elem : feature.geom.elems) {
    230244                                        if (feature.geom.prim == Pflag.POINT) {
    231                                                 geom.add(new Fparams(S57field.FSPT, new Object[] { ((hash(elem.id) << 8) + ((map.nodes.get(elem.id).flg == Nflag.CONN) ? 120l : 110l)), 255, 255, 255 }));
     245                                                if (obj == Obj.SOUNDG) {
     246                                                        geom.add(new Fparams(S57field.FSPT, new Object[] { ((-2 << 8) + 110l), 255, 255, 255 }));
     247                                                } else {
     248                                                        geom.add(new Fparams(S57field.FSPT, new Object[] { ((hash(elem.id) << 8) + ((map.nodes.get(elem.id).flg == Nflag.CONN) ? 120l : 110l)), 255, 255, 255 }));
     249                                                }
    232250                                        } else {
    233251                                                geom.add(new Fparams(S57field.FSPT, new Object[] { ((hash(elem.id) << 8) + 130l), (elem.forward ? 1 : 2), ((outers-- > 0) ? 1 : 2), 2 }));
    … …  
    240258                                for (Entry<Obj, ObjTab> objs : feature.objs.entrySet()) {
    241259                                        Obj objobj = objs.getKey();
     260                                        boolean master = true;
    242261                                        for (Entry<Integer, AttMap> object : objs.getValue().entrySet()) {
    243262                                                ArrayList<Fparams> objatts = new ArrayList<Fparams>();
    244                                                 boolean master = (feature.type == objobj) && ((object.getKey() == 0) || (object.getKey() == 1));
     263                                                master = (feature.type == objobj) && ((object.getKey() == 0) || (object.getKey() == 1));
    245264                                                long id = hash(master ? feature.id : slaveid);
    246265                                                objatts.add(new Fparams(S57field.FRID, new Object[] { 100, id, prim, grup, S57obj.encodeType(objobj), 1, 1 }));
    … …  
    282301                                        while (!slaves.isEmpty()) {
    283302                                                long id = slaves.remove(0);
    284                                                 Object[] next = new Object[]{ (long)((((id & 0xffffffff) + 0x100000000l) << 16) + (agen & 0xffff)) , 2, "" };
     303                                                Object[] next = new Object[] { (long) ((((id & 0xffffffff) + 0x100000000l) << 16) + (agen & 0xffff)), 2, "" };
    285304                                                params = Arrays.copyOf(params, (params.length + next.length));
    286305                                                System.arraycopy(next, 0, params, (params.length - next.length), next.length);
    … …  
    289308                                        objects.get(objects.size() - 1).addAll(refs);
    290309                                }
    291                                
     310
    292311                                for (ArrayList<Fparams> object : objects) {
    293312                                        object.addAll(geom);
    … …  
    303322                        }
    304323                }
    305                
     324
    306325                // Re-write DSID/DSSI with final totals
    307326                ds = new ArrayList<Fparams>();
    308                 ds.add(new Fparams(S57field.DSID, new Object[]{ 10, 1, 1, 4, "0S000000.000", 1, 0, date, date, "03.1", 1, "ENC", "", 1, agen, "Generated by OpenSeaMap.org" }));
    309                 ds.add(new Fparams(S57field.DSSI, new Object[]{ 2, 1, 2, metas, 0, geos, 0, isols, conns, edges, 0 }));
     327                ds.add(new Fparams(S57field.DSID, new Object[] { 10, 1, 1, 4, "0S000000.000", 1, 0, date, date, "03.1", 1, "ENC", "", 1, agen, "Generated by OpenSeaMap.org" }));
     328                ds.add(new Fparams(S57field.DSSI, new Object[] { 2, 1, 2, metas, 0, geos, 0, isols, conns, edges, 0 }));
    310329                record = S57dat.encRecord(1, ds);
    311330                System.arraycopy(record, 0, buf, header.length, record.length);
    312                
    313         return idx;
     331
     332                return idx;
     333        }
     334
    314335}
    315 
    316         public static int encodeCatalogue(S57map map, byte[] buf) throws IndexOutOfBoundsException {
    317                
    318         return idx;
    319 }
    320 
    321 }
  • applications/editors/josm/plugins/seachart/src/s57/S57map.java

    r31734 r31735  
    219219        }
    220220       
     221        public MapBounds bounds;
    221222        public NodeTab nodes;
    222223        public EdgeTab edges;
    223 
    224224        public FtrMap features;
    225225        public FtrTab index;
    226        
    227         public MapBounds bounds;
    228 
    229         public long cref;
    230226        public long xref;
     227
     228        private long cref;
    231229        private Feature feature;
    232230        private Edge edge;
    233231        private KeyVal<?> osm = S57osm.OSMtag("", "");
    234         boolean sea;
     232        private boolean sea;
    235233
    236234        public S57map(boolean s) {
    … …  
    367365
    368366        // OSM map building methods
    369        
     367
    370368        public void addNode(long id, double lat, double lon) {
    371                 Snode node = new Snode(Math.toRadians(lat), Math.toRadians(lon));
    372                 nodes.put(id, node);
     369                nodes.put(id, new Snode(Math.toRadians(lat), Math.toRadians(lon)));
    373370                feature = new Feature();
    374371                feature.id = id;
    … …  
    555552       
    556553        enum Ext {I, N, W, S, E }
     554       
    557555        public void mapDone() {
    558556                class Land {
    … …  
    579577                        for (Feature feature : features.get(Obj.COALNE)) {
    580578                                Feature land = new Feature();
     579                                land.id = ++xref;
    581580                                land.type = Obj.LNDARE;
    582581                                land.reln = Rflag.MASTER;
    583582                                land.objs.put(Obj.LNDARE, new ObjTab());
     583                                land.objs.get(Obj.LNDARE).put(0, new AttMap());
    584584                                if (feature.geom.prim == Pflag.AREA) {
    585585                                        land.geom = feature.geom;
    … …  
    587587                                } else if (feature.geom.prim == Pflag.LINE) {
    588588                                        land.geom.prim = Pflag.LINE;
    589                                         for (int i = 0; i < feature.geom.elems.size(); i++) {
    590                                                 land.geom.elems.add(feature.geom.elems.get(i));
    591                                         }
     589                                        land.geom.elems.addAll(feature.geom.elems);
    592590                                        coasts.add(land);
    593591                                }
  • applications/editors/josm/plugins/seachart/src/s57/S57osm.java

    r31722 r31735  
    1212import java.io.BufferedReader;
    1313import java.io.IOException;
    14 import java.util.ArrayList;
    15 import java.util.HashMap;
     14import java.util.*;
    1615
    1716import s57.S57obj.*;
    … …  
    7776                boolean inWay = false;
    7877                boolean inRel = false;
     78                map.nodes.put(1l, map.new Snode());
     79                map.nodes.put(2l, map.new Snode());
     80                map.nodes.put(3l, map.new Snode());
     81                map.nodes.put(4l, map.new Snode());
    7982
    8083                String ln;
    … …  
    8588                                                if (token.matches("^minlat=.+")) {
    8689                                                        map.bounds.minlat = Math.toRadians(Double.parseDouble(token.split("[\"\']")[1]));
     90                                                        map.nodes.get(2l).lat = map.bounds.minlat;
     91                                                        map.nodes.get(3l).lat = map.bounds.minlat;
    8792                                                } else if (token.matches("^minlon=.+")) {
    8893                                                        map.bounds.minlon = Math.toRadians(Double.parseDouble(token.split("[\"\']")[1]));
     94                                                        map.nodes.get(1l).lon = map.bounds.minlon;
     95                                                        map.nodes.get(2l).lon = map.bounds.minlon;
    8996                                                } else if (token.matches("^maxlat=.+")) {
    9097                                                        map.bounds.maxlat = Math.toRadians(Double.parseDouble(token.split("[\"\']")[1]));
     98                                                        map.nodes.get(1l).lat = map.bounds.maxlat;
     99                                                        map.nodes.get(4l).lat = map.bounds.maxlat;
    91100                                                } else if (token.matches("^maxlon=.+")) {
    92101                                                        map.bounds.maxlon = Math.toRadians(Double.parseDouble(token.split("[\"\']")[1]));
     102                                                        map.nodes.get(3l).lon = map.bounds.maxlon;
     103                                                        map.nodes.get(4l).lon = map.bounds.maxlon;
    93104                                                }
    94105                                        }
    … …  
    199210                return;
    200211        }
     212       
     213        public static void OSMmeta(S57map map) {
     214                map.addEdge(++map.xref);
     215                for (long ref = 0; ref <= 4; ref++) {
     216                        map.addToEdge((ref == 0) ? 4 : ref);
     217                }
     218                map.addTag("seamark:type", "coverage");
     219                map.addTag("seamark:coverage:category", "coverage");
     220                map.tagsDone(map.xref);
     221        }
    201222
    202223}
Note: See TracChangeset for help on using the changeset viewer.