Changeset 29270 in osm
- Timestamp:
- 2013-02-20T20:10:33+01:00 (12 years ago)
- Location:
- applications/editors/josm/plugins/smed2/src/seamap
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/smed2/src/seamap/Renderer.java
r29266 r29270 173 173 174 174 public static void lineVector (Feature feature, LineStyle style) { 175 if (feature.flag != Fflag.POINT) { 176 ArrayList<Long> ways = new ArrayList<Long>(); 177 // if (map.outers.containsKey(feature.refs)) { 178 // ways.addAll(map.mpolys.get(map.outers.get(feature.refs))); 179 // } else { 180 // if (map.mpolys.containsKey(feature.refs)) { 181 // ways.addAll(map.mpolys.get(feature.refs)); 182 // } else { 183 // ways.add(feature.refs); 184 // } 185 // } 186 Path2D.Double p = new Path2D.Double(); 187 p.setWindingRule(GeneralPath.WIND_EVEN_ODD); 175 Path2D.Double p = new Path2D.Double(); 176 p.setWindingRule(GeneralPath.WIND_EVEN_ODD); 177 switch (feature.flag) { 178 case LINE: 179 break; 180 case AREA: 181 break; 182 /* ArrayList<Long> ways = new ArrayList<Long>(); 183 if (map.outers.containsKey(feature.refs)) { 184 ways.addAll(map.mpolys.get(map.outers.get(feature.refs))); 185 } else { 186 if (map.mpolys.containsKey(feature.refs)) { 187 ways.addAll(map.mpolys.get(feature.refs)); 188 } else { 189 ways.add(feature.refs); 190 } 191 } 188 192 for (long way : ways) { 189 193 boolean first = true; 190 /*for (long node : map.ways.get(way)) {194 for (long node : map.ways.get(way)) { 191 195 Point2D point = helper.getPoint(map.points.get(node)); 192 196 if (first) { … … 215 219 g2.setPaint(style.fill); 216 220 g2.fill(p); 217 */ } 221 }*/ 218 222 } 219 223 } -
applications/editors/josm/plugins/smed2/src/seamap/SeaMap.java
r29266 r29270 24 24 ANON, ISOL, CONN 25 25 } 26 26 27 27 public class Snode { 28 28 public double lat; … … 35 35 lon = 0; 36 36 } 37 37 38 public Snode(double ilat, double ilon) { 38 39 flg = Nflag.ANON; … … 40 41 lon = ilon; 41 42 } 43 42 44 public Snode(double ilat, double ilon, Nflag iflg) { 43 45 lat = ilat; … … 46 48 } 47 49 } 48 50 49 51 public class Edge { 50 52 public boolean forward; … … 52 54 public long last; 53 55 public ArrayList<Long> nodes; 56 54 57 public Edge() { 55 58 forward = true; … … 59 62 } 60 63 } 61 64 62 65 public class Side { 63 66 Edge edge; 64 67 boolean forward; 68 65 69 public Side(Edge iedge, boolean ifwd) { 66 70 edge = iedge; … … 68 72 } 69 73 } 70 74 71 75 public class Bound { 72 76 public boolean outer; 73 77 ArrayList<Side> sides; 78 74 79 public Bound() { 75 80 outer = true; 76 81 sides = new ArrayList<Side>(); 77 82 } 83 78 84 public Bound(Side iside, boolean irole) { 79 85 outer = irole; … … 98 104 } 99 105 } 100 106 101 107 public class AttMap extends EnumMap<Att, AttItem> { 102 108 public AttMap() { … … 104 110 } 105 111 } 106 112 107 113 public class ObjTab extends HashMap<Integer, AttMap> { 108 114 public ObjTab() { … … 110 116 } 111 117 } 112 118 113 119 public class ObjMap extends EnumMap<Obj, ObjTab> { 114 120 public ObjMap() { … … 116 122 } 117 123 } 118 124 119 125 public class NodeTab extends HashMap<Long, Snode> { 120 126 public NodeTab() { … … 122 128 } 123 129 } 124 130 125 131 public class EdgeTab extends HashMap<Long, Edge> { 126 132 public EdgeTab() { … … 128 134 } 129 135 } 130 136 131 137 public class AreaTab extends HashMap<Long, Area> { 132 138 public AreaTab() { … … 134 140 } 135 141 } 136 142 137 143 public class FtrMap extends EnumMap<Obj, ArrayList<Feature>> { 138 144 public FtrMap() { … … 140 146 } 141 147 } 142 148 143 149 public class FtrTab extends HashMap<Long, Feature> { 144 150 public FtrTab() { … … 146 152 } 147 153 } 148 154 149 155 public enum Fflag { 150 156 UNKN, POINT, LINE, AREA 151 157 } 152 158 153 159 public class Feature { 154 160 public Fflag flag; … … 174 180 public EdgeTab edges; 175 181 public AreaTab areas; 176 182 177 183 public FtrMap features; 178 184 public FtrTab index; … … 182 188 private ArrayList<Long> outers; 183 189 private ArrayList<Long> inners; 190 191 public class EdgeIterator { 192 Edge edge; 193 boolean forward; 194 ListIterator<Long> it; 195 196 public EdgeIterator(Edge iedge, boolean dir) { 197 edge = iedge; 198 forward = dir; 199 it = null; 200 } 201 202 public boolean hasNext() { 203 return (edge != null) && ((it == null) || (forward && it.hasNext()) || (!forward && it.hasPrevious())); 204 } 205 206 public Snode next() { 207 long ref = 0; 208 if (forward) { 209 if (it == null) { 210 ref = edge.first; 211 it = edge.nodes.listIterator(); 212 } else { 213 if (it.hasNext()) { 214 ref = it.next(); 215 } else { 216 ref = edge.last; 217 edge = null; 218 } 219 } 220 } else { 221 if (it == null) { 222 ref = edge.last; 223 it = edge.nodes.listIterator(edge.nodes.size()); 224 } else { 225 if (it.hasPrevious()) { 226 ref = it.previous(); 227 } else { 228 ref = edge.first; 229 edge = null; 230 } 231 } 232 } 233 return nodes.get(ref); 234 } 235 } 236 237 public class BoundIterator { 238 Bound bound; 239 Side side; 240 ListIterator<Side> sit; 241 EdgeIterator eit; 242 243 public BoundIterator(Bound ibound) { 244 bound = ibound; 245 sit = bound.sides.listIterator(); 246 if (sit.hasNext()) { 247 side = sit.next(); 248 eit = new EdgeIterator(side.edge, side.forward); 249 } else { 250 side = null; 251 } 252 } 253 254 public boolean hasNext() { 255 return side != null; 256 } 257 258 public Snode next() { 259 Snode node = null; 260 if (side != null) { 261 if (eit.hasNext()) { 262 node = eit.next(); 263 } else { 264 if (sit.hasNext()) { 265 side = sit.next(); 266 eit = new EdgeIterator(side.edge, side.forward); 267 node = eit.next(); 268 } else { 269 side = null; 270 } 271 } 272 } 273 return node; 274 } 275 } 276 277 public class AreaIterator { 278 Area area; 279 } 280 281 public class FeatureIterator { 282 Feature feature; 283 } 184 284 185 285 public SeaMap() { … … 234 334 } 235 335 } 236 336 237 337 public void addTag(String key, String val) { 238 338 String subkeys[] = key.split(":"); … … 261 361 } 262 362 AttVal attval = S57val.convertValue(val, att); 263 if (attval.val != null) atts.put(att, new AttItem(attval.conv, attval.val)); 363 if (attval.val != null) 364 atts.put(att, new AttItem(attval.conv, attval.val)); 264 365 } else { 265 366 if (subkeys[1].equals("type")) { … … 269 370 if (att != Att.UNKATT) { 270 371 AttVal attval = S57val.convertValue(val, att); 271 if (attval.val != null) feature.atts.put(att, new AttItem(attval.conv, attval.val)); 372 if (attval.val != null) 373 feature.atts.put(att, new AttItem(attval.conv, attval.val)); 272 374 } 273 375 } … … 311 413 Bound bound = new Bound(new Side(edge, edge.forward), (role == outers)); 312 414 if (node1 != node2) { 313 for (ListIterator<Long> it = role.listIterator(0); it.hasNext(); ) { 314 Edge nedge = edges.get(it.next()); 315 if (nedge.first == node2) { 316 bound.sides.add(new Side(nedge, true)); 317 it.remove(); 318 if (nedge.last == node2) break; 319 } else if (nedge.last == node2) { 320 bound.sides.add(new Side(nedge, false)); 321 it.remove(); 322 if (nedge.first == node2) break; 323 } 415 for (ListIterator<Long> it = role.listIterator(0); it.hasNext();) { 416 Edge nedge = edges.get(it.next()); 417 if (nedge.first == node2) { 418 bound.sides.add(new Side(nedge, true)); 419 it.remove(); 420 if (nedge.last == node2) 421 break; 422 } else if (nedge.last == node2) { 423 bound.sides.add(new Side(nedge, false)); 424 it.remove(); 425 if (nedge.first == node2) 426 break; 427 } 324 428 } 325 429 } … … 344 448 lat = lon = llon = llat = 0; 345 449 double sigma = 0; 346 ListIterator<Long> it; 347 for (Side side : bound.sides) { 348 if (side.forward) { 349 node = nodes.get(side.edge.first); 350 lat = node.lat; 351 lon = node.lon; 352 it = side.edge.nodes.listIterator(); 353 while (it.hasNext()) { 354 llon = lon; 355 llat = lat; 356 node = nodes.get(it.next()); 357 lat = node.lat; 358 lon = node.lon; 359 sigma += (lon * Math.sin(llat)) - (llon * Math.sin(lat)); 360 } 361 llon = lon; 362 llat = lat; 363 node = nodes.get(side.edge.last); 364 lat = node.lat; 365 lon = node.lon; 366 sigma += (lon * Math.sin(llat)) - (llon * Math.sin(lat)); 367 } else { 368 node = nodes.get(side.edge.last); 369 lat = node.lat; 370 lon = node.lon; 371 it = side.edge.nodes.listIterator(side.edge.nodes.size()); 372 while (it.hasPrevious()) { 373 llon = lon; 374 llat = lat; 375 node = nodes.get(it.previous()); 376 lat = node.lat; 377 lon = node.lon; 378 sigma += (lon * Math.sin(llat)) - (llon * Math.sin(lat)); 379 } 380 llon = lon; 381 llat = lat; 382 node = nodes.get(side.edge.first); 383 lat = node.lat; 384 lon = node.lon; 385 sigma += (lon * Math.sin(llat)) - (llon * Math.sin(lat)); 386 } 450 BoundIterator it = new BoundIterator(bound); 451 while (it.hasNext()) { 452 llon = lon; 453 llat = lat; 454 node = it.next(); 455 lat = node.lat; 456 lon = node.lon; 457 sigma += (lon * Math.sin(llat)) - (llon * Math.sin(lat)); 387 458 } 388 459 return sigma; … … 392 463 return (signedArea(bound) < 0); 393 464 } 394 465 395 466 public double calcArea(Bound bound) { 396 467 return Math.abs(signedArea(bound)) * 3444 * 3444 / 2.0; 397 468 } 398 469 399 470 public Snode findCentroid(Feature feature) { 400 401 471 double lat, lon, slat, slon, sarc, llat, llon; 472 lat = lon = slat = slon = sarc = llat = llon = 0; 402 473 switch (feature.flag) { 403 474 case POINT: … … 405 476 case LINE: 406 477 Edge edge = edges.get(feature.refs); 407 llat = nodes.get(edge.first).lat;408 llon = nodes.get(edge.first).lon;409 for (long id : edge.nodes) {410 lat = node s.get(id).lat;411 lon = node s.get(id).lon;412 sarc += (Math.acos(Math.cos(lon -llon) * Math.cos(lat-llat)));478 EdgeIterator eit = new EdgeIterator(edge, true); 479 while (eit.hasNext()) { 480 Snode node = eit.next(); 481 lat = node.lat; 482 lon = node.lon; 483 sarc += (Math.acos(Math.cos(lon - llon) * Math.cos(lat - llat))); 413 484 llat = lat; 414 485 llon = lon; 415 486 } 416 lat = nodes.get(edge.last).lat;417 lon = nodes.get(edge.last).lon;418 sarc += (Math.acos(Math.cos(lon-llon) * Math.cos(lat-llat)));419 487 double harc = sarc / 2; 420 488 sarc = 0; 421 llat = nodes.get(edge.first).lat; 422 llon = nodes.get(edge.first).lon; 423 for (long id : edge.nodes) { 424 lat = nodes.get(id).lat; 425 lon = nodes.get(id).lon; 426 sarc = (Math.acos(Math.cos(lon-llon) * Math.cos(lat-llat))); 427 if (sarc > harc) break; 489 eit = new EdgeIterator(edge, true); 490 while (eit.hasNext()) { 491 Snode node = eit.next(); 492 lat = node.lat; 493 lon = node.lon; 494 sarc = (Math.acos(Math.cos(lon - llon) * Math.cos(lat - llat))); 495 if (sarc > harc) 496 break; 428 497 harc -= sarc; 429 498 llat = lat; 430 499 llon = lon; 431 }432 if (sarc <= harc) {433 lat = nodes.get(edge.last).lat;434 lon = nodes.get(edge.last).lon;435 sarc = (Math.acos(Math.cos(lon-llon) * Math.cos(lat-llat)));436 500 } 437 501 double frac = harc / sarc; … … 439 503 case AREA: 440 504 Bound bound = areas.get(feature.refs).get(0); 441 Snode node; 442 ListIterator<Long> it; 443 for (Side side : bound.sides) { 444 if (side.forward) { 445 node = nodes.get(side.edge.first); 446 lat = node.lat; 447 lon = node.lon; 448 it = side.edge.nodes.listIterator(); 449 while (it.hasNext()) { 450 llon = lon; 451 llat = lat; 452 node = nodes.get(it.next()); 453 lat = node.lat; 454 lon = node.lon; 455 double arc = (Math.acos(Math.cos(lon-llon) * Math.cos(lat-llat))); 456 slat += (lat * arc); 457 slon += (lon * arc); 458 sarc += arc; 459 } 460 llon = lon; 461 llat = lat; 462 node = nodes.get(side.edge.last); 463 lat = node.lat; 464 lon = node.lon; 465 double arc = (Math.acos(Math.cos(lon-llon) * Math.cos(lat-llat))); 466 slat += (lat * arc); 467 slon += (lon * arc); 468 sarc += arc; 469 } else { 470 node = nodes.get(side.edge.last); 471 lat = node.lat; 472 lon = node.lon; 473 it = side.edge.nodes.listIterator(side.edge.nodes.size()); 474 while (it.hasPrevious()) { 475 llon = lon; 476 llat = lat; 477 node = nodes.get(it.previous()); 478 lat = node.lat; 479 lon = node.lon; 480 double arc = (Math.acos(Math.cos(lon-llon) * Math.cos(lat-llat))); 481 slat += (lat * arc); 482 slon += (lon * arc); 483 sarc += arc; 484 } 485 llon = lon; 486 llat = lat; 487 node = nodes.get(side.edge.first); 488 lat = node.lat; 489 lon = node.lon; 490 double arc = (Math.acos(Math.cos(lon-llon) * Math.cos(lat-llat))); 491 slat += (lat * arc); 492 slon += (lon * arc); 493 sarc += arc; 494 } 495 } 496 return new Snode((sarc > 0.0 ? slat/sarc : 0.0), (sarc > 0.0 ? slon/sarc : 0.0)); 505 BoundIterator bit = new BoundIterator(bound); 506 while (bit.hasNext()) { 507 llon = lon; 508 llat = lat; 509 Snode node = bit.next(); 510 lat = node.lat; 511 lon = node.lon; 512 double arc = (Math.acos(Math.cos(lon - llon) * Math.cos(lat - llat))); 513 slat += (lat * arc); 514 slon += (lon * arc); 515 sarc += arc; 516 } 517 return new Snode((sarc > 0.0 ? slat / sarc : 0.0), (sarc > 0.0 ? slon / sarc : 0.0)); 497 518 } 498 519 return null; 499 520 } 500 521 501 522 }
Note:
See TracChangeset
for help on using the changeset viewer.