Changeset 30186 in osm for applications/editors/josm
- Timestamp:
- 2014-01-06T16:26:41+01:00 (11 years ago)
- 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 19 19 public class Js57toosm { 20 20 21 public static int rnum = 0; 22 21 23 public static void main(String[] args) throws IOException { 22 24 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"); 24 26 PrintStream out = System.out; 25 27 … … 36 38 double somf = 1; 37 39 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; 39 43 40 44 while (in.read(leader) == 24) { … … 55 59 if (!ddr) switch (tag) { 56 60 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 } 58 67 break; 59 68 case "DSID": … … 82 91 break; 83 92 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; 85 106 name += (long)S57dat.getSubf(record, fields+pos, S57field.VRID, S57subf.RCID); 86 107 name <<= 16; 108 if (nflag == Nflag.ANON) { 109 map.newEdge(name); 110 } 87 111 break; 88 112 case "ATTV": … … 91 115 break; 92 116 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); 93 123 break; 94 124 case "SGCC": … … 99 129 double lat = (double) ((long) S57dat.getSubf(S57subf.YCOO)) / comf; 100 130 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; 102 140 } 103 141 break; … … 108 146 double lon = (double) ((long) S57dat.getSubf(S57subf.XCOO)) / comf; 109 147 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; 111 153 } 112 154 break; … … 114 156 } 115 157 } 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)); 123 173 } 124 174 } 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"); 130 188 } 131 189 -
applications/editors/josm/plugins/smed2/src/render/Renderer.java
r30184 r30186 198 198 switch (feature.flag) { 199 199 case LINE: 200 Edge edge = map.edges.get(feature. id);200 Edge edge = map.edges.get(feature.refs); 201 201 area = map.new Area(); 202 202 area.add(map.new Bound(map.new Side(edge, true), true)); 203 203 break; 204 204 case AREA: 205 area = map.areas.get(feature. id);205 area = map.areas.get(feature.refs); 206 206 break; 207 207 default: … … 288 288 switch (feature.flag) { 289 289 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); 291 291 point = context.getPoint(eit.next()); 292 292 p.moveTo(point.getX(), point.getY()); … … 297 297 break; 298 298 case AREA: 299 for (Bound bound : map.areas.get(feature. id)) {299 for (Bound bound : map.areas.get(feature.refs)) { 300 300 BoundIterator bit = map.new BoundIterator(bound); 301 301 point = context.getPoint(bit.next()); … … 373 373 break; 374 374 case AREA: 375 for (Bound bound : map.areas.get(feature. id)) {375 for (Bound bound : map.areas.get(feature.refs)) { 376 376 BoundIterator bit = map.new BoundIterator(bound); 377 377 point = context.getPoint(bit.next()); … … 506 506 switch (feature.flag) { 507 507 case LINE: 508 Edge edge = map.edges.get(feature. id);508 Edge edge = map.edges.get(feature.refs); 509 509 area = map.new Area(); 510 510 area.add(map.new Bound(map.new Side(edge, true), true)); 511 511 break; 512 512 case AREA: 513 area = map.areas.get(feature. id);513 area = map.areas.get(feature.refs); 514 514 break; 515 515 default: -
applications/editors/josm/plugins/smed2/src/s57/S57dat.java
r30183 r30186 4 4 import java.util.Arrays; 5 5 import java.util.EnumMap; 6 7 import js57toosm.Js57toosm; 6 8 7 9 public class S57dat { … … 27 29 static { 28 30 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)); 30 32 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)); 31 33 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)); … … 49 51 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)); 50 52 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)); 53 55 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)); 54 56 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)); … … 60 62 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)); 61 63 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)); 63 65 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)); 65 67 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)); 66 68 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)); … … 166 168 public static Object getSubf(S57subf subf) { 167 169 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 } 171 181 S57subf sub = subs.get(index++); 172 182 S57conv conv = convs.get(sub); 173 183 if (sub == subf) { 174 184 if (conv.bin == 0) { 185 String str = ""; 175 186 if (conv.asc == 0) { 176 String str = "";177 187 while (buffer[offset] != 0x1f) { 178 188 str += buffer[offset++]; 179 189 } 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; 184 195 } 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; 191 213 } 192 offset += (conv.bin != 0) ? Math.abs(conv.bin) : conv.asc;193 return val;194 214 } 195 215 } 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; 197 217 } 198 218 } 199 return null;200 219 } 201 220 -
applications/editors/josm/plugins/smed2/src/s57/S57map.java
r30183 r30186 174 174 public class Feature { 175 175 public Fflag flag; 176 public long id;176 public long refs; 177 177 public Obj type; 178 178 public AttMap atts; … … 184 184 Feature() { 185 185 flag = Fflag.UNKN; 186 id= 0;186 refs = 0; 187 187 type = Obj.UNKOBJ; 188 188 atts = new AttMap(); … … 304 304 nodes.put(id, new Snode(Math.toRadians(lat), Math.toRadians(lon))); 305 305 feature = new Feature(); 306 feature. id= id;306 feature.refs = id; 307 307 feature.flag = Fflag.POINT; 308 308 edge = null; 309 309 } 310 310 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) { 312 319 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 } 317 333 } 318 334 319 335 public void addEdge(long id) { 320 336 feature = new Feature(); 321 feature. id= id;337 feature.refs = id; 322 338 feature.flag = Fflag.LINE; 323 339 edge = new Edge(); … … 337 353 public void addArea(long id) { 338 354 feature = new Feature(); 339 feature. id= id;355 feature.refs = id; 340 356 feature.flag = Fflag.AREA; 341 357 outers = new ArrayList<Long>(); … … 530 546 switch (feature.flag) { 531 547 case POINT: 532 return nodes.get(feature. id);548 return nodes.get(feature.refs); 533 549 case LINE: 534 Edge edge = edges.get(feature. id);550 Edge edge = edges.get(feature.refs); 535 551 EdgeIterator eit = new EdgeIterator(edge, true); 536 552 while (eit.hasNext()) { … … 567 583 return new Snode(llat + ((lat - llat) * harc / sarc), llon + ((lon - llon) * harc / sarc)); 568 584 case AREA: 569 Bound bound = areas.get(feature. id).get(0);585 Bound bound = areas.get(feature.refs).get(0); 570 586 BoundIterator bit = new BoundIterator(bound); 571 587 while (bit.hasNext()) {
Note:
See TracChangeset
for help on using the changeset viewer.