Changeset 32906 in osm for applications/editors/josm/plugins/seachart/jbasemap/src
- Timestamp:
- 2016-09-03T16:18:15+02:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/seachart/jbasemap/src/jbasemap/Jbasemap.java
r32082 r32906 31 31 public class Jbasemap { 32 32 33 34 35 36 37 38 33 static String src; 34 static String dst; 35 static Context context; 36 static S57map map; 37 static int zoom; 38 static double z2; 39 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 40 static class Context implements ChartContext { 41 42 static double top = 0; 43 static double mile = 0; 44 45 public Context () { 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; 47 mile = 256 / ((Math.toDegrees(map.bounds.maxlat) - Math.toDegrees(map.bounds.minlat)) * 60); 48 } 49 50 public Point2D getPoint(Snode coord) { 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; 53 return new Point2D.Double(x, y); 54 } 55 55 56 57 58 56 public double mile(Feature feature) { 57 return mile; 58 } 59 59 60 61 62 60 public boolean clip() { 61 return true; 62 } 63 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 64 public Color background(S57map map) { 65 if (map.features.containsKey(Obj.COALNE)) { 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; 85 } else { 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 } 91 } 92 } 93 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 94 public RuleSet ruleset() { 95 return RuleSet.BASE; 96 } 97 } 98 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 } 104 src = args[0]; 105 dst = args[1]; 106 zoom = Integer.parseInt(args[2]); 107 z2 = Math.pow(2, zoom); 108 double scale = 0.1; 109 try { 110 BufferedReader in = new BufferedReader(new FileReader(src)); 111 map = new S57map(false); 112 try { 113 S57osm.OSMmap(in, map, true); 114 } catch (Exception e) { 115 System.err.println("Input data error"); 116 System.exit(-1); 117 } 118 in.close(); 119 } catch (IOException e) { 120 System.err.println("Input file: " + e.getMessage()); 121 System.exit(-1); 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); 127 context = new Context(); 128 Rectangle rect = new Rectangle(256, 256); 129 DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation(); 130 Document document = domImpl.createDocument("http://www.w3.org/2000/svg", "svg", null); 131 SVGGraphics2D svgGenerator = new SVGGraphics2D(document); 132 svgGenerator.clearRect(rect.x, rect.y, rect.width, rect.height); 133 svgGenerator.setSVGCanvasSize(rect.getSize()); 134 svgGenerator.setClip(rect.x, rect.y, rect.width, rect.height); 135 Renderer.reRender(svgGenerator, rect, zoom, scale, map, context); 136 svgGenerator.stream(dst); 137 System.exit(0); 138 } 139 139 }
Note:
See TracChangeset
for help on using the changeset viewer.