Ignore:
Timestamp:
2016-02-27T09:09:45+01:00 (9 years ago)
Author:
malcolmh
Message:

[seachart] update

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/seachart/jbasemap/src/jbasemap/Jbasemap.java

    r31846 r32082  
    3535        static Context context;
    3636        static S57map map;
     37        static int zoom;
     38        static double z2;
    3739
    3840        static class Context implements ChartContext {
     
    4244         
    4345          public Context () {
    44                         top = (1.0 - Math.log(Math.tan(map.bounds.maxlat) + 1.0 / Math.cos(map.bounds.maxlat)) / Math.PI) / 2.0 * 256.0 * 512.0;
     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;
    4547                        mile = 256 / ((Math.toDegrees(map.bounds.maxlat) - Math.toDegrees(map.bounds.minlat)) * 60);
    4648          }
    4749         
    4850                public Point2D getPoint(Snode coord) {
    49                         double x = (Math.toDegrees(coord.lon) - Math.toDegrees(map.bounds.minlon)) * 256.0 * 256.0 / 180.0;
    50                         double y = ((1.0 - Math.log(Math.tan(coord.lat) + 1.0 / Math.cos(coord.lat)) / Math.PI) / 2.0 * 256.0 * 512.0) - top;
     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;
    5153                        return new Point2D.Double(x, y);
    5254                }
     
    6062                }
    6163
    62                 public Color background() {
     64                public Color background(S57map map) {
    6365                        if (map.features.containsKey(Obj.COALNE)) {
    64                                 return Symbols.Bwater;
     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;
    6585                        } else {
    66                                 return Symbols.Yland;
     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                                }
    6791                        }
    6892                }
     
    7498       
    7599        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                }
    76104                src = args[0];
    77105                dst = args[1];
     106                zoom = Integer.parseInt(args[2]);
     107                z2 = Math.pow(2, zoom);
     108                double scale = 0.1;
    78109                try {
    79110                        BufferedReader in = new BufferedReader(new FileReader(src));
    80111                        map = new S57map(false);
    81                         if (args.length == 4) {
    82                                 map.bounds.maxlat = Math.atan(Math.sinh(Math.PI * (1 - 2 * Double.parseDouble(args[3]) / 512))) * 180.0 / Math.PI;
    83                                 map.bounds.minlat = Math.atan(Math.sinh(Math.PI * (1 - 2 * (Double.parseDouble(args[3]) + 1) / 512))) * 180.0 / Math.PI;
    84                                 map.bounds.minlon = Double.parseDouble(args[2]) / 512 * 360.0 - 180.0;
    85                                 map.bounds.maxlon = (Double.parseDouble(args[2]) + 1) / 512 * 360.0 - 180.0;
    86                         }
    87112                        try {
    88                                 S57osm.OSMmap(in, map);
     113                                S57osm.OSMmap(in, map, true);
    89114                        } catch (Exception e) {
    90115                                System.err.println("Input data error");
     
    96121                        System.exit(-1);
    97122                }
     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);
    98127                context = new Context();
    99128                Rectangle rect = new Rectangle(256, 256);
     
    104133                svgGenerator.setSVGCanvasSize(rect.getSize());
    105134                svgGenerator.setClip(rect.x, rect.y, rect.width, rect.height);
    106                 Renderer.reRender(svgGenerator, rect, 9, 0.002, map, context);
     135                Renderer.reRender(svgGenerator, rect, zoom, scale, map, context);
    107136                svgGenerator.stream(dst);
    108137                System.exit(0);
Note: See TracChangeset for help on using the changeset viewer.