Changeset 30215 in osm for applications/editors/josm/plugins/smed2/js57toosm
- Timestamp:
- 2014-01-19T14:52:39+01:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/smed2/js57toosm/src/js57toosm/Js57toosm.java
r30189 r30215 11 11 12 12 import java.io.*; 13 13 import java.util.Map; 14 15 import s57.S57obj; 16 import s57.S57att; 17 import s57.S57att.*; 18 import s57.S57val; 19 import s57.S57val.*; 14 20 import s57.S57dat; 15 21 import s57.S57dat.*; … … 34 40 int len; 35 41 int pos; 42 boolean inFeature = false; 36 43 37 44 double comf = 1; … … 39 46 long name = 0; 40 47 S57map.Nflag nflag = Nflag.ANON; 48 S57map.Pflag prim = S57map.Pflag.NOSP; 49 long objl = 0; 41 50 S57map map = new S57map(); 42 51 double minlat = 90, minlon = 180, maxlat = -90, maxlon = -180; … … 67 76 } 68 77 break; 69 case "DSID":70 break;71 case "DSSI":72 break;73 78 case "DSPM": 74 79 comf = (double) (Long) S57dat.getSubf(record, fields + pos, S57field.DSPM, S57subf.COMF); … … 76 81 break; 77 82 case "FRID": 83 inFeature = true; 84 switch ((int)((long)S57dat.getSubf(record, fields + pos, S57field.FRID, S57subf.PRIM))) { 85 case 1: 86 prim = S57map.Pflag.POINT; 87 break; 88 case 2: 89 prim = S57map.Pflag.LINE; 90 break; 91 case 3: 92 prim = S57map.Pflag.AREA; 93 break; 94 default: 95 prim = S57map.Pflag.NOSP; 96 } 97 objl = (long)S57dat.getSubf(S57subf.OBJL); 78 98 break; 79 99 case "FOID": 100 name = (long) S57dat.getSubf(record, fields + pos, S57field.FOID, S57subf.LNAM); 101 map.newFeature(name, prim, objl); 80 102 break; 81 103 case "ATTF": 82 break; 83 case "NATF": 84 break; 85 case "FFPC": 104 S57dat.setField(record, fields + pos, S57field.ATTF, len); 105 do { 106 long attl = (long) S57dat.getSubf(S57subf.ATTL); 107 String atvl = (String) S57dat.getSubf(S57subf.ATVL); 108 map.newAtt(attl, atvl); 109 } while (S57dat.more()); 86 110 break; 87 111 case "FFPT": 88 break; 89 case "FSPC": 112 name = (long) S57dat.getSubf(record, fields + pos, S57field.FFPT, S57subf.LNAM); 113 int rind = ((Long) S57dat.getSubf(S57subf.RIND)).intValue(); 114 map.newObj(name, rind); 90 115 break; 91 116 case "FSPT": 117 S57dat.setField(record, fields + pos, S57field.FSPT, len); 118 do { 119 name = (Long) S57dat.getSubf(S57subf.NAME) << 16; 120 map.newPrim(name, (long) S57dat.getSubf(S57subf.ORNT), (long) S57dat.getSubf(S57subf.USAG)); 121 } while (S57dat.more()); 92 122 break; 93 123 case "VRID": 94 name = (Long) S57dat.getSubf(record, fields + pos, S57field.VRID, S57subf.RCNM); 124 inFeature = false; 125 name = (long) S57dat.getSubf(record, fields + pos, S57field.VRID, S57subf.RCNM); 95 126 switch ((int) name) { 96 127 case 110: … … 105 136 } 106 137 name <<= 32; 107 name += (Long) S57dat.getSubf( record, fields + pos, S57field.VRID,S57subf.RCID);138 name += (Long) S57dat.getSubf(S57subf.RCID); 108 139 name <<= 16; 109 140 if (nflag == Nflag.ANON) { … … 111 142 } 112 143 break; 113 case "ATTV":114 break;115 case "VRPC":116 break;117 144 case "VRPT": 118 name = (Long) S57dat.getSubf(record, fields + pos, S57field.VRPT, S57subf.NAME) << 16; 119 int topi = ((Long) S57dat.getSubf(S57subf.TOPI)).intValue(); 120 map.addConn(name, topi); 121 name = (Long) S57dat.getSubf(S57subf.NAME) << 16; 122 topi = ((Long) S57dat.getSubf(S57subf.TOPI)).intValue(); 123 map.addConn(name, topi); 124 break; 125 case "SGCC": 145 S57dat.setField(record, fields + pos, S57field.VRPT, len); 146 do { 147 name = (Long) S57dat.getSubf(S57subf.NAME) << 16; 148 int topi = ((Long) S57dat.getSubf(S57subf.TOPI)).intValue(); 149 map.addConn(name, topi); 150 } while (S57dat.more()); 126 151 break; 127 152 case "SG2D": 128 153 S57dat.setField(record, fields + pos, S57field.SG2D, len); 129 while (S57dat.more()){154 do { 130 155 double lat = (double) ((Long) S57dat.getSubf(S57subf.YCOO)) / comf; 131 156 double lon = (double) ((Long) S57dat.getSubf(S57subf.XCOO)) / comf; … … 143 168 if (lon > maxlon) 144 169 maxlon = lon; 145 } 170 } while (S57dat.more()); 146 171 break; 147 172 case "SG3D": 148 173 S57dat.setField(record, fields + pos, S57field.SG3D, len); 149 while (S57dat.more()){174 do { 150 175 double lat = (double) ((Long) S57dat.getSubf(S57subf.YCOO)) / comf; 151 176 double lon = (double) ((Long) S57dat.getSubf(S57subf.XCOO)) / comf; … … 160 185 if (lon > maxlon) 161 186 maxlon = lon; 162 } 187 } while (S57dat.more()); 163 188 break; 164 189 } 165 190 } 166 } 167 } 191 if (inFeature) { 192 map.endFeature(); 193 inFeature = false; 194 } 195 } 196 } 197 map.endFile(); 168 198 in.close(); 169 199 … … 172 202 out.println("<bounds minlat='" + minlat +"' minlon='" + minlon + "' maxlat='" + maxlat + "' maxlon='" + maxlon + "'/>"); 173 203 204 for (long id : map.index.keySet()) { 205 Feature feature = map.index.get(id); 206 if (feature.reln != Rflag.SLAVE) { 207 if (feature.geom.prim == Pflag.POINT) { 208 Snode node = map.nodes.get(feature.geom.elems.get(0).id); 209 String type = S57obj.stringType(feature.type); 210 out.format(" <node id='%d' lat='%f' lon='%f' version='1'>%n",-id, Math.toDegrees(node.lat), Math.toDegrees(node.lon)); 211 out.format(" <tag k='seamark:type' v=\"%s\"/>%n", type); 212 for (Map.Entry<Att, AttVal<?>> item : feature.atts.entrySet()) { 213 out.format(" <tag k='seamark:%s:%s' v=\"%s\"/>%n", type, S57att.stringAttribute(item.getKey()), S57val.stringValue(item.getValue())); 214 } 215 for (Reln rel : feature.rels) { 216 if (rel.reln == Rflag.SLAVE) { 217 Feature slave = map.index.get(rel.id); 218 type = S57obj.stringType(slave.type); 219 for (Map.Entry<Att, AttVal<?>> item : slave.atts.entrySet()) { 220 out.format(" <tag k='seamark:%s:%s' v=\"%s\"/>%n", type, S57att.stringAttribute(item.getKey()), S57val.stringValue(item.getValue())); 221 } 222 } 223 } 224 out.format(" </node>%n"); 225 } 226 } 227 } 228 /* 174 229 for (long id : map.nodes.keySet()) { 175 230 Snode node = map.nodes.get(id); … … 194 249 out.format(" </way>%n"); 195 250 } 196 251 */ 197 252 out.println("</osm>\n"); 198 253 }
Note:
See TracChangeset
for help on using the changeset viewer.