Changeset 31722 in osm for applications/editors/josm/plugins/seachart/src/s57
- Timestamp:
- 2015-10-29T23:01:53+01:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/seachart/src/s57
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/seachart/src/s57/S57dat.java
r31704 r31722 32 32 static { 33 33 convs.put(S57subf.I8RN, new S57conv(5,2)); 34 convs.put(S57subf.RCNM, new S57conv(2,1)); convs.put(S57subf.RCID, new S57conv(10, 32)); convs.put(S57subf.EXPP, new S57conv(1,1));34 convs.put(S57subf.RCNM, new S57conv(2,1)); convs.put(S57subf.RCID, new S57conv(10,4)); convs.put(S57subf.EXPP, new S57conv(1,1)); 35 35 convs.put(S57subf.INTU, new S57conv(1,1)); convs.put(S57subf.DSNM, new S57conv(0,0)); convs.put(S57subf.EDTN, new S57conv(0,0)); 36 36 convs.put(S57subf.UPDN, new S57conv(0,0)); convs.put(S57subf.UADT, new S57conv(8,0)); convs.put(S57subf.ISDT, new S57conv(8,0)); … … 78 78 79 79 public enum S57field { I8RI, DSID, DSSI, DSPM, DSPR, DSRC, DSHT, DSAC, CATD, CATX, DDDF, DDDR, DDDI, DDOM, DDRF, DDSI, DDSC, 80 FRID, FOID, ATTF, NATF, FFPC, FFPT, FSPC, FSPT, VRID, ATTV, VRPC, VRPT, SGCC, SG2D, SG3D, ARCC, AR2D, EL2D, CT2D }80 FRID, FOID, LNAM, ATTF, NATF, FFPC, FFPT, FSPC, FSPT, VRID, ATTV, VRPC, VRPT, SGCC, SG2D, SG3D, ARCC, AR2D, EL2D, CT2D } 81 81 82 82 private static ArrayList<S57subf> S57i8ri = new ArrayList<S57subf>(Arrays.asList(S57subf.I8RN)); … … 105 105 private static ArrayList<S57subf> S57ddsc = new ArrayList<S57subf>(Arrays.asList(S57subf.ATLB, S57subf.ASET, S57subf.AUTH )); 106 106 private static ArrayList<S57subf> S57frid = new ArrayList<S57subf>(Arrays.asList(S57subf.RCNM, S57subf.RCID, S57subf.PRIM, S57subf.GRUP, S57subf.OBJL, S57subf.RVER, S57subf.RUIN )); 107 //private static ArrayList<S57subf> S57foid = new ArrayList<S57subf>(Arrays.asList(S57subf.AGEN, S57subf.FIDN, S57subf.FIDS ));108 private static ArrayList<S57subf> S57 foid= new ArrayList<S57subf>(Arrays.asList(S57subf.LNAM));107 private static ArrayList<S57subf> S57foid = new ArrayList<S57subf>(Arrays.asList(S57subf.AGEN, S57subf.FIDN, S57subf.FIDS )); 108 private static ArrayList<S57subf> S57lnam = new ArrayList<S57subf>(Arrays.asList(S57subf.LNAM)); 109 109 private static ArrayList<S57subf> S57attf = new ArrayList<S57subf>(Arrays.asList(S57subf.ATTL, S57subf.ATVL )); 110 110 private static ArrayList<S57subf> S57natf = new ArrayList<S57subf>(Arrays.asList(S57subf.ATTL, S57subf.ATVL )); … … 132 132 fields.put(S57field.CATX, S57catx); fields.put(S57field.DDDF, S57dddf); fields.put(S57field.DDDR, S57dddr); fields.put(S57field.DDDI, S57dddi); 133 133 fields.put(S57field.DDOM, S57ddom); fields.put(S57field.DDRF, S57ddrf); fields.put(S57field.DDSI, S57ddsi); fields.put(S57field.DDSC, S57ddsc); 134 fields.put(S57field.FRID, S57frid); fields.put(S57field.FOID, S57foid); fields.put(S57field.ATTF, S57attf); fields.put(S57field.NATF, S57natf); 135 fields.put(S57field.FFPC, S57ffpc); fields.put(S57field.FFPT, S57ffpt); fields.put(S57field.FFPC, S57fspc); fields.put(S57field.FSPT, S57fspt); 136 fields.put(S57field.VRID, S57vrid); fields.put(S57field.ATTV, S57attv); fields.put(S57field.VRPC, S57vrpc); fields.put(S57field.VRPT, S57vrpt); 137 fields.put(S57field.SGCC, S57sgcc); fields.put(S57field.SG2D, S57sg2d); fields.put(S57field.SG3D, S57sg3d); fields.put(S57field.ARCC, S57arcc); 138 fields.put(S57field.AR2D, S57ar2d); fields.put(S57field.EL2D, S57el2d); fields.put(S57field.CT2D, S57ct2d); 139 } 140 134 fields.put(S57field.FRID, S57frid); fields.put(S57field.FOID, S57foid); fields.put(S57field.LNAM, S57lnam); fields.put(S57field.ATTF, S57attf); 135 fields.put(S57field.NATF, S57natf); fields.put(S57field.FFPC, S57ffpc); fields.put(S57field.FFPT, S57ffpt); fields.put(S57field.FFPC, S57fspc); 136 fields.put(S57field.FSPT, S57fspt); fields.put(S57field.VRID, S57vrid); fields.put(S57field.ATTV, S57attv); fields.put(S57field.VRPC, S57vrpc); 137 fields.put(S57field.VRPT, S57vrpt); fields.put(S57field.SGCC, S57sgcc); fields.put(S57field.SG2D, S57sg2d); fields.put(S57field.SG3D, S57sg3d); 138 fields.put(S57field.ARCC, S57arcc); fields.put(S57field.AR2D, S57ar2d); fields.put(S57field.EL2D, S57el2d); fields.put(S57field.CT2D, S57ct2d); 139 } 140 141 public enum S57record { DS, DP, DH, DA, CD, CR, ID, IO, IS, FE, VS, VI, VC, VE } 142 143 private static ArrayList<S57field> S57ds = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.DSID, S57field.DSSI )); 144 private static ArrayList<S57field> S57dp = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.DSPM, S57field.DSPR, S57field.DSRC )); 145 private static ArrayList<S57field> S57dh = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.DSHT )); 146 private static ArrayList<S57field> S57da = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.DSAC )); 147 private static ArrayList<S57field> S57cd = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.CATD )); 148 private static ArrayList<S57field> S57cr = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.CATX )); 149 private static ArrayList<S57field> S57id = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.DDDF, S57field.DDDR )); 150 private static ArrayList<S57field> S57io = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.DDDI, null, S57field.DDOM, S57field.DDRF, null )); 151 private static ArrayList<S57field> S57is = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.DDSI, S57field.DDSC )); 152 private static ArrayList<S57field> S57fe = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.FRID, S57field.FOID, null, S57field.ATTF, null, 153 null, S57field.NATF, null, null, S57field.FFPT, null, null, S57field.FSPT, null )); 154 private static ArrayList<S57field> S57vs = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.VRID, null, S57field.SG3D, null)); 155 private static ArrayList<S57field> S57vi = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.VRID, S57field.SG2D)); 156 private static ArrayList<S57field> S57vc = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.VRID, S57field.SG2D)); 157 private static ArrayList<S57field> S57ve = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.VRID, null, S57field.VRPT, null, null, S57field.SG3D, null)); 158 159 private static final EnumMap<S57record, ArrayList<S57field>> records = new EnumMap<S57record, ArrayList<S57field>>(S57record.class); 160 static { 161 records.put(S57record.DS, S57ds); records.put(S57record.DP, S57dp); records.put(S57record.DH, S57dh); records.put(S57record.DA, S57da); records.put(S57record.CD, S57cd); 162 records.put(S57record.CR, S57cr); records.put(S57record.ID, S57id); records.put(S57record.IO, S57io); records.put(S57record.IS, S57is); records.put(S57record.FE, S57fe); 163 records.put(S57record.VS, S57vs); records.put(S57record.VI, S57vi); records.put(S57record.VC, S57vc); records.put(S57record.VE, S57ve); 164 } 165 166 private static final EnumMap<S57record, Integer> rcnms = new EnumMap<S57record, Integer>(S57record.class); 167 static { 168 rcnms.put(S57record.DS, 10); rcnms.put(S57record.DP, 20); rcnms.put(S57record.DH, 30); rcnms.put(S57record.DA, 40); rcnms.put(S57record.CD, 50); 169 rcnms.put(S57record.CR, 60); rcnms.put(S57record.ID, 70); rcnms.put(S57record.IO, 80); rcnms.put(S57record.IS, 90); rcnms.put(S57record.FE, 100); 170 rcnms.put(S57record.VS, 110); rcnms.put(S57record.VI, 110); rcnms.put(S57record.VC, 120); rcnms.put(S57record.VE, 130); 171 } 172 173 private static byte[] leader = {'0', '0', '0', '0', '0', ' ', 'D', ' ', ' ', ' ', ' ', ' ', '0', '0', '0', '0', '0', ' ', ' ', ' ', '0', '0', '0', '4'}; 141 174 private static byte[] buffer; 142 175 private static int offset; … … 259 292 } 260 293 261 public static byte[] encSubf(S57subf subf, Object val) throws UnsupportedEncodingException { 262 S57conv conv = findSubf(subf); 263 if ((conv.bin == 0) && (val instanceof String)) { 264 index = ((String)val).length(); 265 buffer = ((String)val + " ").getBytes("ISO-8859-1"); 294 public static byte[] encSubf(S57subf subf, Object val) { 295 if (val instanceof S57record) val = rcnms.get(val); 296 S57conv conv = convs.get(subf); 297 if (conv.bin == 0) { 298 String sval = ""; 299 if (val instanceof String) { 300 sval = (String) val; 301 } else if (val instanceof Long) { 302 sval = ((Long)val).toString(); 303 } else if (val instanceof Double) { 304 sval = ((Double)val).toString(); 305 } 306 index = sval.length(); 307 try { 308 buffer = ((String) sval + " ").getBytes("ISO-8859-1"); 309 } catch (Exception e) { 310 System.err.println(e.getMessage()); 311 System.exit(-1); 312 } 266 313 if (conv.asc == 0) { 267 314 buffer[index] = 0x01f; … … 274 321 } else { 275 322 int f = Math.abs(conv.bin); 276 long lval = (long) val; 323 long lval; 324 if (val instanceof String) { 325 lval = Long.parseLong((String)val); 326 } else if (val instanceof Double) { 327 double dval = (double) val; 328 lval = (long) dval; 329 } else if (val instanceof Integer) { 330 lval = (int) val; 331 } else { 332 lval = (long) val; 333 } 277 334 if (f < 8) { 278 335 buffer = new byte[f]; … … 284 341 f /= 8; 285 342 buffer = new byte[f]; 286 for (int i = f-1; i <= 0; i++) {343 for (int i = f-1; i >= 0; i--) { 287 344 buffer[i] = (byte) (lval & 0xff); 288 345 lval >>= 8; … … 292 349 return buffer; 293 350 } 294 351 352 static class Index { 353 byte[] field; 354 int length; 355 int offset; 356 Index (byte[] id, int l, int o) { 357 field = id; 358 length = l; 359 offset = o; 360 } 361 } 362 363 public static byte[] encRecord(Object...params) { 364 ArrayList<Index> index = new ArrayList<Index>(); 365 offset = 0; 366 int maxlen = 0; 367 ArrayList<S57field> record = records.get(params[1]); 368 byte[] buf = new byte[0]; 369 int ip = 0; 370 for (S57field field : record) { 371 for (S57subf subf : fields.get(field)) { 372 byte[] next = encSubf(subf, params[ip++]); 373 buf = Arrays.copyOf(buf, (buf.length + next.length)); 374 System.arraycopy(next, 0, buf, (buf.length - next.length), next.length); 375 if (ip >= params.length) 376 break; 377 } 378 buf = Arrays.copyOf(buf, (buf.length + 1)); 379 buf[buf.length-1] = 0x1e; 380 int flen = buf.length - offset; 381 if (field == S57field.I8RI) { 382 index.add(new Index("0001".getBytes(), flen, offset)); 383 } else { 384 index.add(new Index(field.toString().getBytes(), flen, offset)); 385 } 386 maxlen = (flen > maxlen) ? flen : maxlen; 387 offset += flen; 388 } 389 int mlen = String.valueOf(maxlen).length(); 390 String ffmt = "%0" + mlen + "d"; 391 int olen = String.valueOf(offset).length(); 392 String ofmt = "%0" + olen + "d"; 393 int ilen = 4 + mlen + olen; 394 int isiz = (ilen * index.size()) + 1; 395 byte[] ibuf = new byte[isiz]; 396 int i = 0; 397 for (Index item : index) { 398 for (byte ch : item.field) { 399 ibuf[i++] = ch; 400 } 401 byte[] digits = String.format(ffmt, item.length).getBytes(); 402 for (byte ch : digits) { 403 ibuf[i++] = ch; 404 } 405 digits = String.format(ofmt, item.offset).getBytes(); 406 for (byte ch : digits) { 407 ibuf[i++] = ch; 408 } 409 } 410 ibuf[i] = 0x1e; 411 byte[] fbuf = Arrays.copyOf(leader, (leader.length + ibuf.length + buf.length)); 412 System.arraycopy(ibuf, 0, fbuf, leader.length, ibuf.length); 413 System.arraycopy(buf, 0, fbuf, (leader.length + ibuf.length), buf.length); 414 fbuf[20] = (byte)(mlen + 0x30); 415 fbuf[21] = (byte)(olen + 0x30); 416 System.arraycopy(String.format("%05d", fbuf.length).getBytes(), 0, fbuf, 0, 5); 417 System.arraycopy(String.format("%05d", (leader.length + ibuf.length)).getBytes(), 0, fbuf, 12, 5); 418 return fbuf; 419 } 420 295 421 } -
applications/editors/josm/plugins/seachart/src/s57/S57dec.java
r31704 r31722 93 93 break; 94 94 case "FOID": 95 name = (Long) S57dat.decSubf(record, fields + pos, S57field. FOID, S57subf.LNAM);95 name = (Long) S57dat.decSubf(record, fields + pos, S57field.LNAM, S57subf.LNAM); 96 96 map.newFeature(name, pflag, objl); 97 97 break; -
applications/editors/josm/plugins/seachart/src/s57/S57enc.java
r31704 r31722 9 9 10 10 package s57; 11 12 import java.io.UnsupportedEncodingException; 13 import java.util.HashMap; 14 import java.util.Map; 15 16 import s57.S57dat.*; 17 import s57.S57map.*; 11 18 12 19 public class S57enc { // S57 ENC file generation … … 120 127 '1', 0x1f, '0', 0x1f, 121 128 //*** 2035 122 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', // Date x2 129 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', // Date x2 (from system) 123 130 '0', '3', '.', '1', 0x14, 0x1f, 0x1f, 0x01, 0x26, 0x0f, 'G', 'e', 'n', 'e', 'r', 'a', 't', 'e', 'd', ' ', 'b', 'y', ' ', 124 131 'O', 'p', 'e', 'n', 'S', 'e', 'a', 'M', 'a', 'p', '.', 'o', 'r', 'g', 0x1f, 0x1e, … … 126 133 0x02, 0x01, 0x02, 127 134 //*** 2093 128 0x0 2, 0x00, 0x00, 0x00, // # of meta records135 0x00, 0x00, 0x00, 0x00, // # of meta records (from metas counter) 129 136 0x00, 0x00, 0x00, 0x00, 130 0x00, 0x00, 0x00, 0x00, // # of geo records 137 0x00, 0x00, 0x00, 0x00, // # of geo records (from geos counter) 131 138 0x00, 0x00, 0x00, 0x00, 132 0x00, 0x00, 0x00, 0x00, // # of isolated node records 133 0x00, 0x00, 0x00, 0x00, // # of connected node records 134 0x00, 0x00, 0x00, 0x00, // # of edge records 139 0x00, 0x00, 0x00, 0x00, // # of isolated node records (from isols counter) 140 0x00, 0x00, 0x00, 0x00, // # of connected node records (from conns counter) 141 0x00, 0x00, 0x00, 0x00, // # of edge records (from edges counter) 135 142 0x00, 0x00, 0x00, 0x00, 0x1e, 136 143 … … 143 150 0x14, 0x01, 0x00, 0x00, 0x00, 0x02, 0x17, 0x17, 144 151 //*** 2176 145 0x00, 0x00, 0x00, 0x00, // Scale 146 0x01, // Depth units 147 0x01, // Height units 148 0x01, 0x01, (byte)0x80, (byte)0x96, (byte)0x98, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x1f, 0x1e 152 0x00, 0x00, 0x00, 0x00, // Scale (from meta list) 153 0x01, // Depth units (from meta list) 154 0x01, // Height units (from meta list) 155 0x01, 0x01, 156 (byte)0x80, (byte)0x96, (byte)0x98, 0x00, // COMF=10000000 157 0x0a, // SOMF=10 158 0x00, 0x00, 0x00, 0x1f, 0x1e 149 159 }; 150 160 151 private static byte[] leader = {'0', '0', '0', '0', '0', ' ', 'D', ' ', ' ', ' ', ' ', ' ', '0', '0', '0', '0', '0', ' ', ' ', ' ', '0', '0', '0', '0'}; 161 static final double COMF=10000000; 162 static final double SOMF=10; 163 152 164 static int idx; 153 154 public static int encodeChart(S57map map, byte[] buf) throws IndexOutOfBoundsException { 165 static int recs; 166 static int isols; 167 static int conns; 168 static int metas; 169 static int geos; 170 static int rcid; 171 172 public static int encodeChart(S57map map, HashMap<String, String> meta, byte[] buf) throws IndexOutOfBoundsException, UnsupportedEncodingException { 173 174 /* 175 * Encoding order: 176 * 1. Copy records 0-3 & fill in meta attributes. 177 * 2. Depth isolated nodes. 178 * 3. All other isolated nodes. 179 * 4. Connected nodes. 180 * 5. Edges. 181 * 6. Meta objects. 182 * 7. Geo objects. 183 */ 155 184 156 int idx = leader.length; 185 recs = rcid = 3; 186 isols = conns = metas = geos = 0; 157 187 for (idx = 0; idx < header.length; idx++) { 158 188 buf[idx] = header[idx]; 159 189 } 190 // byte[] file = S57dat.encSubf(S57subf.FILE, meta.get("FILE")); 191 192 for (Map.Entry<Long, S57map.Snode> entry : map.nodes.entrySet()) { 193 S57map.Snode node = entry.getValue(); 194 if (node.flg == Nflag.ISOL) { 195 byte[] record = S57dat.encRecord(recs++, S57record.VI, rcid++, 1, 1, (Math.toDegrees(node.lat) * COMF), (Math.toDegrees(node.lon) * COMF)); 196 System.arraycopy(record, 0, buf, idx, record.length); 197 idx += record.length; 198 isols++; 199 recs++; 200 } 201 } 160 202 161 203 return idx; … … 164 206 public static int encodeCatalogue(S57map map, byte[] buf) throws IndexOutOfBoundsException { 165 207 166 167 int idx = leader.length;168 for (int i = 0; i < idx; i++) {169 buf[i] = leader[i];170 }171 172 208 return idx; 173 209 } -
applications/editors/josm/plugins/seachart/src/s57/S57map.java
r31660 r31722 44 44 45 45 public class Snode { // All coordinates in map 46 public double lat; // Latitude 47 public double lon; // Longitude 46 public double lat; // Latitude in radians 47 public double lon; // Longitude in radians 48 48 public Nflag flg; // Role of node 49 49 -
applications/editors/josm/plugins/seachart/src/s57/S57osm.java
r31716 r31722 37 37 static { 38 38 OSMtags.put("natural=coastline", new KeyVal<>(Obj.COALNE, Att.UNKATT, null, null)); OSMtags.put("natural=water", new KeyVal<>(Obj.LAKARE, Att.UNKATT, null, null)); 39 OSMtags.put("waterway=river", new KeyVal<>(Obj.RIVERS, Att.UNKATT, null, null)); OSMtags.put("waterway=riverbank", new KeyVal<>(Obj. COALNE, Att.UNKATT, null, null));39 OSMtags.put("waterway=river", new KeyVal<>(Obj.RIVERS, Att.UNKATT, null, null)); OSMtags.put("waterway=riverbank", new KeyVal<>(Obj.LAKARE, Att.UNKATT, null, null)); 40 40 OSMtags.put("waterway=canal", new KeyVal<>(Obj.CANALS, Att.UNKATT, null, null)); OSMtags.put("waterway=dock", new KeyVal<>(Obj.HRBBSN, Att.UNKATT, null, null)); 41 41 OSMtags.put("waterway=lock", new KeyVal<>(Obj.HRBBSN, Att.UNKATT, null, null)); OSMtags.put("landuse=basin", new KeyVal<>(Obj.LAKARE, Att.UNKATT, null, null));
Note:
See TracChangeset
for help on using the changeset viewer.