Changeset 32082 in osm for applications/editors/josm/plugins/seachart/jbasemap/src
- Timestamp:
- 2016-02-27T09:09:45+01:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/seachart/jbasemap/src/jbasemap/Jbasemap.java
r31846 r32082 35 35 static Context context; 36 36 static S57map map; 37 static int zoom; 38 static double z2; 37 39 38 40 static class Context implements ChartContext { … … 42 44 43 45 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; 45 47 mile = 256 / ((Math.toDegrees(map.bounds.maxlat) - Math.toDegrees(map.bounds.minlat)) * 60); 46 48 } 47 49 48 50 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; 51 53 return new Point2D.Double(x, y); 52 54 } … … 60 62 } 61 63 62 public Color background() { 64 public Color background(S57map map) { 63 65 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; 65 85 } 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 } 67 91 } 68 92 } … … 74 98 75 99 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 } 76 104 src = args[0]; 77 105 dst = args[1]; 106 zoom = Integer.parseInt(args[2]); 107 z2 = Math.pow(2, zoom); 108 double scale = 0.1; 78 109 try { 79 110 BufferedReader in = new BufferedReader(new FileReader(src)); 80 111 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 }87 112 try { 88 S57osm.OSMmap(in, map); 113 S57osm.OSMmap(in, map, true); 89 114 } catch (Exception e) { 90 115 System.err.println("Input data error"); … … 96 121 System.exit(-1); 97 122 } 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); 98 127 context = new Context(); 99 128 Rectangle rect = new Rectangle(256, 256); … … 104 133 svgGenerator.setSVGCanvasSize(rect.getSize()); 105 134 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); 107 136 svgGenerator.stream(dst); 108 137 System.exit(0);
Note:
See TracChangeset
for help on using the changeset viewer.