Ignore:
Timestamp:
2015-10-26T16:40:54+01:00 (9 years ago)
Author:
malcolmh
Message:

add josmtos57

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/seachart/jrender/src/jrender/Jrender.java

    r31532 r31704  
    3333
    3434import s57.S57map;
    35 import s57.S57map.Feature;
    36 import s57.S57map.Snode;
     35import s57.S57osm;
     36import s57.S57map.*;
    3737import symbols.*;
    3838import render.*;
    39 import render.ChartContext.RuleSet;
    4039
    4140public class Jrender {
     
    4645        static int ytile;
    4746        static int zoom;
    48         static double minlat;
    49         static double minlon;
    50         static double maxlat;
    51         static double maxlon;
    52         static ArrayList<String> buf;
    5347        static ArrayList<String> send;
    5448        static HashMap<String, Boolean> deletes;
     
    6357         
    6458          public Context () {
    65                         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;
    66                         mile = 768 / ((maxlat - minlat) * 60);
     59                        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;
     60                        mile = 768 / ((Math.toDegrees(map.bounds.maxlat) - Math.toDegrees(map.bounds.minlat)) * 60);
    6761          }
    6862         
    6963                public Point2D getPoint(Snode coord) {
    70                         double x = (Math.toDegrees(coord.lon) - minlon) * 256.0 * 2048.0 / 180.0;
     64                        double x = (Math.toDegrees(coord.lon) - Math.toDegrees(map.bounds.minlon)) * 256.0 * 2048.0 / 180.0;
    7165                        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;
    7266                        return new Point2D.Double(x, y);
     
    9084        }
    9185       
    92         public static void tileMap(ArrayList<String> buf, String idir, int zoom) throws IOException {
    93                 String k = "";
    94                 String v = "";
    95                
    96                 double lat = 0;
    97                 double lon = 0;
    98                 long id = 0;
    99 
     86        public static void tileMap(String idir, int zoom) throws IOException {
    10087                BufferedImage img;
    101                 boolean inOsm = false;
    102                 boolean inNode = false;
    103                 boolean inWay = false;
    104                 boolean inRel = false;
    105                
    10688                context = new Context();
    10789
    108                 for (String ln : buf) {
    109                         if (inOsm) {
    110                                 if ((inNode || inWay || inRel) && (ln.contains("<tag"))) {
    111                                         k = v = "";
    112                                         String[] token = ln.split("k=");
    113                                         k = token[1].split("[\"\']")[1];
    114                                         token = token[1].split("v=");
    115                                         v = token[1].split("[\"\']")[1];
    116                                         if (!k.isEmpty() && !v.isEmpty()) {
    117                                                 map.addTag(k, v);
    118                                         }
    119                                 }
    120                                 if (inNode) {
    121                                         if (ln.contains("</node")) {
    122                                                 inNode = false;
    123                                                 map.tagsDone(id);
    124                                         }
    125                                 } else if (ln.contains("<node")) {
    126                                         for (String token : ln.split("[ ]+")) {
    127                                                 if (token.matches("^id=.+")) {
    128                                                         id = Long.parseLong(token.split("[\"\']")[1]);
    129                                                 } else if (token.matches("^lat=.+")) {
    130                                                         lat = Double.parseDouble(token.split("[\"\']")[1]);
    131                                                 } else if (token.matches("^lon=.+")) {
    132                                                         lon = Double.parseDouble(token.split("[\"\']")[1]);
    133                                                 }
    134                                         }
    135                                         map.addNode(id, lat, lon);
    136                                         if (ln.contains("/>")) {
    137                                                 map.tagsDone(id);
    138                                         } else {
    139                                                 inNode = true;
    140                                         }
    141                                 } else if (inWay) {
    142                                         if (ln.contains("<nd")) {
    143                                                 long ref = 0;
    144                                                 for (String token : ln.split("[ ]+")) {
    145                                                         if (token.matches("^ref=.+")) {
    146                                                                 ref = Long.parseLong(token.split("[\"\']")[1]);
    147                                                         }
    148                                                 }
    149                                                 map.addToEdge(ref);
    150                                         }
    151                                         if (ln.contains("</way")) {
    152                                                 inWay = false;
    153                                                 map.tagsDone(id);
    154                                         }
    155                                 } else if (ln.contains("<way")) {
    156                                         for (String token : ln.split("[ ]+")) {
    157                                                 if (token.matches("^id=.+")) {
    158                                                         id = Long.parseLong(token.split("[\"\']")[1]);
    159                                                 }
    160                                         }
    161                                         map.addEdge(id);
    162                                         if (ln.contains("/>")) {
    163                                                 map.tagsDone(0);
    164                                         } else {
    165                                                 inWay = true;
    166                                         }
    167                                 } else if (ln.contains("</osm")) {
    168                                         map.mapDone();
    169                                         inOsm = false;
    170                                         break;
    171                                 } else if (inRel) {
    172                                         if (ln.contains("<member")) {
    173                                                 String type = "";
    174                                                 String role = "";
    175                                                 long ref = 0;
    176                                                 for (String token : ln.split("[ ]+")) {
    177                                                         if (token.matches("^ref=.+")) {
    178                                                                 ref = Long.parseLong(token.split("[\"\']")[1]);
    179                                                         } else if (token.matches("^type=.+")) {
    180                                                                 type = (token.split("[\"\']")[1]);
    181                                                         } else if (token.matches("^role=.+")) {
    182                                                                 String str[] = token.split("[\"\']");
    183                                                                 if (str.length > 1) {
    184                                                                         role = (token.split("[\"\']")[1]);
    185                                                                 }
    186                                                         }
    187                                                 }
    188                                                 if ((role.equals("outer") || role.equals("inner")) && type.equals("way"))
    189                                                         map.addToArea(ref, role.equals("outer"));
    190                                         }
    191                                         if (ln.contains("</relation")) {
    192                                                 inRel = false;
    193                                                 map.tagsDone(id);
    194                                         }
    195                                 } else if (ln.contains("<relation")) {
    196                                         for (String token : ln.split("[ ]+")) {
    197                                                 if (token.matches("^id=.+")) {
    198                                                         id = Long.parseLong(token.split("[\"\']")[1]);
    199                                                 }
    200                                         }
    201                                         map.addArea(id);
    202                                         if (ln.contains("/>")) {
    203                                                 map.tagsDone(id);
    204                                         } else {
    205                                                 inRel = true;
    206                                         }
    207                                 }
    208                         } else if (ln.contains("<osm")) {
    209                                 inOsm = true;
    210                                 map = new S57map(context.ruleset() == RuleSet.SEAMARK);
    211                                 map.addNode(1, maxlat, minlon);
    212                                 map.addNode(2, minlat, minlon);
    213                                 map.addNode(3, minlat, maxlon);
    214                                 map.addNode(4, maxlat, maxlon);
    215                                 map.bounds.minlat = Math.toRadians(minlat);
    216                                 map.bounds.maxlat = Math.toRadians(maxlat);
    217                                 map.bounds.minlon = Math.toRadians(minlon);
    218                                 map.bounds.maxlon = Math.toRadians(maxlon);
    219                         }
    220                 }
    221                
    22290                int size = 256;
    22391                for (int i = 0; i < (12 - zoom); i++) size *= 2;
     
    310178                xtile = Integer.parseInt(args[3]);
    311179                ytile = Integer.parseInt(args[4]);
    312                 buf = new ArrayList<String>();
    313180                send = new ArrayList<String>();
    314181                deletes = new HashMap<String, Boolean>();
    315182                BufferedReader in = new BufferedReader(new FileReader(srcdir + zoom + "-" + xtile + "-" + ytile + ".osm"));
    316                 String ln;
    317                 while ((ln = in.readLine()) != null) {
    318                         if (ln.contains("<bounds")) {
    319                                 for (String token : ln.split("[ ]+")) {
    320                                         if (token.matches("^minlat=.+")) {
    321                                                 minlat = Double.parseDouble(token.split("[\"\']")[1]);
    322                                         } else if (token.matches("^minlon=.+")) {
    323                                                 minlon = Double.parseDouble(token.split("[\"\']")[1]);
    324                                         } else if (token.matches("^maxlat=.+")) {
    325                                                 maxlat = Double.parseDouble(token.split("[\"\']")[1]);
    326                                         } else if (token.matches("^maxlon=.+")) {
    327                                                 maxlon = Double.parseDouble(token.split("[\"\']")[1]);
    328                                         }
    329                                 }
    330                         } else {
    331                                 buf.add(ln);
    332                         }
    333                 }
     183                S57osm.OSMmap(in, map);
    334184                in.close();
    335185                if (zoom == 12) {
    336186                        clean(12, 0, 0);
    337187                }
    338                 tileMap(buf, dstdir, zoom);
     188                tileMap(dstdir, zoom);
    339189                if ((send.size() + deletes.size()) > 0) {
    340190                        PrintWriter writer = new PrintWriter(srcdir + zoom + "-" + xtile + "-" + ytile + ".send", "UTF-8");
Note: See TracChangeset for help on using the changeset viewer.