Changeset 30398 in osm
- Timestamp:
- 2014-04-14T23:04:50+02:00 (11 years ago)
- Location:
- applications/editors/josm/plugins/smed2
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/smed2/jicons/build.xml
r30397 r30398 7 7 <property name="batik.dir" value="/usr/local/bin/batik-1.7/"/> 8 8 <path id="classpath"> 9 <fileset dir="${batik.dir}" includes="**/ *.jar"/>9 <fileset dir="${batik.dir}" includes="**/batik*.jar"/> 10 10 </path> 11 11 … … 24 24 <attribute name="Class-Path" value="$jarfile"/> 25 25 </manifest> 26 <zipgroupfileset dir="${batik.dir}" includes="**/batik*.jar" /> 26 <zipgroupfileset dir="${batik.dir}" includes="**/batik-svggen.jar" /> 27 <zipgroupfileset dir="${batik.dir}" includes="**/batik-dom.jar" /> 28 <zipgroupfileset dir="${batik.dir}" includes="**/batik-util.jar" /> 29 <zipgroupfileset dir="${batik.dir}" includes="**/batik-awt-util.jar" /> 30 <zipgroupfileset dir="${batik.dir}" includes="**/batik-ext.jar" /> 31 <zipgroupfileset dir="${batik.dir}" includes="**/batik-xml.jar" /> 27 32 </jar> 28 33 </target> -
applications/editors/josm/plugins/smed2/jicons/src/jicons/Jicons.java
r30396 r30398 19 19 import java.awt.Dimension; 20 20 import java.awt.Graphics2D; 21 import java.awt.RenderingHints;22 21 import java.awt.geom.Point2D; 23 22 import java.awt.image.BufferedImage; … … 192 191 193 192 public void drawRendering(Graphics2D g2, double scale) { 194 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);195 g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);196 193 Renderer.reRender(g2, 16, scale / Renderer.symbolScale[16], map, this); 197 194 } -
applications/editors/josm/plugins/smed2/jrender/build.xml
r30397 r30398 7 7 <property name="batik.dir" value="/usr/local/bin/batik-1.7/"/> 8 8 <path id="classpath"> 9 <fileset dir="${batik.dir}" includes="**/ *.jar"/>9 <fileset dir="${batik.dir}" includes="**/batik*.jar"/> 10 10 </path> 11 11 … … 24 24 <attribute name="Class-Path" value="$jarfile"/> 25 25 </manifest> 26 <zipgroupfileset dir="${batik.dir}" includes="**/batik*.jar" /> 27 26 <zipgroupfileset dir="${batik.dir}" includes="**/batik-svggen.jar" /> 27 <zipgroupfileset dir="${batik.dir}" includes="**/batik-dom.jar" /> 28 <zipgroupfileset dir="${batik.dir}" includes="**/batik-util.jar" /> 29 <zipgroupfileset dir="${batik.dir}" includes="**/batik-awt-util.jar" /> 30 <zipgroupfileset dir="${batik.dir}" includes="**/batik-ext.jar" /> 31 <zipgroupfileset dir="${batik.dir}" includes="**/batik-xml.jar" /> 28 32 </jar> 29 33 </target> -
applications/editors/josm/plugins/smed2/jrender/src/jrender/Jrender.java
r30396 r30398 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; 12 19 import java.io.File; 13 20 import java.io.FileOutputStream; 21 import java.io.FileReader; 14 22 import java.io.IOException; 23 import java.io.OutputStream; 15 24 import java.io.OutputStreamWriter; 16 25 import java.io.Writer; 17 import java.awt.Color; 18 import java.awt.Dimension; 19 import java.awt.Graphics; 20 import java.awt.Graphics2D; 21 import java.awt.Panel; 22 import java.awt.RenderingHints; 23 import java.awt.image.BufferedImage; 26 import java.util.zip.GZIPOutputStream; 24 27 25 28 import javax.imageio.ImageIO; 26 import javax.swing.JFrame; 27 29 30 import org.apache.batik.dom.GenericDOMImplementation; 28 31 import org.apache.batik.svggen.SVGGraphics2D; 29 import org.apache.batik.svggen.SVGGraphics2DIOException; 30 import org.apache.batik.dom.GenericDOMImplementation; 32 import org.w3c.dom.DOMImplementation; 31 33 import org.w3c.dom.Document; 32 import org.w3c.dom.DOMImplementation; 33 34 import symbols.*; 35 import symbols.Symbols.*; 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; 36 40 import render.*; 37 41 38 public class Jrender extends Panel { 39 40 public static void main(String[] args) { 42 public class Jrender { 43 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 52 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 41 62 BufferedImage img; 42 63 Graphics2D g2; 43 44 JFrame frame = new JFrame("Jrender"); 45 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 46 Panel panel = new Jrender(); 47 frame.getContentPane().add("Center", panel); 48 frame.setSize(256, 256); 49 frame.setVisible(true); 50 51 img = new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB); 52 g2 = img.createGraphics(); 53 drawRendering(g2); 54 try { 55 ImageIO.write(img, "png", new File("/Users/mherring/Desktop/export.png")); 56 } catch (Exception e) { 57 System.out.println("Exception"); 58 } 59 60 DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation(); 61 String svgNS = "http://www.w3.org/2000/svg"; 62 Document document = domImpl.createDocument(svgNS, "svg", null); 63 SVGGraphics2D svgGenerator = new SVGGraphics2D(document); 64 svgGenerator.setSVGCanvasSize(new Dimension(256, 256)); 65 drawRendering(svgGenerator); 66 boolean useCSS = true; 67 Writer out = null; 68 try { 69 out = new OutputStreamWriter(new FileOutputStream("/Users/mherring/Desktop/export.svg"), "UTF-8"); 70 } catch (IOException e1) { 71 System.out.println("Exception"); 64 boolean inOsm = false; 65 boolean inNode = false; 66 boolean inWay = false; 67 boolean inRel = false; 68 69 if (args.length < 5) { 70 System.err.println("Usage: java -jar jrender.jar osm_file minlat, minlon, maxlat, maxlon"); 71 System.exit(-1); 72 } 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 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(); 72 182 } 73 try { 74 svgGenerator.stream(out, useCSS); 75 } catch (SVGGraphics2DIOException e) { 76 System.out.println("Exception"); 77 } 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 } 215 216 System.err.println("Finished"); 217 System.exit(0); 78 218 } 79 219 80 public static void drawRendering(Graphics2D g2) {81 double scale = Renderer.symbolScale[8];82 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);83 g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);84 Scheme scheme = new Scheme(); scheme.pat.add(Patt.H); scheme.col.add(Color.red); scheme.col.add(Color.yellow); scheme.col.add(Color.green);85 Symbols.drawSymbol(g2, Buoys.Pillar, scale, 128.0, 128.0, scheme, null);86 }87 220 88 public void paint(Graphics g) { 89 Graphics2D g2 = (Graphics2D)g; 90 drawRendering(g2); 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 @Override 228 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 @Override 235 public double mile(Feature feature) { 236 return mile; 237 } 91 238 } 92 239 }
Note:
See TracChangeset
for help on using the changeset viewer.