Changeset 31735 in osm for applications/editors/josm
- Timestamp:
- 2015-11-08T09:49:14+01:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/seachart
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/seachart/josmtos57/src/josmtos57/Josmtos57.java
r31731 r31735 11 11 12 12 import java.io.*; 13 import java.util.HashMap; 14 import java.util.Scanner; 13 import java.util.*; 15 14 import java.util.zip.CRC32; 16 15 16 import s57.S57dat; 17 17 import s57.S57enc; 18 18 import s57.S57map; 19 19 import s57.S57osm; 20 import s57.S57dat.*; 20 21 21 22 public class Josmtos57 { … … 37 38 'I', 'L', '!', 'V', 'O', 'L', 'M', '!', 'I', 'M', 'P', 'L', '!', 'S', 'L', 'A', 'T', '!', 'W', 'L', 'O', 'N', '!', 'N', 'L', 'A', 'T', '!', 'E', 'L', 'O', 'N', 38 39 '!', 'C', 'R', 'C', 'S', '!', 'C', 'O', 'M', 'T', 0x1f, '(', 'A', '(', '2', ')', ',', 'I', '(', '1', '0', ')', ',', '3', 'A', ',', 'A', '(', '3', ')', ',', '4', 39 'R', ',', '2', 'A', ')', 0x1e 40 }; 41 42 static byte[] entry = { 43 //*** 0 44 '0', '0', '1', '0', '1', ' ', 'D', ' ', ' ', ' ', ' ', ' ', '0', '0', '0', '5', '3', ' ', ' ', ' ', '5', '5', '0', '4', // Leader 45 '0', '0', '0', '1', '0', '0', '0', '0', '6', '0', '0', '0', '0', '0', 'C', 'A', 'T', 'D', '0', '0', '0', '4', '2', '0', '0', '0', '0', '6', 0x1e, // Directory 46 '0', '0', '0', '0', '0', 0x1e, 47 //*** 48 'C', 'D', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', // Record name+number 49 //*** 50 'C', 'A', 'T', 'A', 'L', 'O', 'G', '.', '0', '3', '1', 0x1f, // File name 51 0x1f, // File long name 52 'V', '0', '1', 'X', '0', '1', 0x1f, // Volume 53 'A', 'S', 'C', // Implementation 54 0x1f, 0x1f, 0x1f, 0x1f, // minlat, minlon, maxlat, maxlon 55 0x1f, // CRC32 56 0x1f, 0x1e // Comment 40 'R', ',', '2', 'A', ')', 0x1e, 41 '0', '0', '1', '0', '1', ' ', 'D', ' ', ' ', ' ', ' ', ' ', '0', '0', '0', '5', '3', ' ', ' ', ' ', '5', '5', '0', '4', 42 '0', '0', '0', '1', '0', '0', '0', '0', '6', '0', '0', '0', '0', '0', 'C', 'A', 'T', 'D', '0', '0', '0', '4', '2', '0', '0', '0', '0', '6', 0x1e, 43 '0', '0', '0', '0', '0', 0x1e, 'C', 'D', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', 'C', 'A', 'T', 'A', 'L', 'O', 'G', '.', '0', '3', '1', 0x1f, 44 0x1f, 'V', '0', '1', 'X', '0', '1', 0x1f, 'A', 'S', 'C', 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1e 57 45 }; 58 46 … … 62 50 static byte[] buf; 63 51 static HashMap<String, String> meta; 52 static ArrayList<Fparams> fields; 53 static byte[] record; 64 54 65 55 public static void main(String[] args) throws IOException { 66 56 67 map = new S57map( true);57 map = new S57map(false); 68 58 int idx = 0; 69 59 … … 76 66 meta = new HashMap<String, String>(); 77 67 meta.put("FILE", args[3]); 78 // while (min.hasNext()) { 79 // String[] tokens = min.next().split("="); 80 // meta.put(tokens[0], tokens[1]); 81 // } 68 while (min.hasNext()) { 69 String[] tokens = min.next().split("="); 70 if (tokens.length >= 2) 71 meta.put(tokens[0], tokens[1].split("[ #]")[0]); 72 } 82 73 min.close(); 83 74 } catch (IOException e) { … … 118 109 out.close(); 119 110 111 buf = new byte[header.length]; 112 System.arraycopy(header, 0, buf, 0, header.length); 113 idx = header.length; 114 int recs = 2; 115 fields = new ArrayList<Fparams>(); 116 fields.add(new Fparams(S57field.CATD, new Object[]{ "CD", recs, args[3], "", "V01X01", "BIN", Math.toDegrees(map.bounds.minlat), 117 Math.toDegrees(map.bounds.minlon), Math.toDegrees(map.bounds.maxlat), Math.toDegrees(map.bounds.maxlon), String.format("%08X", crc.getValue()), "" })); 118 record = S57dat.encRecord(String.valueOf(recs++), fields); 119 buf = Arrays.copyOf(buf, (buf.length + record.length)); 120 System.arraycopy(record, 0, buf, idx, record.length); 121 idx += record.length; 122 120 123 try { 121 124 File file = new File(args[2] + "CATALOG.031"); 122 125 if (file.exists()) file.delete(); 123 126 out = new FileOutputStream(file, false); 127 out.write(buf, 0, idx); 124 128 } catch (IOException e) { 125 129 System.err.println("Catalogue file: " + e.getMessage()); -
applications/editors/josm/plugins/seachart/src/s57/S57dat.java
r31731 r31735 262 262 public static byte[] encSubf(S57subf subf, Object val) { 263 263 S57conv conv = convs.get(subf); 264 if ( conv.bin == 0) {264 if ((conv.bin == 0) || asc) { 265 265 String sval = ""; 266 266 if (val instanceof String) { 267 267 sval = (String) val; 268 } else if (val instanceof Integer) { 269 sval = ((Integer)val).toString(); 268 270 } else if (val instanceof Long) { 269 271 sval = ((Long)val).toString(); … … 328 330 }; 329 331 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 330 339 public static byte[] encRecord(int i8rn, ArrayList<Fparams> fparams) { 331 340 ArrayList<Index> index = new ArrayList<Index>(); … … 380 389 System.arraycopy(String.format("%05d", fbuf.length).getBytes(), 0, fbuf, 0, 5); 381 390 System.arraycopy(String.format("%05d", (leader.length + ibuf.length)).getBytes(), 0, fbuf, 12, 5); 391 asc = false; 382 392 return fbuf; 383 393 } -
applications/editors/josm/plugins/seachart/src/s57/S57enc.java
r31731 r31735 30 30 31 31 private static final byte[] header = { 32 32 33 '0', '1', '5', '7', '6', '3', 'L', 'E', '1', ' ', '0', '9', '0', '0', '2', '0', '1', ' ', '!', ' ', '3', '4', '0', '4', // Leader 33 34 '0', '0', '0', '0', '1', '2', '3', '0', '0', '0', '0', '0', '0', '0', '1', '0', '4', '7', '0', '1', '2', '3', … … 126 127 127 128 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 } 128 134 129 135 byte[] record; … … 132 138 String date = new SimpleDateFormat("yyyyMMdd").format(Calendar.getInstance().getTime()); 133 139 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 })); 136 142 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 139 145 isols = conns = metas = geos = edges = 0; 140 146 System.arraycopy(header, 0, buf, 0, header.length); … … 147 153 idx += record.length; 148 154 recs = 3; 149 155 150 156 // Depths 151 157 Object[] depths = new Object[0]; … … 153 159 S57map.Snode node = entry.getValue(); 154 160 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) }; 156 162 depths = Arrays.copyOf(depths, (depths.length + dval.length)); 157 163 System.arraycopy(dval, 0, depths, (depths.length - dval.length), dval.length); … … 160 166 if (depths.length > 0) { 161 167 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 })); 163 169 fields.add(new Fparams(S57field.SG3D, depths)); 164 170 record = S57dat.encRecord(recs++, fields); … … 173 179 if (node.flg == Nflag.ISOL) { 174 180 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) })); 177 183 record = S57dat.encRecord(recs++, fields); 178 184 System.arraycopy(record, 0, buf, idx, record.length); … … 181 187 } 182 188 } 183 189 184 190 // Connected nodes 185 191 for (Map.Entry<Long, S57map.Snode> entry : map.nodes.entrySet()) { … … 187 193 if (node.flg == Nflag.CONN) { 188 194 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) })); 191 197 record = S57dat.encRecord(recs++, fields); 192 198 System.arraycopy(record, 0, buf, idx, record.length); … … 195 201 } 196 202 } 197 203 198 204 // Edges 199 205 for (Map.Entry<Long, S57map.Edge> entry : map.edges.entrySet()) { 200 206 S57map.Edge edge = entry.getValue(); 201 207 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 })); 204 210 Object[] nodes = new Object[0]; 205 211 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) }; 207 213 nodes = Arrays.copyOf(nodes, (nodes.length + nval.length)); 208 214 System.arraycopy(nval, 0, nodes, (nodes.length - nval.length), nval.length); … … 216 222 edges++; 217 223 } 218 224 219 225 // Meta & Geo objects 226 boolean soundings = false; 220 227 for (Entry<Obj, ArrayList<Feature>> entry : map.features.entrySet()) { 221 228 Obj obj = entry.getKey(); 222 229 for (Feature feature : entry.getValue()) { 230 if (obj == Obj.SOUNDG) { 231 if (soundings) { 232 continue; 233 } else { 234 soundings = true; 235 } 236 } 223 237 int prim = feature.geom.prim.ordinal(); 224 238 prim = (prim == 0) ? 255 : prim; 225 239 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 227 241 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; 229 243 for (Prim elem : feature.geom.elems) { 230 244 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 } 232 250 } else { 233 251 geom.add(new Fparams(S57field.FSPT, new Object[] { ((hash(elem.id) << 8) + 130l), (elem.forward ? 1 : 2), ((outers-- > 0) ? 1 : 2), 2 })); … … 240 258 for (Entry<Obj, ObjTab> objs : feature.objs.entrySet()) { 241 259 Obj objobj = objs.getKey(); 260 boolean master = true; 242 261 for (Entry<Integer, AttMap> object : objs.getValue().entrySet()) { 243 262 ArrayList<Fparams> objatts = new ArrayList<Fparams>(); 244 booleanmaster = (feature.type == objobj) && ((object.getKey() == 0) || (object.getKey() == 1));263 master = (feature.type == objobj) && ((object.getKey() == 0) || (object.getKey() == 1)); 245 264 long id = hash(master ? feature.id : slaveid); 246 265 objatts.add(new Fparams(S57field.FRID, new Object[] { 100, id, prim, grup, S57obj.encodeType(objobj), 1, 1 })); … … 282 301 while (!slaves.isEmpty()) { 283 302 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, "" }; 285 304 params = Arrays.copyOf(params, (params.length + next.length)); 286 305 System.arraycopy(next, 0, params, (params.length - next.length), next.length); … … 289 308 objects.get(objects.size() - 1).addAll(refs); 290 309 } 291 310 292 311 for (ArrayList<Fparams> object : objects) { 293 312 object.addAll(geom); … … 303 322 } 304 323 } 305 324 306 325 // Re-write DSID/DSSI with final totals 307 326 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 })); 310 329 record = S57dat.encRecord(1, ds); 311 330 System.arraycopy(record, 0, buf, header.length, record.length); 312 313 return idx; 331 332 return idx; 333 } 334 314 335 } 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 219 219 } 220 220 221 public MapBounds bounds; 221 222 public NodeTab nodes; 222 223 public EdgeTab edges; 223 224 224 public FtrMap features; 225 225 public FtrTab index; 226 227 public MapBounds bounds;228 229 public long cref;230 226 public long xref; 227 228 private long cref; 231 229 private Feature feature; 232 230 private Edge edge; 233 231 private KeyVal<?> osm = S57osm.OSMtag("", ""); 234 boolean sea;232 private boolean sea; 235 233 236 234 public S57map(boolean s) { … … 367 365 368 366 // OSM map building methods 369 367 370 368 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))); 373 370 feature = new Feature(); 374 371 feature.id = id; … … 555 552 556 553 enum Ext {I, N, W, S, E } 554 557 555 public void mapDone() { 558 556 class Land { … … 579 577 for (Feature feature : features.get(Obj.COALNE)) { 580 578 Feature land = new Feature(); 579 land.id = ++xref; 581 580 land.type = Obj.LNDARE; 582 581 land.reln = Rflag.MASTER; 583 582 land.objs.put(Obj.LNDARE, new ObjTab()); 583 land.objs.get(Obj.LNDARE).put(0, new AttMap()); 584 584 if (feature.geom.prim == Pflag.AREA) { 585 585 land.geom = feature.geom; … … 587 587 } else if (feature.geom.prim == Pflag.LINE) { 588 588 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); 592 590 coasts.add(land); 593 591 } -
applications/editors/josm/plugins/seachart/src/s57/S57osm.java
r31722 r31735 12 12 import java.io.BufferedReader; 13 13 import java.io.IOException; 14 import java.util.ArrayList; 15 import java.util.HashMap; 14 import java.util.*; 16 15 17 16 import s57.S57obj.*; … … 77 76 boolean inWay = false; 78 77 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()); 79 82 80 83 String ln; … … 85 88 if (token.matches("^minlat=.+")) { 86 89 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; 87 92 } else if (token.matches("^minlon=.+")) { 88 93 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; 89 96 } else if (token.matches("^maxlat=.+")) { 90 97 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; 91 100 } else if (token.matches("^maxlon=.+")) { 92 101 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; 93 104 } 94 105 } … … 199 210 return; 200 211 } 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 } 201 222 202 223 }
Note:
See TracChangeset
for help on using the changeset viewer.