Changeset 30402 in osm for applications/editors/josm
- Timestamp:
- 2014-04-16T11:25:57+02:00 (10 years ago)
- Location:
- applications/editors/josm/plugins/smed2
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/smed2/jicons/src/jicons/Jicons.java
r30398 r30402 37 37 public class Jicons { 38 38 39 static S57map map = null;40 39 static int x = 0; 41 40 static int y = 0; … … 45 44 46 45 public static void main(String[] args) throws IOException { 47 Render render; 46 Context context; 47 S57map map = null; 48 48 BufferedReader in; 49 49 int line = 0; … … 64 64 in = new BufferedReader(new FileReader(args[0])); 65 65 66 render = new Render();66 context = new Context(); 67 67 String ln; 68 68 while ((ln = in.readLine()) != null) { … … 78 78 img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); 79 79 g2 = img.createGraphics(); 80 render.drawRendering(g2, s);80 Renderer.reRender(g2, 16, s / Renderer.symbolScale[16], map, context); 81 81 try { 82 82 ImageIO.write(img, "png", new File(args[1] + file + ".png")); … … 92 92 SVGGraphics2D svgGenerator = new SVGGraphics2D(document); 93 93 svgGenerator.setSVGCanvasSize(new Dimension(w, h)); 94 render.drawRendering(svgGenerator, s);94 Renderer.reRender(svgGenerator, 16, s / Renderer.symbolScale[16], map, context); 95 95 boolean useCSS = true; 96 96 Writer out = null; … … 188 188 } 189 189 190 static class Renderimplements MapContext {190 static class Context implements MapContext { 191 191 192 public void drawRendering(Graphics2D g2, double scale) {193 Renderer.reRender(g2, 16, scale / Renderer.symbolScale[16], map, this);194 }195 196 192 @Override 197 193 public Point2D getPoint(Snode coord) { … … 201 197 @Override 202 198 public double mile(Feature feature) { 203 return 1000;199 return Math.min(w, h); 204 200 } 205 201 } -
applications/editors/josm/plugins/smed2/jrender/src/jrender/Jrender.java
r30398 r30402 1 /* Copyright 201 2Malcolm Herring1 /* Copyright 2014 Malcolm Herring 2 2 * 3 3 * This is free software: you can redistribute it and/or modify … … 10 10 package jrender; 11 11 12 import java.awt.Dimension;13 import java.awt.Graphics2D;14 import java.awt.geom.Point2D;15 import java.awt.image.BufferedImage;16 import java.io.BufferedOutputStream;17 import java.io.BufferedReader;18 import java.io.ByteArrayOutputStream;19 import java.io.File;20 import java.io.FileOutputStream;21 import java.io.FileReader;22 12 import java.io.IOException; 23 import java.io.OutputStream;24 import java.io.OutputStreamWriter;25 import java.io.Writer;26 import java.util.zip.GZIPOutputStream;27 28 import javax.imageio.ImageIO;29 30 import org.apache.batik.dom.GenericDOMImplementation;31 import org.apache.batik.svggen.SVGGraphics2D;32 import org.w3c.dom.DOMImplementation;33 import org.w3c.dom.Document;34 35 import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream;36 37 import s57.S57map;38 import s57.S57map.Feature;39 import s57.S57map.Snode;40 import render.*;41 13 42 14 public class Jrender { 43 15 44 static S57map map = null; 45 static double minlat = 0; 46 static double minlon = 0; 47 static double maxlat = 0; 48 static double maxlon = 0; 49 static double top = 0; 50 static double mile = 0; 51 16 public static class MapBB { 17 public double minlat; 18 public double minlon; 19 public double maxlat; 20 public double maxlon; 21 public MapBB(double nt, double nn, double xt, double xn) { 22 minlat = nt; 23 minlon = nn; 24 maxlat = xt; 25 maxlon = xn; 26 } 27 } 28 52 29 public static void main(String[] args) throws IOException { 53 Render render;54 BufferedReader in;55 String k = "";56 String v = "";57 58 double lat = 0;59 double lon = 0;60 long id = 0;61 62 BufferedImage img;63 Graphics2D g2;64 boolean inOsm = false;65 boolean inNode = false;66 boolean inWay = false;67 boolean inRel = false;68 69 30 if (args.length < 5) { 70 31 System.err.println("Usage: java -jar jrender.jar osm_file minlat, minlon, maxlat, maxlon"); 71 32 System.exit(-1); 72 33 } 73 in = new BufferedReader(new FileReader(args[0]));74 minlat = Double.parseDouble(args[1]);75 minlon = Double.parseDouble(args[2]);76 maxlat = Double.parseDouble(args[3]);77 maxlon = Double.parseDouble(args[4]);78 top = (1.0 - Math.log(Math.tan(Math.toRadians(maxlat)) + 1.0 / Math.cos(Math.toRadians(maxlat))) / Math.PI) / 2.0 * 256.0 * 4096.0;79 mile = 768 / ((maxlat - minlat) * 60);80 34 81 render = new Render(); 82 String ln; 83 while ((ln = in.readLine()) != null) { 84 if (inOsm) { 85 if ((inNode || inWay || inRel) && (ln.contains("<tag"))) { 86 k = v = ""; 87 String[] token = ln.split("k="); 88 k = token[1].split("[\"\']")[1]; 89 token = token[1].split("v="); 90 v = token[1].split("[\"\']")[1]; 91 if (!k.isEmpty() && !v.isEmpty()) { 92 map.addTag(k, v); 93 } 94 } 95 if (inNode) { 96 if (ln.contains("</node")) { 97 inNode = false; 98 map.tagsDone(id); 99 } 100 } else if (ln.contains("<node")) { 101 for (String token : ln.split("[ ]+")) { 102 if (token.matches("^id=.+")) { 103 id = Long.parseLong(token.split("[\"\']")[1]); 104 } else if (token.matches("^lat=.+")) { 105 lat = Double.parseDouble(token.split("[\"\']")[1]); 106 } else if (token.matches("^lon=.+")) { 107 lon = Double.parseDouble(token.split("[\"\']")[1]); 108 } 109 } 110 map.addNode(id, lat, lon); 111 if (ln.contains("/>")) { 112 map.tagsDone(id); 113 } else { 114 inNode = true; 115 } 116 } else if (inWay) { 117 if (ln.contains("<nd")) { 118 long ref = 0; 119 for (String token : ln.split("[ ]+")) { 120 if (token.matches("^ref=.+")) { 121 ref = Long.parseLong(token.split("[\"\']")[1]); 122 } 123 } 124 map.addToEdge(ref); 125 } 126 if (ln.contains("</way")) { 127 inWay = false; 128 map.tagsDone(id); 129 } 130 } else if (ln.contains("<way")) { 131 for (String token : ln.split("[ ]+")) { 132 if (token.matches("^id=.+")) { 133 id = Long.parseLong(token.split("[\"\']")[1]); 134 } 135 } 136 map.addEdge(id); 137 if (ln.contains("/>")) { 138 map.tagsDone(0); 139 } else { 140 inWay = true; 141 } 142 } else if (ln.contains("</osm")) { 143 inOsm = false; 144 break; 145 } else if (inRel) { 146 if (ln.contains("<member")) { 147 String type = ""; 148 String role = ""; 149 long ref = 0; 150 for (String token : ln.split("[ ]+")) { 151 if (token.matches("^ref=.+")) { 152 ref = Long.parseLong(token.split("[\"\']")[1]); 153 } else if (token.matches("^type=.+")) { 154 type = (token.split("[\"\']")[1]); 155 } else if (token.matches("^role=.+")) { 156 role = (token.split("[\"\']")[1]); 157 } 158 } 159 if ((role.equals("outer") || role.equals("inner")) && type.equals("way")) 160 map.addToArea(ref, role.equals("outer")); 161 } 162 if (ln.contains("</relation")) { 163 inRel = false; 164 map.tagsDone(id); 165 } 166 } else if (ln.contains("<relation")) { 167 for (String token : ln.split("[ ]+")) { 168 if (token.matches("^id=.+")) { 169 id = Long.parseLong(token.split("[\"\']")[1]); 170 } 171 } 172 map.addArea(id); 173 if (ln.contains("/>")) { 174 map.tagsDone(id); 175 } else { 176 inRel = true; 177 } 178 } 179 } else if (ln.contains("<osm")) { 180 inOsm = true; 181 map = new S57map(); 182 } 183 } 184 in.close(); 185 186 for (int s = 1, z = 12; z <= 18; s *= 2, z++) { 187 for (int x = 0; x < s; x++) { 188 for (int y = 0; y < s; y++) { 189 img = new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB); 190 g2 = img.createGraphics(); 191 g2.scale(s, s); 192 g2.translate(-(256 + (x * 256 / s)), -(256 + (y * 256 / s))); 193 render.drawRendering(g2, z, 1); 194 ByteOutputStream bos = new ByteOutputStream(); 195 ImageIO.write(img, "png", bos); 196 if (bos.size() > 334) { 197 FileOutputStream fos = new FileOutputStream("/Users/mherring/boatsw/oseam/josm/plugins/smed2/jrender/tst/tst" + z + "_" + x + "_" + y + ".png"); 198 bos.writeTo(fos); 199 fos.close(); 200 } 201 } 202 } 203 } 204 205 for (int z = 12; z <= 18; z++) { 206 DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation(); 207 Document document = domImpl.createDocument("http://www.w3.org/2000/svg", "svg", null); 208 SVGGraphics2D svgGenerator = new SVGGraphics2D(document); 209 svgGenerator.setSVGCanvasSize(new Dimension(256, 256)); 210 svgGenerator.setClip(0, 0, 256, 256); 211 svgGenerator.translate(-256, -256); 212 render.drawRendering(svgGenerator, z, 1); 213 svgGenerator.stream("/Users/mherring/boatsw/oseam/josm/plugins/smed2/jrender/tst/tst" + z + ".svg"); 214 } 35 MapBB bb = new MapBB(Double.parseDouble(args[1]), Double.parseDouble(args[2]), Double.parseDouble(args[3]), Double.parseDouble(args[4])); 36 Tilegen.tileMap(Extract.extractData(args[0], bb), bb); 215 37 216 38 System.err.println("Finished"); 217 39 System.exit(0); 218 40 } 219 220 221 static class Render implements MapContext {222 223 public void drawRendering(Graphics2D g2, int zoom, double scale) {224 Renderer.reRender(g2, zoom, scale, map, this);225 }226 227 @Override228 public Point2D getPoint(Snode coord) {229 double x = (Math.toDegrees(coord.lon) - minlon) * 256.0 * 2048.0 / 180.0;230 double y = ((1.0 - Math.log(Math.tan(coord.lat) + 1.0 / Math.cos(coord.lat)) / Math.PI) / 2.0 * 256.0 * 4096.0) - top;231 return new Point2D.Double(x, y);232 }233 234 @Override235 public double mile(Feature feature) {236 return mile;237 }238 }239 41 }
Note:
See TracChangeset
for help on using the changeset viewer.