Changeset 31704 in osm for applications/editors/josm/plugins/seachart/src/s57/S57osm.java
- Timestamp:
- 2015-10-26T16:40:54+01:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/seachart/src/s57/S57osm.java
r31660 r31704 10 10 package s57; 11 11 12 import java.io.BufferedReader; 13 import java.io.IOException; 12 14 import java.util.ArrayList; 13 15 import java.util.HashMap; … … 35 37 static { 36 38 OSMtags.put("natural=coastline", new KeyVal<>(Obj.COALNE, Att.UNKATT, null, null)); OSMtags.put("natural=water", new KeyVal<>(Obj.LAKARE, Att.UNKATT, null, null)); 37 OSMtags.put("waterway=river bank", new KeyVal<>(Obj.RIVBNK, Att.UNKATT, null, null)); OSMtags.put("waterway=river", new KeyVal<>(Obj.RIVERS, Att.UNKATT, null, null));39 OSMtags.put("waterway=river", new KeyVal<>(Obj.RIVERS, Att.UNKATT, null, null)); 38 40 OSMtags.put("waterway=canal", new KeyVal<>(Obj.CANALS, Att.UNKATT, null, null)); OSMtags.put("waterway=dock", new KeyVal<>(Obj.HRBBSN, Att.UNKATT, null, null)); 39 41 OSMtags.put("waterway=lock", new KeyVal<>(Obj.HRBBSN, Att.UNKATT, null, null)); OSMtags.put("landuse=basin", new KeyVal<>(Obj.LAKARE, Att.UNKATT, null, null)); … … 62 64 return new KeyVal<>(Obj.UNKOBJ, Att.UNKATT, null, null); 63 65 } 66 67 public static void OSMmap(BufferedReader in, S57map map) throws IOException { 68 String k = ""; 69 String v = ""; 70 71 double lat = 0; 72 double lon = 0; 73 long id = 0; 74 75 boolean inOsm = false; 76 boolean inNode = false; 77 boolean inWay = false; 78 boolean inRel = false; 79 80 String ln; 81 while ((ln = in.readLine()) != null) { 82 if (inOsm) { 83 if (ln.contains("<bounds")) { 84 for (String token : ln.split("[ ]+")) { 85 if (token.matches("^minlat=.+")) { 86 map.bounds.minlat = Math.toRadians(Double.parseDouble(token.split("[\"\']")[1])); 87 } else if (token.matches("^minlon=.+")) { 88 map.bounds.minlon = Math.toRadians(Double.parseDouble(token.split("[\"\']")[1])); 89 } else if (token.matches("^maxlat=.+")) { 90 map.bounds.maxlat = Math.toRadians(Double.parseDouble(token.split("[\"\']")[1])); 91 } else if (token.matches("^maxlon=.+")) { 92 map.bounds.maxlon = Math.toRadians(Double.parseDouble(token.split("[\"\']")[1])); 93 } 94 } 95 } else { 96 if ((inNode || inWay || inRel) && (ln.contains("<tag"))) { 97 k = v = ""; 98 String[] token = ln.split("k="); 99 k = token[1].split("[\"\']")[1]; 100 token = token[1].split("v="); 101 v = token[1].split("[\"\']")[1]; 102 if (!k.isEmpty() && !v.isEmpty()) { 103 map.addTag(k, v); 104 } 105 } 106 if (inNode) { 107 if (ln.contains("</node")) { 108 inNode = false; 109 map.tagsDone(id); 110 } 111 } else if (ln.contains("<node")) { 112 for (String token : ln.split("[ ]+")) { 113 if (token.matches("^id=.+")) { 114 id = Long.parseLong(token.split("[\"\']")[1]); 115 } else if (token.matches("^lat=.+")) { 116 lat = Double.parseDouble(token.split("[\"\']")[1]); 117 } else if (token.matches("^lon=.+")) { 118 lon = Double.parseDouble(token.split("[\"\']")[1]); 119 } 120 } 121 map.addNode(id, lat, lon); 122 if (ln.contains("/>")) { 123 map.tagsDone(id); 124 } else { 125 inNode = true; 126 } 127 } else if (inWay) { 128 if (ln.contains("<nd")) { 129 long ref = 0; 130 for (String token : ln.split("[ ]+")) { 131 if (token.matches("^ref=.+")) { 132 ref = Long.parseLong(token.split("[\"\']")[1]); 133 } 134 } 135 map.addToEdge(ref); 136 } 137 if (ln.contains("</way")) { 138 inWay = false; 139 map.tagsDone(id); 140 } 141 } else if (ln.contains("<way")) { 142 for (String token : ln.split("[ ]+")) { 143 if (token.matches("^id=.+")) { 144 id = Long.parseLong(token.split("[\"\']")[1]); 145 } 146 } 147 map.addEdge(id); 148 if (ln.contains("/>")) { 149 map.tagsDone(0); 150 } else { 151 inWay = true; 152 } 153 } else if (ln.contains("</osm")) { 154 map.mapDone(); 155 inOsm = false; 156 break; 157 } else if (inRel) { 158 if (ln.contains("<member")) { 159 String type = ""; 160 String role = ""; 161 long ref = 0; 162 for (String token : ln.split("[ ]+")) { 163 if (token.matches("^ref=.+")) { 164 ref = Long.parseLong(token.split("[\"\']")[1]); 165 } else if (token.matches("^type=.+")) { 166 type = (token.split("[\"\']")[1]); 167 } else if (token.matches("^role=.+")) { 168 String str[] = token.split("[\"\']"); 169 if (str.length > 1) { 170 role = (token.split("[\"\']")[1]); 171 } 172 } 173 } 174 if ((role.equals("outer") || role.equals("inner")) && type.equals("way")) 175 map.addToArea(ref, role.equals("outer")); 176 } 177 if (ln.contains("</relation")) { 178 inRel = false; 179 map.tagsDone(id); 180 } 181 } else if (ln.contains("<relation")) { 182 for (String token : ln.split("[ ]+")) { 183 if (token.matches("^id=.+")) { 184 id = Long.parseLong(token.split("[\"\']")[1]); 185 } 186 } 187 map.addArea(id); 188 if (ln.contains("/>")) { 189 map.tagsDone(id); 190 } else { 191 inRel = true; 192 } 193 } 194 } 195 } else if (ln.contains("<osm")) { 196 inOsm = true; 197 } 198 } 199 return; 200 } 64 201 65 202 }
Note:
See TracChangeset
for help on using the changeset viewer.
