Changeset 32906 in osm
- Timestamp:
- 2016-09-03T16:18:15+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/seachart
- Files:
-
- 6 edited
-
jbasemap/src/jbasemap/Jbasemap.java (modified) (1 diff)
-
jicons/src/jicons/Jicons.java (modified) (1 diff)
-
josmtos57/src/josmtos57/Josmtos57.java (modified) (1 diff)
-
jplotter/src/jplotter/Jplotter.java (modified) (1 diff)
-
jrender/src/jrender/Jrender.java (modified) (1 diff)
-
js57toosm/src/js57toosm/Js57toosm.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified applications/editors/josm/plugins/seachart/jbasemap/src/jbasemap/Jbasemap.java ¶
r32082 r32906 31 31 public class Jbasemap { 32 32 33 static String src;34 static String dst;35 static Context context;36 static S57map map;37 static int zoom;38 static double z2;33 static String src; 34 static String dst; 35 static Context context; 36 static S57map map; 37 static int zoom; 38 static double z2; 39 39 40 static class Context implements ChartContext {41 42 static double top = 0;43 static double mile = 0;44 45 public Context () {46 top = (1.0 - Math.log(Math.tan(map.bounds.maxlat) + 1.0 / Math.cos(map.bounds.maxlat)) / Math.PI) / 2.0 * 256.0 * z2;47 mile = 256 / ((Math.toDegrees(map.bounds.maxlat) - Math.toDegrees(map.bounds.minlat)) * 60);48 }49 50 public Point2D getPoint(Snode coord) {51 double x = (Math.toDegrees(coord.lon) - Math.toDegrees(map.bounds.minlon)) * 256.0 * (z2 / 2) / 180.0;52 double y = ((1.0 - Math.log(Math.tan(coord.lat) + 1.0 / Math.cos(coord.lat)) / Math.PI) / 2.0 * 256.0 * z2) - top;53 return new Point2D.Double(x, y);54 }40 static class Context implements ChartContext { 41 42 static double top = 0; 43 static double mile = 0; 44 45 public Context () { 46 top = (1.0 - Math.log(Math.tan(map.bounds.maxlat) + 1.0 / Math.cos(map.bounds.maxlat)) / Math.PI) / 2.0 * 256.0 * z2; 47 mile = 256 / ((Math.toDegrees(map.bounds.maxlat) - Math.toDegrees(map.bounds.minlat)) * 60); 48 } 49 50 public Point2D getPoint(Snode coord) { 51 double x = (Math.toDegrees(coord.lon) - Math.toDegrees(map.bounds.minlon)) * 256.0 * (z2 / 2) / 180.0; 52 double y = ((1.0 - Math.log(Math.tan(coord.lat) + 1.0 / Math.cos(coord.lat)) / Math.PI) / 2.0 * 256.0 * z2) - top; 53 return new Point2D.Double(x, y); 54 } 55 55 56 public double mile(Feature feature) {57 return mile;58 }56 public double mile(Feature feature) { 57 return mile; 58 } 59 59 60 public boolean clip() {61 return true;62 }60 public boolean clip() { 61 return true; 62 } 63 63 64 public Color background(S57map map) {65 if (map.features.containsKey(Obj.COALNE)) {66 for (Feature feature : map.features.get(Obj.COALNE)) {67 if (feature.geom.prim == Pflag.POINT) {68 break;69 }70 GeomIterator git = map.new GeomIterator(feature.geom);71 git.nextComp();72 while (git.hasEdge()) {73 git.nextEdge();74 while (git.hasNode()) {75 Snode node = git.next();76 if (node == null)77 continue;78 if ((node.lat >= map.bounds.minlat) && (node.lat <= map.bounds.maxlat) && (node.lon >= map.bounds.minlon) && (node.lon <= map.bounds.maxlon)) {79 return Symbols.Bwater;80 }81 }82 }83 }84 return Symbols.Yland;85 } else {86 if (map.features.containsKey(Obj.ROADWY) || map.features.containsKey(Obj.RAILWY) || map.features.containsKey(Obj.LAKARE) || map.features.containsKey(Obj.RIVERS) || map.features.containsKey(Obj.CANALS)) {87 return Symbols.Yland;88 } else {89 return Symbols.Bwater;90 }91 }92 }64 public Color background(S57map map) { 65 if (map.features.containsKey(Obj.COALNE)) { 66 for (Feature feature : map.features.get(Obj.COALNE)) { 67 if (feature.geom.prim == Pflag.POINT) { 68 break; 69 } 70 GeomIterator git = map.new GeomIterator(feature.geom); 71 git.nextComp(); 72 while (git.hasEdge()) { 73 git.nextEdge(); 74 while (git.hasNode()) { 75 Snode node = git.next(); 76 if (node == null) 77 continue; 78 if ((node.lat >= map.bounds.minlat) && (node.lat <= map.bounds.maxlat) && (node.lon >= map.bounds.minlon) && (node.lon <= map.bounds.maxlon)) { 79 return Symbols.Bwater; 80 } 81 } 82 } 83 } 84 return Symbols.Yland; 85 } else { 86 if (map.features.containsKey(Obj.ROADWY) || map.features.containsKey(Obj.RAILWY) || map.features.containsKey(Obj.LAKARE) || map.features.containsKey(Obj.RIVERS) || map.features.containsKey(Obj.CANALS)) { 87 return Symbols.Yland; 88 } else { 89 return Symbols.Bwater; 90 } 91 } 92 } 93 93 94 public RuleSet ruleset() {95 return RuleSet.BASE;96 }97 }98 99 public static void main(String[] args) throws IOException {100 if (args.length < 5) {101 System.err.println("Usage: java -jar jbasemap.jar OSM_file SVG_file zoom xtile ytile");102 System.exit(-1);103 }104 src = args[0];105 dst = args[1];106 zoom = Integer.parseInt(args[2]);107 z2 = Math.pow(2, zoom);108 double scale = 0.1;109 try {110 BufferedReader in = new BufferedReader(new FileReader(src));111 map = new S57map(false);112 try {113 S57osm.OSMmap(in, map, true);114 } catch (Exception e) {115 System.err.println("Input data error");116 System.exit(-1);117 }118 in.close();119 } catch (IOException e) {120 System.err.println("Input file: " + e.getMessage());121 System.exit(-1);122 }123 map.bounds.maxlat = Math.atan(Math.sinh(Math.PI * (1 - 2 * Double.parseDouble(args[4]) / z2)));124 map.bounds.minlat = Math.atan(Math.sinh(Math.PI * (1 - 2 * (Double.parseDouble(args[4]) + 1) / z2)));125 map.bounds.minlon = Math.toRadians(Double.parseDouble(args[3]) / z2 * 360.0 - 180.0);126 map.bounds.maxlon = Math.toRadians((Double.parseDouble(args[3]) + 1) / z2 * 360.0 - 180.0);127 context = new Context();128 Rectangle rect = new Rectangle(256, 256);129 DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();130 Document document = domImpl.createDocument("http://www.w3.org/2000/svg", "svg", null);131 SVGGraphics2D svgGenerator = new SVGGraphics2D(document);132 svgGenerator.clearRect(rect.x, rect.y, rect.width, rect.height);133 svgGenerator.setSVGCanvasSize(rect.getSize());134 svgGenerator.setClip(rect.x, rect.y, rect.width, rect.height);135 Renderer.reRender(svgGenerator, rect, zoom, scale, map, context);136 svgGenerator.stream(dst);137 System.exit(0);138 }94 public RuleSet ruleset() { 95 return RuleSet.BASE; 96 } 97 } 98 99 public static void main(String[] args) throws IOException { 100 if (args.length < 5) { 101 System.err.println("Usage: java -jar jbasemap.jar OSM_file SVG_file zoom xtile ytile"); 102 System.exit(-1); 103 } 104 src = args[0]; 105 dst = args[1]; 106 zoom = Integer.parseInt(args[2]); 107 z2 = Math.pow(2, zoom); 108 double scale = 0.1; 109 try { 110 BufferedReader in = new BufferedReader(new FileReader(src)); 111 map = new S57map(false); 112 try { 113 S57osm.OSMmap(in, map, true); 114 } catch (Exception e) { 115 System.err.println("Input data error"); 116 System.exit(-1); 117 } 118 in.close(); 119 } catch (IOException e) { 120 System.err.println("Input file: " + e.getMessage()); 121 System.exit(-1); 122 } 123 map.bounds.maxlat = Math.atan(Math.sinh(Math.PI * (1 - 2 * Double.parseDouble(args[4]) / z2))); 124 map.bounds.minlat = Math.atan(Math.sinh(Math.PI * (1 - 2 * (Double.parseDouble(args[4]) + 1) / z2))); 125 map.bounds.minlon = Math.toRadians(Double.parseDouble(args[3]) / z2 * 360.0 - 180.0); 126 map.bounds.maxlon = Math.toRadians((Double.parseDouble(args[3]) + 1) / z2 * 360.0 - 180.0); 127 context = new Context(); 128 Rectangle rect = new Rectangle(256, 256); 129 DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation(); 130 Document document = domImpl.createDocument("http://www.w3.org/2000/svg", "svg", null); 131 SVGGraphics2D svgGenerator = new SVGGraphics2D(document); 132 svgGenerator.clearRect(rect.x, rect.y, rect.width, rect.height); 133 svgGenerator.setSVGCanvasSize(rect.getSize()); 134 svgGenerator.setClip(rect.x, rect.y, rect.width, rect.height); 135 Renderer.reRender(svgGenerator, rect, zoom, scale, map, context); 136 svgGenerator.stream(dst); 137 System.exit(0); 138 } 139 139 } -
TabularUnified applications/editors/josm/plugins/seachart/jicons/src/jicons/Jicons.java ¶
r32380 r32906 37 37 38 38 public class Jicons { 39 40 static int x = 0;41 static int y = 0;42 static int w = 0;43 static int h = 0;44 static double s = 0;45 46 public static void main(String[] args) throws IOException {47 Context context;48 S57map map = null;49 BufferedReader in;50 int line = 0;51 String format = "";52 String file = "";53 String k = "";54 String v = "";55 56 BufferedImage img;57 Graphics2D g2;58 boolean inIcons = false;59 boolean inIcon = false;60 61 if (args.length < 2) {62 System.err.println("Usage: java -jar jicons.jar icon_definition_file icons_directory");63 System.exit(-1);64 }65 in = new BufferedReader(new FileReader(args[0]));66 67 context = new Context();68 String ln;69 while ((ln = in.readLine()) != null) {70 line++;71 if (inIcons) {72 if (inIcon) {73 if (ln.contains("</icon")) {74 inIcon = false;75 map.tagsDone(0);76 // generate icon file77 switch (format) {78 case "PNG":79 img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);80 g2 = img.createGraphics();81 Renderer.reRender(g2, new Rectangle(x, y, w, h), 16, s / Renderer.symbolScale[16], map, context);82 try {83 ImageIO.write(img, "png", new File(args[1] + file + ".png"));84 } catch (Exception e) {85 System.err.println("Line " + line + ": PNG write Exception");86 }87 System.err.println(file + ".png");88 break;89 case "SVG":90 DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();91 String svgNS = "http://www.w3.org/2000/svg";92 Document document = domImpl.createDocument(svgNS, "svg", null);93 SVGGraphics2D svgGenerator = new SVGGraphics2D(document);94 svgGenerator.setSVGCanvasSize(new Dimension(w, h));95 Renderer.reRender(svgGenerator, new Rectangle(x, y, w, h), 16, s / Renderer.symbolScale[16], map, context);96 boolean useCSS = true;97 Writer out = null;98 try {99 out = new OutputStreamWriter(new FileOutputStream(args[1] + file + ".svg"), "UTF-8");100 } catch (IOException e1) {101 System.err.println("Line " + line + ": SVG file Exception");102 }103 try {104 svgGenerator.stream(out, useCSS);105 } catch (SVGGraphics2DIOException e) {106 System.err.println("Line " + line + ": SVG write Exception");107 }108 System.err.println(file + ".svg");109 break;110 }111 } else if (ln.contains("<tag")) {112 k = v = "";113 String[] token = ln.split("k=");114 k = token[1].split("[\"\']")[1];115 token = token[1].split("v=");116 v = token[1].split("[\"\']")[1];117 if (k.isEmpty()) {118 System.err.println("Line " + line + ": No key in tag");119 System.exit(-1);120 }121 if (v.isEmpty()) {122 System.err.println("Line " + line + ": No value in tag");123 System.exit(-1);124 }125 map.addTag(k, v);126 }127 } else if (ln.contains("<icon")) {128 inIcon = true;129 h = w = x = y = -1;130 s = 0;131 file = format = "";132 map = new S57map(true);133 map.addNode(0, 0, 0);134 for (String token : ln.split("[ ]+")) {135 if (token.matches("^width=.+")) {136 w = Integer.parseInt(token.split("[\"\']")[1]);137 } else if (token.matches("^height=.+")) {138 h = Integer.parseInt(token.split("[\"\']")[1]);139 } else if (token.matches("^x=.+")) {140 x = Integer.parseInt(token.split("[\"\']")[1]);141 } else if (token.matches("^y=.+")) {142 y = Integer.parseInt(token.split("[\"\']")[1]);143 } else if (token.matches("^scale=.+")) {144 s = Double.parseDouble(token.split("[\"\']")[1]);145 } else if (token.matches("^file=.+")) {146 file = (token.split("[\"\']")[1]);147 } else if (token.matches("^format=.+")) {148 format = (token.split("[\"\']")[1]);149 }150 }151 if (file.isEmpty()) {152 System.err.println("Line " + line + ": No filename");153 System.exit(-1);154 }155 if (format.isEmpty()) {156 System.err.println("Line " + line + ": No format");157 System.exit(-1);158 }159 if ((h < 0) && (w < 0)) {160 System.err.println("Line " + line + ": No icon size");161 System.exit(-1);162 }163 if (w < 0) {164 w = h;165 }166 if (h < 0) {167 h = w;168 }169 if (x < 0) {170 x = w / 2;171 }172 if (y < 0) {173 y = h / 2;174 }175 if (s == 0) {176 s = 1;177 }178 } else if (ln.contains("</icons")) {179 inIcons = false;180 break;181 }182 } else if (ln.contains("<icons")) {183 inIcons = true;184 }185 }186 in.close();187 System.err.println("Finished");188 System.exit(0);189 }190 191 static class Context implements ChartContext {192 193 public Point2D getPoint(Snode coord) {194 return new Point2D.Double(x, y);195 }196 197 public double mile(Feature feature) {198 return Math.min(w, h);199 }200 201 public boolean clip() {202 return false;203 }204 205 public Color background(S57map map) {206 return new Color(0, true);207 }208 209 public RuleSet ruleset() {210 return RuleSet.ALL;211 }212 }39 40 static int x = 0; 41 static int y = 0; 42 static int w = 0; 43 static int h = 0; 44 static double s = 0; 45 46 public static void main(String[] args) throws IOException { 47 Context context; 48 S57map map = null; 49 BufferedReader in; 50 int line = 0; 51 String format = ""; 52 String file = ""; 53 String k = ""; 54 String v = ""; 55 56 BufferedImage img; 57 Graphics2D g2; 58 boolean inIcons = false; 59 boolean inIcon = false; 60 61 if (args.length < 2) { 62 System.err.println("Usage: java -jar jicons.jar icon_definition_file icons_directory"); 63 System.exit(-1); 64 } 65 in = new BufferedReader(new FileReader(args[0])); 66 67 context = new Context(); 68 String ln; 69 while ((ln = in.readLine()) != null) { 70 line++; 71 if (inIcons) { 72 if (inIcon) { 73 if (ln.contains("</icon")) { 74 inIcon = false; 75 map.tagsDone(0); 76 // generate icon file 77 switch (format) { 78 case "PNG": 79 img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); 80 g2 = img.createGraphics(); 81 Renderer.reRender(g2, new Rectangle(x, y, w, h), 16, s / Renderer.symbolScale[16], map, context); 82 try { 83 ImageIO.write(img, "png", new File(args[1] + file + ".png")); 84 } catch (Exception e) { 85 System.err.println("Line " + line + ": PNG write Exception"); 86 } 87 System.err.println(file + ".png"); 88 break; 89 case "SVG": 90 DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation(); 91 String svgNS = "http://www.w3.org/2000/svg"; 92 Document document = domImpl.createDocument(svgNS, "svg", null); 93 SVGGraphics2D svgGenerator = new SVGGraphics2D(document); 94 svgGenerator.setSVGCanvasSize(new Dimension(w, h)); 95 Renderer.reRender(svgGenerator, new Rectangle(x, y, w, h), 16, s / Renderer.symbolScale[16], map, context); 96 boolean useCSS = true; 97 Writer out = null; 98 try { 99 out = new OutputStreamWriter(new FileOutputStream(args[1] + file + ".svg"), "UTF-8"); 100 } catch (IOException e1) { 101 System.err.println("Line " + line + ": SVG file Exception"); 102 } 103 try { 104 svgGenerator.stream(out, useCSS); 105 } catch (SVGGraphics2DIOException e) { 106 System.err.println("Line " + line + ": SVG write Exception"); 107 } 108 System.err.println(file + ".svg"); 109 break; 110 } 111 } else if (ln.contains("<tag")) { 112 k = v = ""; 113 String[] token = ln.split("k="); 114 k = token[1].split("[\"\']")[1]; 115 token = token[1].split("v="); 116 v = token[1].split("[\"\']")[1]; 117 if (k.isEmpty()) { 118 System.err.println("Line " + line + ": No key in tag"); 119 System.exit(-1); 120 } 121 if (v.isEmpty()) { 122 System.err.println("Line " + line + ": No value in tag"); 123 System.exit(-1); 124 } 125 map.addTag(k, v); 126 } 127 } else if (ln.contains("<icon")) { 128 inIcon = true; 129 h = w = x = y = -1; 130 s = 0; 131 file = format = ""; 132 map = new S57map(true); 133 map.addNode(0, 0, 0); 134 for (String token : ln.split("[ ]+")) { 135 if (token.matches("^width=.+")) { 136 w = Integer.parseInt(token.split("[\"\']")[1]); 137 } else if (token.matches("^height=.+")) { 138 h = Integer.parseInt(token.split("[\"\']")[1]); 139 } else if (token.matches("^x=.+")) { 140 x = Integer.parseInt(token.split("[\"\']")[1]); 141 } else if (token.matches("^y=.+")) { 142 y = Integer.parseInt(token.split("[\"\']")[1]); 143 } else if (token.matches("^scale=.+")) { 144 s = Double.parseDouble(token.split("[\"\']")[1]); 145 } else if (token.matches("^file=.+")) { 146 file = (token.split("[\"\']")[1]); 147 } else if (token.matches("^format=.+")) { 148 format = (token.split("[\"\']")[1]); 149 } 150 } 151 if (file.isEmpty()) { 152 System.err.println("Line " + line + ": No filename"); 153 System.exit(-1); 154 } 155 if (format.isEmpty()) { 156 System.err.println("Line " + line + ": No format"); 157 System.exit(-1); 158 } 159 if ((h < 0) && (w < 0)) { 160 System.err.println("Line " + line + ": No icon size"); 161 System.exit(-1); 162 } 163 if (w < 0) { 164 w = h; 165 } 166 if (h < 0) { 167 h = w; 168 } 169 if (x < 0) { 170 x = w / 2; 171 } 172 if (y < 0) { 173 y = h / 2; 174 } 175 if (s == 0) { 176 s = 1; 177 } 178 } else if (ln.contains("</icons")) { 179 inIcons = false; 180 break; 181 } 182 } else if (ln.contains("<icons")) { 183 inIcons = true; 184 } 185 } 186 in.close(); 187 System.err.println("Finished"); 188 System.exit(0); 189 } 190 191 static class Context implements ChartContext { 192 193 public Point2D getPoint(Snode coord) { 194 return new Point2D.Double(x, y); 195 } 196 197 public double mile(Feature feature) { 198 return Math.min(w, h); 199 } 200 201 public boolean clip() { 202 return false; 203 } 204 205 public Color background(S57map map) { 206 return new Color(0, true); 207 } 208 209 public RuleSet ruleset() { 210 return RuleSet.ALL; 211 } 212 } 213 213 } -
TabularUnified applications/editors/josm/plugins/seachart/josmtos57/src/josmtos57/Josmtos57.java ¶
r32380 r32906 22 22 public class Josmtos57 { 23 23 24 // http://opendatacommons.org/licenses/odbl/1-0/25 26 /*27 URL website = new URL("http://www.website.com/information.asp");28 try (InputStream in = website.openStream()) { Files.copy(in, target, StandardCopyOption.REPLACE_EXISTING); }29 */30 31 /*32 * To do:33 * 1. Geometry truncation at cell boundary.34 * 2. Geometry validation/correction to comply with S57 limitations.35 * 3. Improvements in mapping of OSM features to S57 objects.36 */24 // http://opendatacommons.org/licenses/odbl/1-0/ 25 26 /* 27 URL website = new URL("http://www.website.com/information.asp"); 28 try (InputStream in = website.openStream()) { Files.copy(in, target, StandardCopyOption.REPLACE_EXISTING); } 29 */ 30 31 /* 32 * To do: 33 * 1. Geometry truncation at cell boundary. 34 * 2. Geometry validation/correction to comply with S57 limitations. 35 * 3. Improvements in mapping of OSM features to S57 objects. 36 */ 37 37 38 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, 0x1e52 };53 54 static BufferedReader in;55 static FileOutputStream out;56 static S57map map;57 static byte[] buf;58 static HashMap<String, String> meta;59 static ArrayList<Fparams> fields;60 static byte[] record;61 62 public static void main(String[] args) throws IOException {38 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 52 }; 53 54 static BufferedReader in; 55 static FileOutputStream out; 56 static S57map map; 57 static byte[] buf; 58 static HashMap<String, String> meta; 59 static ArrayList<Fparams> fields; 60 static byte[] record; 61 62 public static void main(String[] args) throws IOException { 63 63 64 map = new S57map(false);65 int idx = 0;66 67 if (args.length < 4) {68 System.err.println("Usage: java -jar josmtos57.jar OSM_filename meta_data_filename S57_ENC_ROOT_directory S57_filename");69 System.exit(-1);70 }71 try {72 Scanner min = new Scanner(new FileInputStream(args[1]));73 meta = new HashMap<>();74 meta.put("FILE", args[3]);75 while (min.hasNext()) {76 String[] tokens = min.next().split("=");77 if (tokens.length >= 2)78 meta.put(tokens[0], tokens[1].split("[ #]")[0]);79 }80 min.close();81 } catch (IOException e) {82 System.err.println("Meta data file: " + e.getMessage());83 System.exit(-1);84 }85 try {86 in = new BufferedReader(new FileReader(new File(args[0])));87 try {88 S57osm.OSMmap(in, map, false);89 } catch (Exception e) {90 System.err.println("Input data error");91 System.exit(-1);92 }93 in.close();94 } catch (IOException e) {95 System.err.println("Input file: " + e.getMessage());96 System.exit(-1);97 }98 99 try {100 buf = new byte[5242880];101 idx = S57enc.encodeChart(map, meta, buf);102 } catch (IndexOutOfBoundsException e) {103 System.err.println("Output file too big (limit 5 MB) - try smaller areas");104 System.exit(-1);105 } catch (UnsupportedEncodingException e) {106 System.err.println("Input data error" + e.getMessage());107 System.exit(-1);108 }109 110 CRC32 crc = new CRC32();111 crc.update(buf, 0, idx);112 try {113 File file = new File(args[2] + args[3]);114 if (file.exists()) file.delete();115 out = new FileOutputStream(file, false);116 out.write(buf, 0, idx);117 } catch (IOException e) {118 System.err.println("Output file: " + e.getMessage());119 System.exit(-1);120 }121 out.close();122 123 buf = new byte[header.length];124 System.arraycopy(header, 0, buf, 0, header.length);125 idx = header.length;126 int recs = 2;127 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()), "" }));130 record = S57dat.encRecord(String.valueOf(recs++), fields);131 buf = Arrays.copyOf(buf, (buf.length + record.length));132 System.arraycopy(record, 0, buf, idx, record.length);133 idx += record.length;64 map = new S57map(false); 65 int idx = 0; 66 67 if (args.length < 4) { 68 System.err.println("Usage: java -jar josmtos57.jar OSM_filename meta_data_filename S57_ENC_ROOT_directory S57_filename"); 69 System.exit(-1); 70 } 71 try { 72 Scanner min = new Scanner(new FileInputStream(args[1])); 73 meta = new HashMap<>(); 74 meta.put("FILE", args[3]); 75 while (min.hasNext()) { 76 String[] tokens = min.next().split("="); 77 if (tokens.length >= 2) 78 meta.put(tokens[0], tokens[1].split("[ #]")[0]); 79 } 80 min.close(); 81 } catch (IOException e) { 82 System.err.println("Meta data file: " + e.getMessage()); 83 System.exit(-1); 84 } 85 try { 86 in = new BufferedReader(new FileReader(new File(args[0]))); 87 try { 88 S57osm.OSMmap(in, map, false); 89 } catch (Exception e) { 90 System.err.println("Input data error"); 91 System.exit(-1); 92 } 93 in.close(); 94 } catch (IOException e) { 95 System.err.println("Input file: " + e.getMessage()); 96 System.exit(-1); 97 } 98 99 try { 100 buf = new byte[5242880]; 101 idx = S57enc.encodeChart(map, meta, buf); 102 } catch (IndexOutOfBoundsException e) { 103 System.err.println("Output file too big (limit 5 MB) - try smaller areas"); 104 System.exit(-1); 105 } catch (UnsupportedEncodingException e) { 106 System.err.println("Input data error" + e.getMessage()); 107 System.exit(-1); 108 } 109 110 CRC32 crc = new CRC32(); 111 crc.update(buf, 0, idx); 112 try { 113 File file = new File(args[2] + args[3]); 114 if (file.exists()) file.delete(); 115 out = new FileOutputStream(file, false); 116 out.write(buf, 0, idx); 117 } catch (IOException e) { 118 System.err.println("Output file: " + e.getMessage()); 119 System.exit(-1); 120 } 121 out.close(); 122 123 buf = new byte[header.length]; 124 System.arraycopy(header, 0, buf, 0, header.length); 125 idx = header.length; 126 int recs = 2; 127 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()), "" })); 130 record = S57dat.encRecord(String.valueOf(recs++), fields); 131 buf = Arrays.copyOf(buf, (buf.length + record.length)); 132 System.arraycopy(record, 0, buf, idx, record.length); 133 idx += record.length; 134 134 135 try {136 File file = new File(args[2] + "CATALOG.031");137 if (file.exists()) file.delete();138 out = new FileOutputStream(file, false);139 out.write(buf, 0, idx);140 } catch (IOException e) {141 System.err.println("Catalogue file: " + e.getMessage());142 System.exit(-1);143 }144 out.close();135 try { 136 File file = new File(args[2] + "CATALOG.031"); 137 if (file.exists()) file.delete(); 138 out = new FileOutputStream(file, false); 139 out.write(buf, 0, idx); 140 } catch (IOException e) { 141 System.err.println("Catalogue file: " + e.getMessage()); 142 System.exit(-1); 143 } 144 out.close(); 145 145 146 // String[] dir = (new File(args[2]).list());147 // for (String item : dir) {148 // System.err.println(item);149 // }150 151 System.err.println("Finished");152 }146 // String[] dir = (new File(args[2]).list()); 147 // for (String item : dir) { 148 // System.err.println(item); 149 // } 150 151 System.err.println("Finished"); 152 } 153 153 154 154 } -
TabularUnified applications/editors/josm/plugins/seachart/jplotter/src/jplotter/Jplotter.java ¶
r30894 r32906 6 6 public class Jplotter { 7 7 8 public static void main(String[] args) {9 JFrame frame = new JFrame("Chart Plotter");10 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);11 frame.setLayout(null);12 Container c = frame.getContentPane();8 public static void main(String[] args) { 9 JFrame frame = new JFrame("Chart Plotter"); 10 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 11 frame.setLayout(null); 12 Container c = frame.getContentPane(); 13 13 14 JPanel map = new JPanel(new BorderLayout());15 map.setSize(600, 600);16 map.setLocation(50, 35);17 map.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder()));18 map.setLayout(null);19 map.setVisible(true);20 c.add(map);14 JPanel map = new JPanel(new BorderLayout()); 15 map.setSize(600, 600); 16 map.setLocation(50, 35); 17 map.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder())); 18 map.setLayout(null); 19 map.setVisible(true); 20 c.add(map); 21 21 22 frame.setSize(700, 700);23 frame.setVisible(true);24 }22 frame.setSize(700, 700); 23 frame.setVisible(true); 24 } 25 25 } -
TabularUnified applications/editors/josm/plugins/seachart/jrender/src/jrender/Jrender.java ¶
r32393 r32906 34 34 public class Jrender { 35 35 36 static String srcdir;37 static String dstdir;38 static int xtile;39 static int ytile;40 static int zoom;41 static ArrayList<String> send;42 static HashMap<String, Boolean> deletes;43 static Context context;44 static S57map map;45 static int empty;36 static String srcdir; 37 static String dstdir; 38 static int xtile; 39 static int ytile; 40 static int zoom; 41 static ArrayList<String> send; 42 static HashMap<String, Boolean> deletes; 43 static Context context; 44 static S57map map; 45 static int empty; 46 46 47 static class Context implements ChartContext {48 49 static double top;50 static double mile;51 52 public Context () {53 top = (1.0 - Math.log(Math.tan(map.bounds.maxlat) + 1.0 / Math.cos(map.bounds.maxlat)) / Math.PI) / 2.0 * 256.0 * 4096.0 * Math.pow(2, (zoom - 12));54 mile = (2 * ((zoom < 12) ? (256 / (int)(Math.pow(2, (11 - zoom)))) : 256) + 256) / ((Math.toDegrees(map.bounds.maxlat) - Math.toDegrees(map.bounds.minlat)) * 60);55 }56 57 public Point2D getPoint(Snode coord) {58 double x = (Math.toDegrees(coord.lon) - Math.toDegrees(map.bounds.minlon)) * 256.0 * 2048.0 * Math.pow(2, (zoom - 12)) / 180.0;59 double y = ((1.0 - Math.log(Math.tan(coord.lat) + 1.0 / Math.cos(coord.lat)) / Math.PI) / 2.0 * 256.0 * 4096.0 * Math.pow(2, (zoom - 12))) - top;60 return new Point2D.Double(x, y);61 }47 static class Context implements ChartContext { 48 49 static double top; 50 static double mile; 51 52 public Context () { 53 top = (1.0 - Math.log(Math.tan(map.bounds.maxlat) + 1.0 / Math.cos(map.bounds.maxlat)) / Math.PI) / 2.0 * 256.0 * 4096.0 * Math.pow(2, (zoom - 12)); 54 mile = (2 * ((zoom < 12) ? (256 / (int)(Math.pow(2, (11 - zoom)))) : 256) + 256) / ((Math.toDegrees(map.bounds.maxlat) - Math.toDegrees(map.bounds.minlat)) * 60); 55 } 56 57 public Point2D getPoint(Snode coord) { 58 double x = (Math.toDegrees(coord.lon) - Math.toDegrees(map.bounds.minlon)) * 256.0 * 2048.0 * Math.pow(2, (zoom - 12)) / 180.0; 59 double y = ((1.0 - Math.log(Math.tan(coord.lat) + 1.0 / Math.cos(coord.lat)) / Math.PI) / 2.0 * 256.0 * 4096.0 * Math.pow(2, (zoom - 12))) - top; 60 return new Point2D.Double(x, y); 61 } 62 62 63 public double mile(Feature feature) {64 return mile;65 }63 public double mile(Feature feature) { 64 return mile; 65 } 66 66 67 public boolean clip() {68 return false;69 }67 public boolean clip() { 68 return false; 69 } 70 70 71 public Color background(S57map map) {72 return new Color(0, true);73 }71 public Color background(S57map map) { 72 return new Color(0, true); 73 } 74 74 75 public RuleSet ruleset() {76 return RuleSet.SEAMARK;77 }78 }79 80 static void tile(int z, int s, int xn, int yn) throws IOException {81 int border = (z < 12) ? (256 / (int)(Math.pow(2, (11 - zoom)))) : 256;82 int scale = (int)Math.pow(2, z - 12);83 int xdir = (scale > 0) ? (scale * xtile) + xn : xtile;84 int ynam = (scale > 0) ? (scale * ytile) + yn : ytile;85 BufferedImage img = new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB);86 Graphics2D g2 = img.createGraphics();87 g2.scale(s, s);88 g2.translate(-(border + (xn * 256 / s)), -(border + (yn * 256 / s)));89 Renderer.reRender(g2, new Rectangle(256, 256), z, 1.0 * Math.pow(2, (zoom - 12)), map, context);90 ByteArrayOutputStream bos = new ByteArrayOutputStream();91 ImageIO.write(img, "png", bos);92 if (bos.size() > empty) {93 String dstnam = dstdir + z + "/" + xdir + "/" + ynam + ".png";94 deletes.remove(dstnam);95 send.add("put " + dstnam + " tiles/" + z + "/" + xdir + "/" + ynam + ".png");96 File ofile = new File(dstdir + "/" + z + "/" + xdir + "/");97 ofile.mkdirs();98 FileOutputStream fos = new FileOutputStream(dstdir + "/" + z + "/" + xdir + "/" + ynam + ".png");99 bos.writeTo(fos);100 fos.close();101 if (send.size() > 20) {102 PrintWriter writer = new PrintWriter(srcdir + z + "-" + xdir + "-" + ynam + ".send", "UTF-8");103 for (String str : send) {104 writer.println(str);105 }106 writer.close();107 send = new ArrayList<>();108 }109 }110 if ((z >= 12) && (z < 18) && ((z < 16) || (bos.size() > empty))) {111 for (int x = 0; x < 2; x++) {112 for (int y = 0; y < 2; y++) {113 tile((z + 1), (s * 2), (xn * 2 + x), (yn * 2 + y));114 }115 }116 }117 }118 119 static void clean(int z, int xn, int yn) throws Exception {120 int scale = (int) Math.pow(2, z - 12);121 int xdir = (scale * xtile) + xn;122 int ynam = (scale * ytile) + yn;123 String delnam = dstdir + z + "/" + xdir + "/" + ynam + ".png";124 File delfile = new File(delnam);125 if (delfile.exists()) {126 deletes.put(delnam, true);127 delfile.delete();128 }129 if ((z < 18)) {130 for (int x = 0; x < 2; x++) {131 for (int y = 0; y < 2; y++) {132 clean((z + 1), (xn * 2 + x), (yn * 2 + y));133 }134 }135 }136 }137 138 public static void main(String[] args) throws Exception {139 if (args.length < 5) {140 System.err.println("Usage: java -jar jrender.jar <osm source directory> <tile directory> <zoom> <xtile> <ytile>");141 System.exit(-1);142 }143 srcdir = args[0];144 dstdir = args[1];145 zoom = Integer.parseInt(args[2]);146 xtile = Integer.parseInt(args[3]);147 ytile = Integer.parseInt(args[4]);148 send = new ArrayList<>();149 deletes = new HashMap<>();150 BufferedReader in = new BufferedReader(new FileReader(srcdir + xtile + "-" + ytile + "-" + zoom + ".osm"));151 map = new S57map(true);152 S57osm.OSMmap(in, map, false);153 in.close();154 context = new Context();155 ByteArrayOutputStream bos = new ByteArrayOutputStream();156 ImageIO.write(new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB), "png", bos);157 empty = bos.size();158 if (zoom == 12) {159 clean(12, 0, 0);160 }161 tile(zoom, 1, 0, 0);162 if (send.size() > 0) {163 PrintWriter writer = new PrintWriter(srcdir + zoom + "-" + xtile + "-" + ytile + ".send", "UTF-8");164 for (String str : send) {165 writer.println(str);166 }167 writer.close();168 }169 if (deletes.size() > 0) {170 PrintWriter writer = new PrintWriter(srcdir + zoom + "-" + xtile + "-" + ytile + ".delete", "UTF-8");171 for (String del : deletes.keySet()) {172 writer.println("rm " + del);173 }174 writer.close();175 }176 System.exit(0);177 }75 public RuleSet ruleset() { 76 return RuleSet.SEAMARK; 77 } 78 } 79 80 static void tile(int z, int s, int xn, int yn) throws IOException { 81 int border = (z < 12) ? (256 / (int)(Math.pow(2, (11 - zoom)))) : 256; 82 int scale = (int)Math.pow(2, z - 12); 83 int xdir = (scale > 0) ? (scale * xtile) + xn : xtile; 84 int ynam = (scale > 0) ? (scale * ytile) + yn : ytile; 85 BufferedImage img = new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB); 86 Graphics2D g2 = img.createGraphics(); 87 g2.scale(s, s); 88 g2.translate(-(border + (xn * 256 / s)), -(border + (yn * 256 / s))); 89 Renderer.reRender(g2, new Rectangle(256, 256), z, 1.0 * Math.pow(2, (zoom - 12)), map, context); 90 ByteArrayOutputStream bos = new ByteArrayOutputStream(); 91 ImageIO.write(img, "png", bos); 92 if (bos.size() > empty) { 93 String dstnam = dstdir + z + "/" + xdir + "/" + ynam + ".png"; 94 deletes.remove(dstnam); 95 send.add("put " + dstnam + " tiles/" + z + "/" + xdir + "/" + ynam + ".png"); 96 File ofile = new File(dstdir + "/" + z + "/" + xdir + "/"); 97 ofile.mkdirs(); 98 FileOutputStream fos = new FileOutputStream(dstdir + "/" + z + "/" + xdir + "/" + ynam + ".png"); 99 bos.writeTo(fos); 100 fos.close(); 101 if (send.size() > 20) { 102 PrintWriter writer = new PrintWriter(srcdir + z + "-" + xdir + "-" + ynam + ".send", "UTF-8"); 103 for (String str : send) { 104 writer.println(str); 105 } 106 writer.close(); 107 send = new ArrayList<>(); 108 } 109 } 110 if ((z >= 12) && (z < 18) && ((z < 16) || (bos.size() > empty))) { 111 for (int x = 0; x < 2; x++) { 112 for (int y = 0; y < 2; y++) { 113 tile((z + 1), (s * 2), (xn * 2 + x), (yn * 2 + y)); 114 } 115 } 116 } 117 } 118 119 static void clean(int z, int xn, int yn) throws Exception { 120 int scale = (int) Math.pow(2, z - 12); 121 int xdir = (scale * xtile) + xn; 122 int ynam = (scale * ytile) + yn; 123 String delnam = dstdir + z + "/" + xdir + "/" + ynam + ".png"; 124 File delfile = new File(delnam); 125 if (delfile.exists()) { 126 deletes.put(delnam, true); 127 delfile.delete(); 128 } 129 if ((z < 18)) { 130 for (int x = 0; x < 2; x++) { 131 for (int y = 0; y < 2; y++) { 132 clean((z + 1), (xn * 2 + x), (yn * 2 + y)); 133 } 134 } 135 } 136 } 137 138 public static void main(String[] args) throws Exception { 139 if (args.length < 5) { 140 System.err.println("Usage: java -jar jrender.jar <osm source directory> <tile directory> <zoom> <xtile> <ytile>"); 141 System.exit(-1); 142 } 143 srcdir = args[0]; 144 dstdir = args[1]; 145 zoom = Integer.parseInt(args[2]); 146 xtile = Integer.parseInt(args[3]); 147 ytile = Integer.parseInt(args[4]); 148 send = new ArrayList<>(); 149 deletes = new HashMap<>(); 150 BufferedReader in = new BufferedReader(new FileReader(srcdir + xtile + "-" + ytile + "-" + zoom + ".osm")); 151 map = new S57map(true); 152 S57osm.OSMmap(in, map, false); 153 in.close(); 154 context = new Context(); 155 ByteArrayOutputStream bos = new ByteArrayOutputStream(); 156 ImageIO.write(new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB), "png", bos); 157 empty = bos.size(); 158 if (zoom == 12) { 159 clean(12, 0, 0); 160 } 161 tile(zoom, 1, 0, 0); 162 if (send.size() > 0) { 163 PrintWriter writer = new PrintWriter(srcdir + zoom + "-" + xtile + "-" + ytile + ".send", "UTF-8"); 164 for (String str : send) { 165 writer.println(str); 166 } 167 writer.close(); 168 } 169 if (deletes.size() > 0) { 170 PrintWriter writer = new PrintWriter(srcdir + zoom + "-" + xtile + "-" + ytile + ".delete", "UTF-8"); 171 for (String del : deletes.keySet()) { 172 writer.println("rm " + del); 173 } 174 writer.close(); 175 } 176 System.exit(0); 177 } 178 178 } -
TabularUnified applications/editors/josm/plugins/seachart/js57toosm/src/js57toosm/Js57toosm.java ¶
r32393 r32906 26 26 27 27 public class Js57toosm { 28 29 static FileInputStream in;30 static PrintStream out;31 static S57map map;32 static final ArrayList<Att> typatts = new ArrayList<>(); static {33 typatts.add(Att.OBJNAM); typatts.add(Att.NOBJNM); typatts.add(Att.STATUS); typatts.add(Att.INFORM); typatts.add(Att.NINFOM);34 typatts.add(Att.PEREND); typatts.add(Att.PERSTA); typatts.add(Att.CONDTN); typatts.add(Att.CONRAD); typatts.add(Att.CONVIS);35 }36 37 public static void main(String[] args) throws IOException {38 39 ArrayList<Long> done = new ArrayList<>();40 41 if (args.length < 3) {42 System.err.println("Usage: java -jar js57toosm.jar S57_filename types_filename OSM_filename");43 System.exit(-1);44 }45 try {46 in = new FileInputStream(args[0]);47 } catch (IOException e) {48 System.err.println("Input file: " + e.getMessage());49 System.exit(-1);50 }51 try {52 out = new PrintStream(args[2]);53 } catch (IOException e) {54 System.err.println("Output file: " + e.getMessage());55 in.close();56 System.exit(-1);57 }58 ArrayList<Obj> types = new ArrayList<>();59 try {60 Scanner tin = new Scanner(new FileInputStream(args[1]));61 while (tin.hasNext()) {62 Obj type = S57obj.enumType(tin.next());63 if (type != Obj.UNKOBJ)64 types.add(type);65 }66 tin.close();67 } catch (IOException e) {68 System.err.println("Types file: " + e.getMessage());69 in.close();70 out.close();71 System.exit(-1);72 }73 74 map = new S57map(true);75 S57dec.decodeChart(in, map);76 77 out.format("<?xml version='1.0' encoding='UTF-8'?>%n");78 out.format("<osm version='0.6' upload='false' generator='js57toosm'>%n");79 out.format("<bounds minlat='%.8f' minlon='%.8f' maxlat='%.8f' maxlon='%.8f'/>%n",80 Math.toDegrees(map.bounds.minlat), Math.toDegrees(map.bounds.minlon), Math.toDegrees(map.bounds.maxlat), Math.toDegrees(map.bounds.maxlon));81 82 for (long id : map.index.keySet()) {83 Feature feature = map.index.get(id);84 String type = S57obj.stringType(feature.type);85 if (!type.isEmpty() && (types.isEmpty() || types.contains(feature.type))) {86 if (feature.reln == Rflag.MASTER) {87 if (feature.geom.prim == Pflag.POINT) {88 for (Prim prim : feature.geom.elems) {89 long ref = prim.id;90 Snode node;91 while ((node = map.nodes.get(ref)) != null) {92 if (!done.contains(ref)) {93 out.format(" <node id='%d' lat='%.8f' lon='%.8f' version='1'>%n", -ref, Math.toDegrees(node.lat), Math.toDegrees(node.lon));94 out.format(" <tag k='seamark:type' v=\"%s\"/>%n", type);95 if ((feature.type == Obj.SOUNDG) && (node.flg == S57map.Nflag.DPTH))96 out.format(" <tag k='seamark:sounding:depth' v='%.1f'/>%n", ((Snode) node).val);97 writeAtts(feature);98 out.format(" </node>%n");99 done.add(ref);100 }101 ref++;102 }103 }104 }105 }106 }107 }108 for (long id : map.index.keySet()) {109 Feature feature = map.index.get(id);110 String type = S57obj.stringType(feature.type);111 if (!type.isEmpty() && (types.isEmpty() || types.contains(feature.type))) {112 if (feature.reln == Rflag.MASTER) {113 if ((feature.geom.prim == Pflag.LINE) || ((feature.geom.prim == Pflag.AREA) && (feature.geom.outers == 1) && (feature.geom.inners == 0))) {114 GeomIterator git = map.new GeomIterator(feature.geom);115 while (git.hasComp()) {116 git.nextComp();117 while (git.hasEdge()) {118 git.nextEdge();119 while (git.hasNode()) {120 long ref = git.nextRef();121 Snode node = map.nodes.get(ref);122 if (!done.contains(ref)) {123 out.format(" <node id='%d' lat='%.8f' lon='%.8f' version='1'/>%n", -ref, Math.toDegrees(node.lat), Math.toDegrees(node.lon));124 done.add(ref);125 }126 }127 }128 }129 git = map.new GeomIterator(feature.geom);130 while (git.hasComp()) {131 long edge = git.nextComp();132 out.format(" <way id='%d' version='1'>%n", -edge);133 while (git.hasEdge()) {134 git.nextEdge();135 while (git.hasNode()) {136 long ref = git.nextRef();137 out.format(" <nd ref='%d'/>%n", -ref);138 }139 }140 out.format(" <tag k='seamark:type' v='%s'/>%n", type);141 writeAtts(feature);142 out.format(" </way>%n");143 }144 } else if (feature.geom.prim == Pflag.AREA) {145 GeomIterator git = map.new GeomIterator(feature.geom);146 while (git.hasComp()) {147 git.nextComp();148 while (git.hasEdge()) {149 git.nextEdge();150 while (git.hasNode()) {151 long ref = git.nextRef();152 Snode node = map.nodes.get(ref);153 if (!done.contains(ref)) {154 out.format(" <node id='%d' lat='%.8f' lon='%.8f' version='1'/>%n", -ref, Math.toDegrees(node.lat), Math.toDegrees(node.lon));155 done.add(ref);156 }157 }158 }159 }160 git = map.new GeomIterator(feature.geom);161 while (git.hasComp()) {162 long ref = git.nextComp();163 out.format(" <way id='%d' version='1'>%n", -ref);164 while (git.hasEdge()) {165 git.nextEdge();166 while (git.hasNode()) {167 ref = git.nextRef();168 out.format(" <nd ref='%d'/>%n", -ref);169 }170 }171 out.format(" </way>%n");172 }173 out.format(" <relation id='%d' version='1'>%n", -map.xref++);174 out.format(" <tag k='type' v='multipolygon'/>%n");175 git = map.new GeomIterator(feature.geom);176 int outers = feature.geom.outers;177 while (git.hasComp()) {178 long ref = git.nextComp();179 if (outers-- > 0) {180 out.format(" <member type='way' ref='%d' role='outer'/>%n", -ref);181 } else {182 out.format(" <member type='way' ref='%d' role='inner'/>%n", -ref);183 }184 }185 out.format(" <tag k='seamark:type' v='%s'/>%n", type);186 writeAtts(feature);187 out.format(" </relation>%n");188 }189 }190 }191 }192 out.println("</osm>\n");193 out.close();194 System.err.println("Finished");195 }196 197 static void writeAtts(Feature feature) {198 for (Map.Entry<Att, AttVal<?>> item : feature.atts.entrySet()) {199 String attstr = S57att.stringAttribute(item.getKey());200 String valstr = S57val.stringValue(item.getValue(), item.getKey());201 if (!attstr.isEmpty() && !valstr.isEmpty()) {202 if (typatts.contains(item.getKey())) {203 out.format(" <tag k='seamark:%s' v='%s'/>%n", attstr, StringEscapeUtils.escapeXml10(valstr));204 } else {205 out.format(" <tag k='seamark:%s:%s' v='%s'/>%n", S57obj.stringType(feature.type), attstr, StringEscapeUtils.escapeXml10(valstr));206 }207 }208 }209 for (Obj obj : feature.objs.keySet()) {210 ObjTab tab = feature.objs.get(obj);211 for (int ix : tab.keySet()) {212 AttMap atts = tab.get(ix);213 for (Map.Entry<Att, AttVal<?>> item : atts.entrySet()) {214 String attstr = S57att.stringAttribute(item.getKey());215 String valstr = S57val.stringValue(item.getValue(), item.getKey());216 if (!attstr.isEmpty() && !valstr.isEmpty()) {217 if ((ix == 0) && (tab.size() == 1)) {218 out.format(" <tag k='seamark:%s:%s' v='%s'/>%n", S57obj.stringType(obj), attstr, StringEscapeUtils.escapeXml10(valstr));219 } else {220 out.format(" <tag k='seamark:%s:%d:%s' v='%s'/>%n", S57obj.stringType(obj), ix + 1, attstr, StringEscapeUtils.escapeXml10(valstr));221 }222 }223 }224 }225 }226 }28 29 static FileInputStream in; 30 static PrintStream out; 31 static S57map map; 32 static final ArrayList<Att> typatts = new ArrayList<>(); static { 33 typatts.add(Att.OBJNAM); typatts.add(Att.NOBJNM); typatts.add(Att.STATUS); typatts.add(Att.INFORM); typatts.add(Att.NINFOM); 34 typatts.add(Att.PEREND); typatts.add(Att.PERSTA); typatts.add(Att.CONDTN); typatts.add(Att.CONRAD); typatts.add(Att.CONVIS); 35 } 36 37 public static void main(String[] args) throws IOException { 38 39 ArrayList<Long> done = new ArrayList<>(); 40 41 if (args.length < 3) { 42 System.err.println("Usage: java -jar js57toosm.jar S57_filename types_filename OSM_filename"); 43 System.exit(-1); 44 } 45 try { 46 in = new FileInputStream(args[0]); 47 } catch (IOException e) { 48 System.err.println("Input file: " + e.getMessage()); 49 System.exit(-1); 50 } 51 try { 52 out = new PrintStream(args[2]); 53 } catch (IOException e) { 54 System.err.println("Output file: " + e.getMessage()); 55 in.close(); 56 System.exit(-1); 57 } 58 ArrayList<Obj> types = new ArrayList<>(); 59 try { 60 Scanner tin = new Scanner(new FileInputStream(args[1])); 61 while (tin.hasNext()) { 62 Obj type = S57obj.enumType(tin.next()); 63 if (type != Obj.UNKOBJ) 64 types.add(type); 65 } 66 tin.close(); 67 } catch (IOException e) { 68 System.err.println("Types file: " + e.getMessage()); 69 in.close(); 70 out.close(); 71 System.exit(-1); 72 } 73 74 map = new S57map(true); 75 S57dec.decodeChart(in, map); 76 77 out.format("<?xml version='1.0' encoding='UTF-8'?>%n"); 78 out.format("<osm version='0.6' upload='false' generator='js57toosm'>%n"); 79 out.format("<bounds minlat='%.8f' minlon='%.8f' maxlat='%.8f' maxlon='%.8f'/>%n", 80 Math.toDegrees(map.bounds.minlat), Math.toDegrees(map.bounds.minlon), Math.toDegrees(map.bounds.maxlat), Math.toDegrees(map.bounds.maxlon)); 81 82 for (long id : map.index.keySet()) { 83 Feature feature = map.index.get(id); 84 String type = S57obj.stringType(feature.type); 85 if (!type.isEmpty() && (types.isEmpty() || types.contains(feature.type))) { 86 if (feature.reln == Rflag.MASTER) { 87 if (feature.geom.prim == Pflag.POINT) { 88 for (Prim prim : feature.geom.elems) { 89 long ref = prim.id; 90 Snode node; 91 while ((node = map.nodes.get(ref)) != null) { 92 if (!done.contains(ref)) { 93 out.format(" <node id='%d' lat='%.8f' lon='%.8f' version='1'>%n", -ref, Math.toDegrees(node.lat), Math.toDegrees(node.lon)); 94 out.format(" <tag k='seamark:type' v=\"%s\"/>%n", type); 95 if ((feature.type == Obj.SOUNDG) && (node.flg == S57map.Nflag.DPTH)) 96 out.format(" <tag k='seamark:sounding:depth' v='%.1f'/>%n", ((Snode) node).val); 97 writeAtts(feature); 98 out.format(" </node>%n"); 99 done.add(ref); 100 } 101 ref++; 102 } 103 } 104 } 105 } 106 } 107 } 108 for (long id : map.index.keySet()) { 109 Feature feature = map.index.get(id); 110 String type = S57obj.stringType(feature.type); 111 if (!type.isEmpty() && (types.isEmpty() || types.contains(feature.type))) { 112 if (feature.reln == Rflag.MASTER) { 113 if ((feature.geom.prim == Pflag.LINE) || ((feature.geom.prim == Pflag.AREA) && (feature.geom.outers == 1) && (feature.geom.inners == 0))) { 114 GeomIterator git = map.new GeomIterator(feature.geom); 115 while (git.hasComp()) { 116 git.nextComp(); 117 while (git.hasEdge()) { 118 git.nextEdge(); 119 while (git.hasNode()) { 120 long ref = git.nextRef(); 121 Snode node = map.nodes.get(ref); 122 if (!done.contains(ref)) { 123 out.format(" <node id='%d' lat='%.8f' lon='%.8f' version='1'/>%n", -ref, Math.toDegrees(node.lat), Math.toDegrees(node.lon)); 124 done.add(ref); 125 } 126 } 127 } 128 } 129 git = map.new GeomIterator(feature.geom); 130 while (git.hasComp()) { 131 long edge = git.nextComp(); 132 out.format(" <way id='%d' version='1'>%n", -edge); 133 while (git.hasEdge()) { 134 git.nextEdge(); 135 while (git.hasNode()) { 136 long ref = git.nextRef(); 137 out.format(" <nd ref='%d'/>%n", -ref); 138 } 139 } 140 out.format(" <tag k='seamark:type' v='%s'/>%n", type); 141 writeAtts(feature); 142 out.format(" </way>%n"); 143 } 144 } else if (feature.geom.prim == Pflag.AREA) { 145 GeomIterator git = map.new GeomIterator(feature.geom); 146 while (git.hasComp()) { 147 git.nextComp(); 148 while (git.hasEdge()) { 149 git.nextEdge(); 150 while (git.hasNode()) { 151 long ref = git.nextRef(); 152 Snode node = map.nodes.get(ref); 153 if (!done.contains(ref)) { 154 out.format(" <node id='%d' lat='%.8f' lon='%.8f' version='1'/>%n", -ref, Math.toDegrees(node.lat), Math.toDegrees(node.lon)); 155 done.add(ref); 156 } 157 } 158 } 159 } 160 git = map.new GeomIterator(feature.geom); 161 while (git.hasComp()) { 162 long ref = git.nextComp(); 163 out.format(" <way id='%d' version='1'>%n", -ref); 164 while (git.hasEdge()) { 165 git.nextEdge(); 166 while (git.hasNode()) { 167 ref = git.nextRef(); 168 out.format(" <nd ref='%d'/>%n", -ref); 169 } 170 } 171 out.format(" </way>%n"); 172 } 173 out.format(" <relation id='%d' version='1'>%n", -map.xref++); 174 out.format(" <tag k='type' v='multipolygon'/>%n"); 175 git = map.new GeomIterator(feature.geom); 176 int outers = feature.geom.outers; 177 while (git.hasComp()) { 178 long ref = git.nextComp(); 179 if (outers-- > 0) { 180 out.format(" <member type='way' ref='%d' role='outer'/>%n", -ref); 181 } else { 182 out.format(" <member type='way' ref='%d' role='inner'/>%n", -ref); 183 } 184 } 185 out.format(" <tag k='seamark:type' v='%s'/>%n", type); 186 writeAtts(feature); 187 out.format(" </relation>%n"); 188 } 189 } 190 } 191 } 192 out.println("</osm>\n"); 193 out.close(); 194 System.err.println("Finished"); 195 } 196 197 static void writeAtts(Feature feature) { 198 for (Map.Entry<Att, AttVal<?>> item : feature.atts.entrySet()) { 199 String attstr = S57att.stringAttribute(item.getKey()); 200 String valstr = S57val.stringValue(item.getValue(), item.getKey()); 201 if (!attstr.isEmpty() && !valstr.isEmpty()) { 202 if (typatts.contains(item.getKey())) { 203 out.format(" <tag k='seamark:%s' v='%s'/>%n", attstr, StringEscapeUtils.escapeXml10(valstr)); 204 } else { 205 out.format(" <tag k='seamark:%s:%s' v='%s'/>%n", S57obj.stringType(feature.type), attstr, StringEscapeUtils.escapeXml10(valstr)); 206 } 207 } 208 } 209 for (Obj obj : feature.objs.keySet()) { 210 ObjTab tab = feature.objs.get(obj); 211 for (int ix : tab.keySet()) { 212 AttMap atts = tab.get(ix); 213 for (Map.Entry<Att, AttVal<?>> item : atts.entrySet()) { 214 String attstr = S57att.stringAttribute(item.getKey()); 215 String valstr = S57val.stringValue(item.getValue(), item.getKey()); 216 if (!attstr.isEmpty() && !valstr.isEmpty()) { 217 if ((ix == 0) && (tab.size() == 1)) { 218 out.format(" <tag k='seamark:%s:%s' v='%s'/>%n", S57obj.stringType(obj), attstr, StringEscapeUtils.escapeXml10(valstr)); 219 } else { 220 out.format(" <tag k='seamark:%s:%d:%s' v='%s'/>%n", S57obj.stringType(obj), ix + 1, attstr, StringEscapeUtils.escapeXml10(valstr)); 221 } 222 } 223 } 224 } 225 } 226 } 227 227 228 228 }
Note:
See TracChangeset
for help on using the changeset viewer.
