Changeset 32907 in osm for applications/editors/josm/plugins/seachart/josmtos57/src
- Timestamp:
- 2016-09-03T16:43:42+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/seachart/josmtos57/src/josmtos57/Josmtos57.java
r32906 r32907 1 /* Copyright 2015 Malcolm Herring 2 * 3 * This is free software: you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License as published by 5 * the Free Software Foundation, version 3 of the License. 6 * 7 * For a copy of the GNU General Public License, see <http://www.gnu.org/licenses/>. 8 */ 9 1 // License: GPL. For details, see LICENSE file. 10 2 package josmtos57; 11 3 12 import java.io.*; 13 import java.util.*; 4 import java.io.BufferedReader; 5 import java.io.File; 6 import java.io.FileInputStream; 7 import java.io.FileOutputStream; 8 import java.io.FileReader; 9 import java.io.IOException; 10 import java.io.UnsupportedEncodingException; 11 import java.util.ArrayList; 12 import java.util.Arrays; 13 import java.util.HashMap; 14 import java.util.Scanner; 14 15 import java.util.zip.CRC32; 15 16 16 17 import s57.S57dat; 18 import s57.S57dat.Fparams; 19 import s57.S57dat.S57field; 17 20 import s57.S57enc; 18 21 import s57.S57map; 19 22 import s57.S57osm; 20 import s57.S57dat.*;21 23 22 public class Josmtos57 { 24 /** 25 * @author Malcolm Herring 26 */ 27 public final class Josmtos57 { 28 private Josmtos57() { 29 // Hide default constructor for utilities classes 30 } 23 31 24 32 // http://opendatacommons.org/licenses/odbl/1-0/ 25 33 26 34 /* 27 35 URL website = new URL("http://www.website.com/information.asp"); 28 36 try (InputStream in = website.openStream()) { Files.copy(in, target, StandardCopyOption.REPLACE_EXISTING); } 29 37 */ 30 38 31 39 /* 32 40 * To do: … … 37 45 38 46 static byte[] header = { 39 '0', '0', '2', '6', '2', '3', 'L', 'E', '1', ' ', '0', '9', '0', '0', '0', '7', '3', ' ', ' ', ' ', '6', '6', '0', '4', '0', '0', '0', '0', '0', '0', '0', '0', 40 '1', '9', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '0', '0', '0', '0', '4', '8', '0', '0', '0', '0', '1', '9', 'C', 'A', 'T', 'D', '0', '0', '0', '1', 41 '2', '2', '0', '0', '0', '0', '6', '7', 0x1e, '0', '0', '0', '0', ';', '&', ' ', ' ', ' ', 0x1f, '0', '0', '0', '1', 'C', 'A', 'T', 'D', 0x1e, '0', '1', '0', '0', 42 ';', '&', ' ', ' ', ' ', 'I', 'S', 'O', '/', 'I', 'E', 'C', ' ', '8', '2', '1', '1', ' ', 'R', 'e', 'c', 'o', 'r', 'd', ' ', 'I', 'd', 'e', 'n', 't', 'i', 'f', 43 'i', 'e', 'r', 0x1f, 0x1f, '(', 'I', '(', '5', ')', ')', 0x1e, '1', '6', '0', '0', ';', '&', ' ', ' ', ' ', 'C', 'a', 't', 'a', 'l', 'o', 'g', 'u', 'e', ' ', 'D', 44 'i', 'r', 'e', 'c', 't', 'o', 'r', 'y', ' ', 'F', 'i', 'e', 'l', 'd', 0x1f, 'R', 'C', 'N', 'M', '!', 'R', 'C', 'I', 'D', '!', 'F', 'I', 'L', 'E', '!', 'L', 'F', 45 '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', 46 '!', 'C', 'R', 'C', 'S', '!', 'C', 'O', 'M', 'T', 0x1f, '(', 'A', '(', '2', ')', ',', 'I', '(', '1', '0', ')', ',', '3', 'A', ',', 'A', '(', '3', ')', ',', '4', 47 'R', ',', '2', 'A', ')', 0x1e, 48 '0', '0', '1', '0', '1', ' ', 'D', ' ', ' ', ' ', ' ', ' ', '0', '0', '0', '5', '3', ' ', ' ', ' ', '5', '5', '0', '4', 49 '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, 50 '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, 51 0x1f, 'V', '0', '1', 'X', '0', '1', 0x1f, 'A', 'S', 'C', 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1e 47 // CHECKSTYLE.OFF: LineLength 48 '0', '0', '2', '6', '2', '3', 'L', 'E', '1', ' ', '0', '9', '0', '0', '0', '7', '3', ' ', ' ', ' ', '6', '6', '0', '4', '0', '0', '0', '0', '0', '0', '0', '0', 49 '1', '9', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '0', '0', '0', '0', '4', '8', '0', '0', '0', '0', '1', '9', 'C', 'A', 'T', 'D', '0', '0', '0', '1', 50 '2', '2', '0', '0', '0', '0', '6', '7', 0x1e, '0', '0', '0', '0', ';', '&', ' ', ' ', ' ', 0x1f, '0', '0', '0', '1', 'C', 'A', 'T', 'D', 0x1e, '0', '1', '0', '0', 51 ';', '&', ' ', ' ', ' ', 'I', 'S', 'O', '/', 'I', 'E', 'C', ' ', '8', '2', '1', '1', ' ', 'R', 'e', 'c', 'o', 'r', 'd', ' ', 'I', 'd', 'e', 'n', 't', 'i', 'f', 52 'i', 'e', 'r', 0x1f, 0x1f, '(', 'I', '(', '5', ')', ')', 0x1e, '1', '6', '0', '0', ';', '&', ' ', ' ', ' ', 'C', 'a', 't', 'a', 'l', 'o', 'g', 'u', 'e', ' ', 'D', 53 'i', 'r', 'e', 'c', 't', 'o', 'r', 'y', ' ', 'F', 'i', 'e', 'l', 'd', 0x1f, 'R', 'C', 'N', 'M', '!', 'R', 'C', 'I', 'D', '!', 'F', 'I', 'L', 'E', '!', 'L', 'F', 54 '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', 55 '!', 'C', 'R', 'C', 'S', '!', 'C', 'O', 'M', 'T', 0x1f, '(', 'A', '(', '2', ')', ',', 'I', '(', '1', '0', ')', ',', '3', 'A', ',', 'A', '(', '3', ')', ',', '4', 56 'R', ',', '2', 'A', ')', 0x1e, 57 '0', '0', '1', '0', '1', ' ', 'D', ' ', ' ', ' ', ' ', ' ', '0', '0', '0', '5', '3', ' ', ' ', ' ', '5', '5', '0', '4', 58 '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, 59 '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, 60 0x1f, 'V', '0', '1', 'X', '0', '1', 0x1f, 'A', 'S', 'C', 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1e 61 // CHECKSTYLE.ON: LineLength 52 62 }; 53 63 54 64 static BufferedReader in; 55 65 static FileOutputStream out; … … 59 69 static ArrayList<Fparams> fields; 60 70 static byte[] record; 61 71 62 72 public static void main(String[] args) throws IOException { 63 73 64 74 map = new S57map(false); 65 75 int idx = 0; 66 76 67 77 if (args.length < 4) { 68 78 System.err.println("Usage: java -jar josmtos57.jar OSM_filename meta_data_filename S57_ENC_ROOT_directory S57_filename"); … … 96 106 System.exit(-1); 97 107 } 98 108 99 109 try { 100 110 buf = new byte[5242880]; … … 107 117 System.exit(-1); 108 118 } 109 119 110 120 CRC32 crc = new CRC32(); 111 121 crc.update(buf, 0, idx); … … 120 130 } 121 131 out.close(); 122 132 123 133 buf = new byte[header.length]; 124 134 System.arraycopy(header, 0, buf, 0, header.length); … … 126 136 int recs = 2; 127 137 fields = new ArrayList<>(); 128 fields.add(new Fparams(S57field.CATD, new Object[]{ "CD", recs, args[3], "", "V01X01", "BIN", Math.toDegrees(map.bounds.minlat), 129 Math.toDegrees(map.bounds.minlon), Math.toDegrees(map.bounds.maxlat), Math.toDegrees(map.bounds.maxlon), String.format("%08X", crc.getValue()), "" })); 138 fields.add(new Fparams(S57field.CATD, new Object[]{"CD", recs, args[3], "", "V01X01", "BIN", Math.toDegrees(map.bounds.minlat), 139 Math.toDegrees(map.bounds.minlon), Math.toDegrees(map.bounds.maxlat), Math.toDegrees(map.bounds.maxlon), 140 String.format("%08X", crc.getValue()), ""})); 130 141 record = S57dat.encRecord(String.valueOf(recs++), fields); 131 142 buf = Arrays.copyOf(buf, (buf.length + record.length)); … … 144 155 out.close(); 145 156 146 // String[] dir = (new File(args[2]).list()); 147 // for (String item : dir) { 148 // System.err.println(item); 149 // } 150 157 // String[] dir = (new File(args[2]).list()); 158 // for (String item : dir) { 159 // System.err.println(item); 160 // } 161 151 162 System.err.println("Finished"); 152 163 }
Note:
See TracChangeset
for help on using the changeset viewer.