Changeset 35392 in osm for applications
- Timestamp:
- 2020-03-22T12:03:02+01:00 (5 years ago)
- Location:
- applications/editors/josm/plugins/seachart
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/seachart/jbasemap/src/jbasemap/Jbasemap.java
r32907 r35392 6 6 import java.awt.geom.Point2D; 7 7 import java.io.BufferedReader; 8 import java.io.File Reader;8 import java.io.File; 9 9 import java.io.IOException; 10 10 … … 63 63 64 64 @Override 65 public int grid() { 66 return 0; 67 } 68 69 @Override 65 70 public boolean clip() { 66 71 return true; … … 116 121 z2 = Math.pow(2, zoom); 117 122 double scale = 0.1; 123 File in = new File(src); 124 map = new S57map(false); 118 125 try { 119 BufferedReader in = new BufferedReader(new FileReader(src)); 120 map = new S57map(false); 121 try { 122 S57osm.OSMmap(in, map, true); 123 } catch (Exception e) { 124 System.err.println("Input data error"); 125 System.exit(-1); 126 } 127 in.close(); 128 } catch (IOException e) { 129 System.err.println("Input file: " + e.getMessage()); 126 S57osm.OSMmap(in, map, true); 127 } catch (Exception e) { 128 System.err.println("Input data error"); 130 129 System.exit(-1); 131 130 } -
applications/editors/josm/plugins/seachart/jchart/src/jchart/Jchart.java
r35391 r35392 8 8 import java.awt.geom.Point2D; 9 9 import java.awt.image.BufferedImage; 10 import java.io.BufferedReader;11 10 import java.io.File; 12 11 import java.io.FileOutputStream; 13 import java.io.FileReader;14 12 import java.io.IOException; 15 13 import java.io.OutputStreamWriter; … … 132 130 System.exit(-1); 133 131 } 134 BufferedReader in = new BufferedReader(new FileReader(args[0]));132 File in = new File(args[0]); 135 133 zoom = Integer.parseInt(args[1]); 136 134 map = new S57map(false); 137 135 S57osm.OSMmap(in, map, false); 138 in.close();136 // in.close(); 139 137 context = new Context(); 140 138 Point2D size = context.getPoint(new Snode(map.bounds.minlat, map.bounds.maxlon)); -
applications/editors/josm/plugins/seachart/jicons/src/jicons/Jicons.java
r32907 r35392 207 207 208 208 @Override 209 public int grid() { 210 return 0; 211 } 212 213 @Override 209 214 public Color background(S57map map) { 210 215 return new Color(0, true); -
applications/editors/josm/plugins/seachart/josmtos57/src/josmtos57/Josmtos57.java
r32907 r35392 6 6 import java.io.FileInputStream; 7 7 import java.io.FileOutputStream; 8 import java.io.File Reader;8 import java.io.File; 9 9 import java.io.IOException; 10 10 import java.io.UnsupportedEncodingException; … … 62 62 }; 63 63 64 static BufferedReaderin;64 static File in; 65 65 static FileOutputStream out; 66 66 static S57map map; … … 93 93 System.exit(-1); 94 94 } 95 in = new File(args[0]); 95 96 try { 96 in = new BufferedReader(new FileReader(new File(args[0]))); 97 try { 98 S57osm.OSMmap(in, map, false); 99 } catch (Exception e) { 100 System.err.println("Input data error"); 101 System.exit(-1); 102 } 103 in.close(); 104 } catch (IOException e) { 105 System.err.println("Input file: " + e.getMessage()); 97 S57osm.OSMmap(in, map, false); 98 } catch (Exception e) { 99 System.err.println("Input data error"); 106 100 System.exit(-1); 107 101 } -
applications/editors/josm/plugins/seachart/jrender/src/jrender/Jrender.java
r34886 r35392 73 73 public boolean clip() { 74 74 return false; 75 } 76 77 @Override 78 public int grid() { 79 return 0; 75 80 } 76 81 … … 156 161 send = new ArrayList<>(); 157 162 deletes = new HashMap<>(); 158 BufferedReader in = new BufferedReader(new FileReader(srcdir + xtile + "-" + ytile + "-" + zoom + ".osm"));163 File in = new File(srcdir + xtile + "-" + ytile + "-" + zoom + ".osm"); 159 164 map = new S57map(true); 160 165 S57osm.OSMmap(in, map, false); 161 in.close();162 166 context = new Context(); 163 167 ByteArrayOutputStream bos = new ByteArrayOutputStream(); -
applications/editors/josm/plugins/seachart/src/render/Renderer.java
r35391 r35392 25 25 26 26 import s57.S57map; 27 import s57.S57map.Feature; 27 28 import s57.S57map.GeomIterator; 28 29 import s57.S57map.Pflag; … … 331 332 if (context.grid() > 0) { 332 333 LineStyle style = new LineStyle(Color.black, (float)2.0); 333 double nspan = 60 * Math.toDegrees(map.bounds.maxlon - map.bounds.minlon) / 5.0;334 double nspan = 60 * Math.toDegrees(map.bounds.maxlon - map.bounds.minlon) / context.grid(); 334 335 double mult = 1.0; 335 336 if (nspan < 1.0) { … … 373 374 g2.setPaint(style.line); 374 375 g2.draw(p); 375 double tspan = 60 * Math.toDegrees(map.bounds.maxlat - map.bounds.minlat) / 5.0;376 double tspan = 60 * Math.toDegrees(map.bounds.maxlat - map.bounds.minlat) / context.grid(); 376 377 mult = 1.0; 377 378 if (tspan < 1.0) { … … 413 414 g2.setPaint(style.line); 414 415 g2.draw(p); 415 } 416 /* Symbol legend = new Symbol(); 417 legend.add(new Instr(Form.BBOX, new Rectangle2D.Double(0, 0, 900, 300))); 418 Path2D.Double path = new Path2D.Double(); path.moveTo(0, 0); path.lineTo(900, 0); path.lineTo(900, 300); path.lineTo(0, 300); path.closePath(); 419 legend.add(new Instr(Form.FILL, Color.white)); 420 legend.add(new Instr(Form.PGON, path)); 421 legend.add(new Instr(Form.TEXT, new Caption("© OpenStreetMap contributors", new Font("Arial", Font.PLAIN, 25), Color.black, new Delta(Handle.BC, AffineTransform.getTranslateInstance(450, 300))))); 422 legend.add(new Instr(Form.TEXT, new Caption("Mercator projection", new Font("Arial", Font.PLAIN, 30), Color.black, new Delta(Handle.BC, AffineTransform.getTranslateInstance(450, 250))))); 423 Point2D point = context.getPoint(new Snode(map.bounds.minlat, map.bounds.minlon)); 424 Symbols.drawSymbol(g2, legend, sScale, point.getX(), point.getY(), null, new Delta(Handle.BL, AffineTransform.getTranslateInstance(0, 0))); 425 legend = new Symbol(); 426 legend.add(new Instr(Form.BBOX, new Rectangle2D.Double(0, 0, 900, 300))); 427 legend.add(new Instr(Form.TEXT, new Caption("Mercator projection", new Font("Arial", Font.PLAIN, 30), Color.black, new Delta(Handle.BC, AffineTransform.getTranslateInstance(450, 250))))); 428 point = context.getPoint(new Snode(map.bounds.minlat, map.bounds.minlon)); 429 Symbols.drawSymbol(g2, legend, sScale, point.getX(), point.getY(), null, new Delta(Handle.BL, AffineTransform.getTranslateInstance(0, 0))); 430 */ } 416 431 } 417 432 -
applications/editors/josm/plugins/seachart/src/s57/S57map.java
r34652 r35392 215 215 public ObjMap objs; // Slave object attributes 216 216 217 Feature() {217 public Feature() { 218 218 id = 0; 219 219 reln = Rflag.UNKN; -
applications/editors/josm/plugins/seachart/src/s57/S57osm.java
r35388 r35392 2 2 package s57; 3 3 4 import java.io. BufferedReader;4 import java.io.File; 5 5 import java.util.ArrayList; 6 6 import java.util.HashMap; 7 8 import javax.xml.parsers.DocumentBuilderFactory; 9 import javax.xml.parsers.DocumentBuilder; 10 import org.w3c.dom.Document; 11 import org.w3c.dom.NodeList; 12 import org.w3c.dom.Node; 13 import org.w3c.dom.Element; 14 import org.w3c.dom.NamedNodeMap; 7 15 8 16 import s57.S57att.Att; … … 89 97 } 90 98 91 public static void OSMmap( BufferedReaderin, S57map map, boolean bb) throws Exception {99 public static void OSMmap(File in, S57map map, boolean bb) throws Exception { 92 100 String k = ""; 93 101 String v = ""; … … 96 104 double lon = 0; 97 105 long id = 0; 98 99 boolean inOsm = false; 100 boolean inNode = false; 101 boolean inWay = false; 102 boolean inRel = false; 106 long ref = 0; 107 String type = ""; 108 String role = ""; 109 103 110 map.nodes.put(1L, new Snode()); 104 111 map.nodes.put(2L, new Snode()); … … 106 113 map.nodes.put(4L, new Snode()); 107 114 108 String ln; 109 while ((ln = in.readLine()) != null) { 110 if (inOsm) { 111 if (ln.contains("<bounds") && !bb) { 112 for (String token : ln.split("[ ]+")) { 113 if (token.matches("^minlat=.+")) { 114 map.bounds.minlat = Math.toRadians(Double.parseDouble(token.split("[\"]")[1])); 115 map.nodes.get(2L).lat = map.bounds.minlat; 116 map.nodes.get(3L).lat = map.bounds.minlat; 117 } else if (token.matches("^minlon=.+")) { 118 map.bounds.minlon = Math.toRadians(Double.parseDouble(token.split("[\"]")[1])); 119 map.nodes.get(1L).lon = map.bounds.minlon; 120 map.nodes.get(2L).lon = map.bounds.minlon; 121 } else if (token.matches("^maxlat=.+")) { 122 map.bounds.maxlat = Math.toRadians(Double.parseDouble(token.split("[\"]")[1])); 123 map.nodes.get(1L).lat = map.bounds.maxlat; 124 map.nodes.get(4L).lat = map.bounds.maxlat; 125 } else if (token.matches("^maxlon=.+")) { 126 map.bounds.maxlon = Math.toRadians(Double.parseDouble(token.split("[\"]")[1])); 127 map.nodes.get(3L).lon = map.bounds.maxlon; 128 map.nodes.get(4L).lon = map.bounds.maxlon; 129 } 130 } 131 } else { 132 if ((inNode || inWay || inRel) && ln.contains("<tag")) { 133 k = v = ""; 134 String[] token = ln.split("k="); 135 k = token[1].split("[\"]")[1]; 136 token = token[1].split("v="); 137 v = token[1].split("[\"]")[1]; 138 if (!k.isEmpty() && !v.isEmpty()) { 139 map.addTag(k, v); 140 } 141 } 142 if (inNode) { 143 if (ln.contains("</node")) { 144 inNode = false; 145 map.tagsDone(id); 146 } 147 } else if (ln.contains("<node")) { 148 for (String token : ln.split("[ ]+")) { 149 if (token.matches("^id=.+")) { 150 id = Long.parseLong(token.split("[\"]")[1]); 151 } else if (token.matches("^lat=.+")) { 152 lat = Double.parseDouble(token.split("[\"]")[1]); 153 } else if (token.matches("^lon=.+")) { 154 lon = Double.parseDouble(token.split("[\"]")[1]); 155 } 156 } 157 map.addNode(id, lat, lon); 158 if (ln.contains("/>")) { 159 map.tagsDone(id); 160 } else { 161 inNode = true; 162 } 163 } else if (inWay) { 164 if (ln.contains("<nd")) { 165 long ref = 0; 166 for (String token : ln.split("[ ]+")) { 167 if (token.matches("^ref=.+")) { 168 ref = Long.parseLong(token.split("[\"]")[1]); 169 } 170 } 171 try { 172 map.addToEdge(ref); 173 } catch (Exception e) { 174 inWay = false; 175 } 176 } 177 if (ln.contains("</way")) { 178 inWay = false; 179 map.tagsDone(id); 180 } 181 } else if (ln.contains("<way")) { 182 for (String token : ln.split("[ ]+")) { 183 if (token.matches("^id=.+")) { 184 id = Long.parseLong(token.split("[\"]")[1]); 185 } 186 } 187 map.addEdge(id); 188 if (ln.contains("/>")) { 189 map.tagsDone(0); 190 } else { 191 inWay = true; 192 } 193 } else if (ln.contains("</osm")) { 194 map.mapDone(); 195 inOsm = false; 196 break; 197 } else if (inRel) { 198 if (ln.contains("<member")) { 199 String type = ""; 200 String role = ""; 201 long ref = 0; 202 for (String token : ln.split("[ ]+")) { 203 if (token.matches("^ref=.+")) { 204 ref = Long.parseLong(token.split("[\"]")[1]); 205 } else if (token.matches("^type=.+")) { 206 type = token.split("[\"]")[1]; 207 } else if (token.matches("^role=.+")) { 208 String[] str = token.split("[\"]"); 209 if (str.length > 1) { 210 role = token.split("[\"]")[1]; 211 } 212 } 213 } 214 if ((role.equals("outer") || role.equals("inner")) && type.equals("way")) 215 map.addToArea(ref, role.equals("outer")); 216 } 217 if (ln.contains("</relation")) { 218 inRel = false; 219 map.tagsDone(id); 220 } 221 } else if (ln.contains("<relation")) { 222 for (String token : ln.split("[ ]+")) { 223 if (token.matches("^id=.+")) { 224 id = Long.parseLong(token.split("[\"]")[1]); 225 } 226 } 227 map.addArea(id); 228 if (ln.contains("/>")) { 229 map.tagsDone(id); 230 } else { 231 inRel = true; 232 } 233 } 234 } 235 } else if (ln.contains("<osm")) { 236 inOsm = true; 237 } 238 } 115 DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); 116 DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); 117 Document doc = dBuilder.parse(in); 118 doc.getDocumentElement().normalize(); 119 if (!doc.getDocumentElement().getNodeName().equals("osm")) { 120 System.err.println("OSM file format error"); 121 System.exit(-1); 122 } 123 NodeList nList = doc.getElementsByTagName("bounds"); 124 NamedNodeMap nnmap = nList.item(0).getAttributes(); 125 map.bounds.minlat = Math.toRadians(Double.parseDouble(nnmap.getNamedItem("minlat").getNodeValue())); 126 map.nodes.get(2L).lat = map.bounds.minlat; 127 map.nodes.get(3L).lat = map.bounds.minlat; 128 map.bounds.minlon = Math.toRadians(Double.parseDouble(nnmap.getNamedItem("minlon").getNodeValue())); 129 map.nodes.get(1L).lon = map.bounds.minlon; 130 map.nodes.get(2L).lon = map.bounds.minlon; 131 map.bounds.maxlat = Math.toRadians(Double.parseDouble(nnmap.getNamedItem("maxlat").getNodeValue())); 132 map.nodes.get(1L).lat = map.bounds.maxlat; 133 map.nodes.get(4L).lat = map.bounds.maxlat; 134 map.bounds.maxlon = Math.toRadians(Double.parseDouble(nnmap.getNamedItem("maxlon").getNodeValue())); 135 map.nodes.get(3L).lon = map.bounds.maxlon; 136 map.nodes.get(4L).lon = map.bounds.maxlon; 137 138 nList = doc.getElementsByTagName("node"); 139 int nLen = nList.getLength(); 140 for (int i = 0; i < nLen; i++) { 141 Node nNode = nList.item(i); 142 if (nNode.getNodeType() == Node.ELEMENT_NODE) { 143 nnmap = nNode.getAttributes(); 144 id = Long.parseLong(nnmap.getNamedItem("id").getNodeValue()); 145 lat = Double.parseDouble(nnmap.getNamedItem("lat").getNodeValue()); 146 lon = Double.parseDouble(nnmap.getNamedItem("lon").getNodeValue()); 147 map.addNode(id, lat, lon); 148 NodeList tList = ((Element)nNode).getElementsByTagName("tag"); 149 for (int j = 0; j < tList.getLength(); j++) { 150 NamedNodeMap ntmap = tList.item(j).getAttributes(); 151 k = ntmap.getNamedItem("k").getNodeValue(); 152 v = ntmap.getNamedItem("v").getNodeValue(); 153 if (!k.isEmpty() && !v.isEmpty()) { 154 map.addTag(k, v); 155 } 156 } 157 map.tagsDone(id); 158 } 159 } 160 161 nList = doc.getElementsByTagName("way"); 162 nLen = nList.getLength(); 163 for (int i = 0; i < nLen; i++) { 164 Node nNode = nList.item(i); 165 if (nNode.getNodeType() == Node.ELEMENT_NODE) { 166 nnmap = nNode.getAttributes(); 167 id = Long.parseLong(nnmap.getNamedItem("id").getNodeValue()); 168 map.addEdge(id); 169 NodeList rList = ((Element)nNode).getElementsByTagName("nd"); 170 for (int j = 0; j < rList.getLength(); j++) { 171 NamedNodeMap nrmap = rList.item(j).getAttributes(); 172 ref = Long.parseLong(nrmap.getNamedItem("ref").getNodeValue()); 173 try { 174 map.addToEdge(ref); 175 } catch (Exception e) { 176 System.err.println("Unknown node in way"); 177 System.exit(-1); 178 } 179 } 180 NodeList tList = ((Element)nNode).getElementsByTagName("tag"); 181 for (int j = 0; j < tList.getLength(); j++) { 182 NamedNodeMap ntmap = tList.item(j).getAttributes(); 183 k = ntmap.getNamedItem("k").getNodeValue(); 184 v = ntmap.getNamedItem("v").getNodeValue(); 185 if (!k.isEmpty() && !v.isEmpty()) { 186 map.addTag(k, v); 187 } 188 } 189 map.tagsDone(id); 190 } 191 } 192 193 nList = doc.getElementsByTagName("relation"); 194 nLen = nList.getLength(); 195 for (int i = 0; i < nLen; i++) { 196 Node nNode = nList.item(i); 197 if (nNode.getNodeType() == Node.ELEMENT_NODE) { 198 nnmap = nNode.getAttributes(); 199 id = Long.parseLong(nnmap.getNamedItem("id").getNodeValue()); 200 map.addArea(id); 201 NodeList rList = ((Element)nNode).getElementsByTagName("member"); 202 for (int j = 0; j < rList.getLength(); j++) { 203 NamedNodeMap nrmap = rList.item(j).getAttributes(); 204 type = nrmap.getNamedItem("type").getNodeValue(); 205 ref = Long.parseLong(nrmap.getNamedItem("ref").getNodeValue()); 206 role = nrmap.getNamedItem("role").getNodeValue(); 207 if ((role.equals("outer") || role.equals("inner")) && type.equals("way")) 208 map.addToArea(ref, role.equals("outer")); 209 } 210 NodeList tList = ((Element)nNode).getElementsByTagName("tag"); 211 for (int j = 0; j < tList.getLength(); j++) { 212 NamedNodeMap ntmap = tList.item(j).getAttributes(); 213 k = ntmap.getNamedItem("k").getNodeValue(); 214 v = ntmap.getNamedItem("v").getNodeValue(); 215 if (!k.isEmpty() && !v.isEmpty()) { 216 map.addTag(k, v); 217 } 218 } 219 map.tagsDone(id); 220 } 221 } 222 223 map.mapDone(); 239 224 return; 240 225 }
Note:
See TracChangeset
for help on using the changeset viewer.