Changeset 30284 in osm for applications/editors/josm/plugins/smed2/js57toosm
- Timestamp:
- 2014-02-16T11:17:53+01:00 (11 years ago)
- Location:
- applications/editors/josm/plugins/smed2/js57toosm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/smed2/js57toosm/build.xml
r30269 r30284 3 3 <property name="build" location="build"/> 4 4 <property name="jarfile" location="./js57toosm.jar"/> 5 5 <property name="ant.build.javac.target" value="1.6"/> 6 <property name="ant.build.javac.source" value="1.6"/> 7 6 8 <target name="init"> 7 9 <mkdir dir="${build}"/> -
applications/editors/josm/plugins/smed2/js57toosm/src/js57toosm/Js57toosm.java
r30283 r30284 13 13 import java.util.*; 14 14 15 import s57.S57map.Prim;16 15 import s57.S57obj; 17 16 import s57.S57obj.*; … … 20 19 import s57.S57val; 21 20 import s57.S57val.*; 22 import s57.S57dat;23 import s57.S57dat.*;24 21 import s57.S57map; 25 22 import s57.S57map.*; 23 import s57.S57dec; 26 24 27 25 public class Js57toosm { … … 33 31 public static void main(String[] args) throws IOException { 34 32 33 ArrayList<Long> done = new ArrayList<Long>(); 34 35 35 if (args.length < 1) { 36 36 System.err.println("Usage: java -jar js57toosm.jar S57_filename [types_filename]"); … … 49 49 50 50 map = new S57map(); 51 S57dat.rnum = 0; 52 53 byte[] leader = new byte[24]; 54 boolean ddr = false; 55 int length; 56 int fields; 57 int mapfl, mapfp, mapts, entry; 58 String tag; 59 int len; 60 int pos; 61 boolean inFeature = false; 62 63 double comf = 1; 64 double somf = 1; 65 long name = 0; 66 S57map.Nflag nflag = Nflag.ANON; 67 S57map.Pflag pflag = S57map.Pflag.NOSP; 68 long objl = 0; 69 double minlat = 90, minlon = 180, maxlat = -90, maxlon = -180; 70 71 ArrayList<Long> done = new ArrayList<Long>(); 72 73 while (in.read(leader) == 24) { 74 length = Integer.parseInt(new String(leader, 0, 5)) - 24; 75 ddr = (leader[6] == 'L'); 76 fields = Integer.parseInt(new String(leader, 12, 5)) - 24; 77 mapfl = leader[20] - '0'; 78 mapfp = leader[21] - '0'; 79 mapts = leader[23] - '0'; 80 entry = mapfl + mapfp + mapts; 81 byte[] record = new byte[length]; 82 if (in.read(record) != length) 83 break; 84 for (int idx = 0; idx < fields-1; idx += entry) { 85 tag = new String(record, idx, mapts); 86 len = Integer.parseInt(new String(record, idx+mapts, mapfl)); 87 pos = Integer.parseInt(new String(record, idx+mapts+mapfl, mapfp)); 88 if (!ddr) { 89 switch (tag) { 90 case "0001": 91 int i8rn = ((Long) S57dat.getSubf(record, fields + pos, S57field.I8RI, S57subf.I8RN)).intValue(); 92 if (i8rn != ++S57dat.rnum) { 93 out.println("Out of order record ID"); 94 in.close(); 95 System.exit(-1); 96 } 97 break; 98 case "DSPM": 99 comf = (double) (Long) S57dat.getSubf(record, fields + pos, S57field.DSPM, S57subf.COMF); 100 somf = (double) (Long) S57dat.getSubf(S57subf.SOMF); 101 break; 102 case "FRID": 103 inFeature = true; 104 switch ((int)((long)S57dat.getSubf(record, fields + pos, S57field.FRID, S57subf.PRIM))) { 105 case 1: 106 pflag = S57map.Pflag.POINT; 107 break; 108 case 2: 109 pflag = S57map.Pflag.LINE; 110 break; 111 case 3: 112 pflag = S57map.Pflag.AREA; 113 break; 114 default: 115 pflag = S57map.Pflag.NOSP; 116 } 117 objl = (long)S57dat.getSubf(S57subf.OBJL); 118 break; 119 case "FOID": 120 name = (long) S57dat.getSubf(record, fields + pos, S57field.FOID, S57subf.LNAM); 121 map.newFeature(name, pflag, objl); 122 break; 123 case "ATTF": 124 S57dat.setField(record, fields + pos, S57field.ATTF, len); 125 do { 126 long attl = (long) S57dat.getSubf(S57subf.ATTL); 127 String atvl = (String) S57dat.getSubf(S57subf.ATVL); 128 if (!atvl.isEmpty()) { 129 map.newAtt(attl, atvl); 130 } 131 } while (S57dat.more()); 132 break; 133 case "FFPT": 134 S57dat.setField(record, fields + pos, S57field.FFPT, len); 135 do { 136 name = (long) S57dat.getSubf(S57subf.LNAM); 137 int rind = ((Long) S57dat.getSubf(S57subf.RIND)).intValue(); 138 S57dat.getSubf(S57subf.COMT); 139 map.newObj(name, rind); 140 } while (S57dat.more()); 141 break; 142 case "FSPT": 143 S57dat.setField(record, fields + pos, S57field.FSPT, len); 144 do { 145 name = (Long) S57dat.getSubf(S57subf.NAME) << 16; 146 map.newPrim(name, (long) S57dat.getSubf(S57subf.ORNT), (long) S57dat.getSubf(S57subf.USAG)); 147 S57dat.getSubf(S57subf.MASK); 148 } while (S57dat.more()); 149 break; 150 case "VRID": 151 inFeature = false; 152 name = (long) S57dat.getSubf(record, fields + pos, S57field.VRID, S57subf.RCNM); 153 switch ((int) name) { 154 case 110: 155 nflag = Nflag.ISOL; 156 break; 157 case 120: 158 nflag = Nflag.CONN; 159 break; 160 default: 161 nflag = Nflag.ANON; 162 break; 163 } 164 name <<= 32; 165 name += (Long) S57dat.getSubf(S57subf.RCID); 166 name <<= 16; 167 if (nflag == Nflag.ANON) { 168 map.newEdge(name); 169 } 170 break; 171 case "VRPT": 172 S57dat.setField(record, fields + pos, S57field.VRPT, len); 173 do { 174 long conn = (Long) S57dat.getSubf(S57subf.NAME) << 16; 175 int topi = ((Long) S57dat.getSubf(S57subf.TOPI)).intValue(); 176 map.addConn(conn, topi); 177 S57dat.getSubf(S57subf.MASK); 178 } while (S57dat.more()); 179 break; 180 case "SG2D": 181 S57dat.setField(record, fields + pos, S57field.SG2D, len); 182 do { 183 double lat = (double) ((Long) S57dat.getSubf(S57subf.YCOO)) / comf; 184 double lon = (double) ((Long) S57dat.getSubf(S57subf.XCOO)) / comf; 185 if (nflag == Nflag.ANON) { 186 map.newNode(++name, lat, lon, nflag); 187 } else { 188 map.newNode(name, lat, lon, nflag); 189 } 190 if (lat < minlat) 191 minlat = lat; 192 if (lat > maxlat) 193 maxlat = lat; 194 if (lon < minlon) 195 minlon = lon; 196 if (lon > maxlon) 197 maxlon = lon; 198 } while (S57dat.more()); 199 break; 200 case "SG3D": 201 S57dat.setField(record, fields + pos, S57field.SG3D, len); 202 do { 203 double lat = (double) ((Long) S57dat.getSubf(S57subf.YCOO)) / comf; 204 double lon = (double) ((Long) S57dat.getSubf(S57subf.XCOO)) / comf; 205 double depth = (double) ((Long) S57dat.getSubf(S57subf.VE3D)) / somf; 206 map.newNode(name++, lat, lon, depth); 207 if (lat < minlat) 208 minlat = lat; 209 if (lat > maxlat) 210 maxlat = lat; 211 if (lon < minlon) 212 minlon = lon; 213 if (lon > maxlon) 214 maxlon = lon; 215 } while (S57dat.more()); 216 break; 217 } 218 } 219 if (inFeature) { 220 map.endFeature(); 221 inFeature = false; 222 } 223 } 224 } 225 map.endFile(); 226 in.close(); 227 228 out.println("<?xml version='1.0' encoding='UTF-8'?>"); 229 out.println("<osm version='0.6' generator='js57toosm'>"); 230 out.println("<bounds minlat='" + minlat + "' minlon='" + minlon + "' maxlat='" + maxlat + "' maxlon='" + maxlon + "'/>"); 51 MapBounds bounds = S57dec.decodeFile(in, types, map); 52 53 out.format("<?xml version='1.0' encoding='UTF-8'?>"); 54 out.format("<osm version='0.6' generator='js57toosm'>"); 55 out.format("<bounds minlat='%.8f' minlon='%.8f' maxlat='%.8f' maxlon='%.8f'/>", bounds.minlat, bounds.minlon, bounds.maxlat, bounds.maxlon); 231 56 232 57 for (long id : map.index.keySet()) { … … 261 86 if (!type.isEmpty() && (types.isEmpty() || types.contains(feature.type))) { 262 87 if (feature.reln == Rflag.MASTER) { 263 if ( feature.geom.prim == Pflag.LINE) {88 if ((feature.geom.prim == Pflag.LINE) || ((feature.geom.prim == Pflag.AREA) && (feature.geom.outers == 1) && (feature.geom.inners == 0))) { 264 89 GeomIterator git = map.new GeomIterator(feature.geom); 265 90 while (git.hasComp()) {
Note:
See TracChangeset
for help on using the changeset viewer.