Changeset 30402 in osm for applications/editors/josm


Ignore:
Timestamp:
2014-04-16T11:25:57+02:00 (10 years ago)
Author:
malcolmh
Message:

save

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  
    3737public class Jicons {
    3838       
    39         static S57map map = null;
    4039        static int x = 0;
    4140        static int y = 0;
     
    4544
    4645        public static void main(String[] args) throws IOException {
    47                 Render render;
     46                Context context;
     47                S57map map = null;
    4848                BufferedReader in;
    4949                int line = 0;
     
    6464                in = new BufferedReader(new FileReader(args[0]));
    6565               
    66                 render = new Render();
     66                context = new Context();
    6767                String ln;
    6868                while ((ln = in.readLine()) != null) {
     
    7878                                                        img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
    7979                                                        g2 = img.createGraphics();
    80                                                         render.drawRendering(g2, s);
     80                                                        Renderer.reRender(g2, 16, s / Renderer.symbolScale[16], map, context);
    8181                                                        try {
    8282                                                                ImageIO.write(img, "png", new File(args[1] + file + ".png"));
     
    9292                                                        SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
    9393                                                        svgGenerator.setSVGCanvasSize(new Dimension(w, h));
    94                                                         render.drawRendering(svgGenerator, s);
     94                                                        Renderer.reRender(svgGenerator, 16, s / Renderer.symbolScale[16], map, context);
    9595                                                        boolean useCSS = true;
    9696                                                        Writer out = null;
     
    188188        }
    189189       
    190         static class Render implements MapContext {
     190        static class Context implements MapContext {
    191191               
    192                 public void drawRendering(Graphics2D g2, double scale) {
    193                         Renderer.reRender(g2, 16, scale / Renderer.symbolScale[16], map, this);
    194                 }
    195 
    196192                @Override
    197193                public Point2D getPoint(Snode coord) {
     
    201197                @Override
    202198                public double mile(Feature feature) {
    203                         return 1000;
     199                        return Math.min(w, h);
    204200                }
    205201        }
  • applications/editors/josm/plugins/smed2/jrender/src/jrender/Jrender.java

    r30398 r30402  
    1 /* Copyright 2012 Malcolm Herring
     1/* Copyright 2014 Malcolm Herring
    22 *
    33 * This is free software: you can redistribute it and/or modify
     
    1010package jrender;
    1111
    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;
    2212import 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.*;
    4113
    4214public class Jrender {
    4315
    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       
    5229        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                
    6930                if (args.length < 5) {
    7031                        System.err.println("Usage: java -jar jrender.jar osm_file minlat, minlon, maxlat, maxlon");
    7132                        System.exit(-1);
    7233                }
    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);
    8034               
    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);
    21537
    21638                System.err.println("Finished");
    21739                System.exit(0);
    21840        }
    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                 @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                 }
    238         }
    23941}
Note: See TracChangeset for help on using the changeset viewer.