Changeset 30314 in osm for applications/editors/josm/plugins/smed2
- Timestamp:
- 2014-03-01T18:57:59+01:00 (11 years ago)
- Location:
- applications/editors/josm/plugins/smed2
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/smed2/js57toosm/src/js57toosm/Js57toosm.java
r30298 r30314 104 104 git = map.new GeomIterator(feature.geom); 105 105 while (git.hasComp()) { 106 long way= git.nextComp();107 out.format(" <way id='%d' version='1'>%n", - way);106 long edge = git.nextComp(); 107 out.format(" <way id='%d' version='1'>%n", -edge); 108 108 while (git.hasEdge()) { 109 109 git.nextEdge(); … … 112 112 out.format(" <nd ref='%d'/>%n", -ref); 113 113 } 114 out.format(" <tag k='seamark:type' v=\"%s\"/>%n", type);115 writeAtts(feature, type);116 114 } 115 out.format(" <tag k='seamark:type' v=\"%s\"/>%n", type); 116 writeAtts(feature, type); 117 117 out.format(" </way>%n"); 118 done.add(way);119 118 } 120 119 } else if (feature.geom.prim == Pflag.AREA) { … … 136 135 git = map.new GeomIterator(feature.geom); 137 136 while (git.hasComp()) { 138 git.nextComp(); 137 long ref = git.nextComp(); 138 out.format(" <way id='%d' version='1'>%n", -ref); 139 139 while (git.hasEdge()) { 140 long way = git.nextEdge(); 141 if (!done.contains(way)) { 142 out.format(" <way id='%d' version='1'>%n", -way); 143 while (git.hasNode()) { 144 long ref = git.nextRef(true); 145 out.format(" <nd ref='%d'/>%n", -ref); 146 } 147 out.format(" </way>%n"); 148 done.add(way); 140 git.nextEdge(); 141 while (git.hasNode()) { 142 ref = git.nextRef(); 143 out.format(" <nd ref='%d'/>%n", -ref); 149 144 } 150 145 } 146 out.format(" </way>%n"); 151 147 } 152 148 out.format(" <relation id='%d' version='1'>%n", -map.ref++); 153 149 out.format(" <tag k='type' v='multipolygon'/>%n"); 154 150 git = map.new GeomIterator(feature.geom); 155 int outers = feature.geom. refs.get(0).size;151 int outers = feature.geom.outers; 156 152 while (git.hasComp()) { 157 git.nextComp(); 158 while (git.hasEdge()) { 159 long way = git.nextEdge(); 160 if (outers-- > 0) { 161 out.format(" <member type='way' ref='%d' role='outer'/>%n", -way); 162 } else { 163 out.format(" <member type='way' ref='%d' role='inner'/>%n", -way); 164 } 153 long ref = git.nextComp(); 154 if (outers-- > 0) { 155 out.format(" <member type='way' ref='%d' role='outer'/>%n", -ref); 156 } else { 157 out.format(" <member type='way' ref='%d' role='inner'/>%n", -ref); 165 158 } 166 159 } -
applications/editors/josm/plugins/smed2/src/panels/PanelMain.java
r30298 r30314 47 47 }; 48 48 private JButton importButton = null; 49 JFileChooser ifc = new JFileChooser(Main.pref.get("smed2plugin. file"));49 JFileChooser ifc = new JFileChooser(Main.pref.get("smed2plugin.encinpfile")); 50 50 private ActionListener alImport = new ActionListener() { 51 51 public void actionPerformed(java.awt.event.ActionEvent e) { … … 56 56 if (returnVal == JFileChooser.APPROVE_OPTION) { 57 57 try { 58 Main.pref.put("smed2plugin. file", ifc.getSelectedFile().getPath());58 Main.pref.put("smed2plugin.encinpfile", ifc.getSelectedFile().getPath()); 59 59 Smed2Action.panelS57.startImport(ifc.getSelectedFile()); 60 60 } catch (IOException e1) { -
applications/editors/josm/plugins/smed2/src/panels/PanelS57.java
r30298 r30314 50 50 51 51 public void startImport(File inf) throws IOException { 52 JFileChooser ifc = new JFileChooser(Main.pref.get("smed2plugin.file"));53 52 FileInputStream in = new FileInputStream(inf); 54 53 PanelMain.setStatus("Select OSM types file", Color.yellow); 55 ifc.setCurrentDirectory(inf);54 JFileChooser ifc = new JFileChooser(Main.pref.get("smed2plugin.typesfile")); 56 55 int returnVal = ifc.showOpenDialog(Main.parent); 57 56 if (returnVal == JFileChooser.APPROVE_OPTION) { 58 Main.pref.put("smed2plugin. file", ifc.getSelectedFile().getPath());57 Main.pref.put("smed2plugin.typesfile", ifc.getSelectedFile().getPath()); 59 58 Scanner tin = new Scanner(new FileInputStream(ifc.getSelectedFile())); 60 59 while (tin.hasNext()) { … … 82 81 while ((snode = map.nodes.get(ref)) != null) { 83 82 if (!done.contains(ref)) { 84 Node node = new Node( new LatLon(Math.toDegrees(snode.lat), Math.toDegrees(snode.lon)));85 node.set OsmId(ref, 1);83 Node node = new Node(ref, 1); 84 node.setCoor((new LatLon(Math.toDegrees(snode.lat), Math.toDegrees(snode.lon)))); 86 85 data.addPrimitive(node); 87 86 addKeys(node, feature, type); … … 110 109 Snode snode = map.nodes.get(ref); 111 110 if (!done.contains(ref)) { 112 Node node = new Node( new LatLon(Math.toDegrees(snode.lat), Math.toDegrees(snode.lon)));113 node.set OsmId(ref, 1);111 Node node = new Node(ref, 1); 112 node.setCoor((new LatLon(Math.toDegrees(snode.lat), Math.toDegrees(snode.lon)))); 114 113 data.addPrimitive(node); 115 114 done.add(ref); … … 129 128 way.addNode((Node)data.getPrimitiveById(ref, OsmPrimitiveType.NODE)); 130 129 } 131 addKeys(way, feature, type); 132 } 133 done.add(edge); 130 } 131 addKeys(way, feature, type); 134 132 } 135 133 } else if (feature.geom.prim == Pflag.AREA) { … … 143 141 Snode snode = map.nodes.get(ref); 144 142 if (!done.contains(ref)) { 145 Node node = new Node( new LatLon(Math.toDegrees(snode.lat), Math.toDegrees(snode.lon)));146 node.set OsmId(ref, 1);143 Node node = new Node(ref, 1); 144 node.setCoor((new LatLon(Math.toDegrees(snode.lat), Math.toDegrees(snode.lon)))); 147 145 data.addPrimitive(node); 148 146 done.add(ref); … … 153 151 git = map.new GeomIterator(feature.geom); 154 152 while (git.hasComp()) { 155 git.nextComp(); 156 while (git.hasEdge()) { 157 long edge = git.nextEdge(); 158 if (!done.contains(edge)) { 159 Way way = new Way(edge, 1); 160 data.addPrimitive(way); 161 while (git.hasNode()) { 162 long ref = git.nextRef(true); 163 way.addNode((Node)data.getPrimitiveById(ref, OsmPrimitiveType.NODE)); 164 } 165 done.add(edge); 153 long ref = git.nextComp(); 154 Way way = new Way(ref, 1); 155 data.addPrimitive(way); 156 while (git.hasEdge()) { 157 git.nextEdge(); 158 while (git.hasNode()) { 159 ref = git.nextRef(); 160 way.addNode((Node) data.getPrimitiveById(ref, OsmPrimitiveType.NODE)); 166 161 } 167 162 } … … 170 165 data.addPrimitive(rel); 171 166 git = map.new GeomIterator(feature.geom); 172 int outers = feature.geom.refs.get(0).size; 173 while (git.hasComp()) { 174 git.nextComp(); 175 while (git.hasEdge()) { 176 long way = git.nextEdge(); 177 if (outers-- > 0) { 178 rel.addMember(new RelationMember("outer", (Way)data.getPrimitiveById(way, OsmPrimitiveType.WAY))); 179 } else { 180 rel.addMember(new RelationMember("inner", (Way)data.getPrimitiveById(way, OsmPrimitiveType.WAY))); 181 } 167 int outers = feature.geom.outers; 168 while (git.hasComp()) { 169 long ref = git.nextComp(); 170 if (outers-- > 0) { 171 rel.addMember(new RelationMember("outer", (Way) data.getPrimitiveById(ref, OsmPrimitiveType.WAY))); 172 } else { 173 rel.addMember(new RelationMember("inner", (Way) data.getPrimitiveById(ref, OsmPrimitiveType.WAY))); 182 174 } 183 175 } -
applications/editors/josm/plugins/smed2/src/render/Renderer.java
r30285 r30314 220 220 git.nextComp(); 221 221 boolean first = true; 222 while (git.hasNode()) { 223 prev = next; 224 next = context.getPoint(git.next()); 225 angle = Math.atan2(next.getY() - prev.getY(), next.getX() - prev.getX()); 226 piv = true; 227 if (first) { 228 curr = succ = next; 229 gap = (space > 0); 230 stcount = ratio - 1; 231 symbol = prisymb; 232 len = gap ? psize * space * 0.5 : psize; 233 first = false; 234 } else { 235 while (curr.distance(next) >= len) { 236 if (piv) { 237 double rem = len; 238 double s = prev.distance(next); 239 double p = curr.distance(prev); 240 if ((s > 0) && (p > 0)) { 241 double n = curr.distance(next); 242 double theta = Math.acos((s * s + p * p - n * n) / 2 / s / p); 243 double phi = Math.asin(p / len * Math.sin(theta)); 244 rem = len * Math.sin(Math.PI - theta - phi) / Math.sin(theta); 222 while (git.hasEdge()) { 223 git.nextEdge(); 224 while (git.hasNode()) { 225 prev = next; 226 next = context.getPoint(git.next()); 227 angle = Math.atan2(next.getY() - prev.getY(), next.getX() - prev.getX()); 228 piv = true; 229 if (first) { 230 curr = succ = next; 231 gap = (space > 0); 232 stcount = ratio - 1; 233 symbol = prisymb; 234 len = gap ? psize * space * 0.5 : psize; 235 first = false; 236 } else { 237 while (curr.distance(next) >= len) { 238 if (piv) { 239 double rem = len; 240 double s = prev.distance(next); 241 double p = curr.distance(prev); 242 if ((s > 0) && (p > 0)) { 243 double n = curr.distance(next); 244 double theta = Math.acos((s * s + p * p - n * n) / 2 / s / p); 245 double phi = Math.asin(p / len * Math.sin(theta)); 246 rem = len * Math.sin(Math.PI - theta - phi) / Math.sin(theta); 247 } 248 succ = new Point2D.Double(prev.getX() + (rem * Math.cos(angle)), prev.getY() + (rem * Math.sin(angle))); 249 piv = false; 250 } else { 251 succ = new Point2D.Double(curr.getX() + (len * Math.cos(angle)), curr.getY() + (len * Math.sin(angle))); 245 252 } 246 succ = new Point2D.Double(prev.getX() + (rem * Math.cos(angle)), prev.getY() + (rem * Math.sin(angle))); 247 piv = false; 248 } else { 249 succ = new Point2D.Double(curr.getX() + (len * Math.cos(angle)), curr.getY() + (len * Math.sin(angle))); 250 } 251 if (!gap) { 252 Symbols.drawSymbol(g2, symbol, sScale, curr.getX(), curr.getY(), new Scheme(col), 253 new Delta(Handle.BC, AffineTransform.getRotateInstance(Math.atan2((succ.getY() - curr.getY()), (succ.getX() - curr.getX())) + Math.toRadians(90)))); 254 } 255 if (space > 0) 256 gap = !gap; 257 curr = succ; 258 len = gap ? (psize * space) : (--stcount == 0) ? (stflag ? tsize : ssize) : psize; 259 if (stcount == 0) { 260 symbol = stflag ? tersymb : secsymb; 261 if (trect != null) stflag = !stflag; 262 stcount = ratio; 263 } else { 264 symbol = prisymb; 253 if (!gap) { 254 Symbols.drawSymbol(g2, symbol, sScale, curr.getX(), curr.getY(), new Scheme(col), new Delta(Handle.BC, AffineTransform.getRotateInstance(Math.atan2((succ.getY() - curr.getY()), (succ.getX() - curr.getX())) + Math.toRadians(90)))); 255 } 256 if (space > 0) 257 gap = !gap; 258 curr = succ; 259 len = gap ? (psize * space) : (--stcount == 0) ? (stflag ? tsize : ssize) : psize; 260 if (stcount == 0) { 261 symbol = stflag ? tersymb : secsymb; 262 if (trect != null) 263 stflag = !stflag; 264 stcount = ratio; 265 } else { 266 symbol = prisymb; 267 } 265 268 } 266 269 } … … 278 281 while (git.hasComp()) { 279 282 git.nextComp(); 280 point = context.getPoint(git.next()); 281 p.moveTo(point.getX(), point.getY()); 282 while (git.hasNode()) { 283 while (git.hasEdge()) { 284 git.nextEdge(); 283 285 point = context.getPoint(git.next()); 284 p.lineTo(point.getX(), point.getY()); 286 p.moveTo(point.getX(), point.getY()); 287 while (git.hasNode()) { 288 point = context.getPoint(git.next()); 289 p.lineTo(point.getX(), point.getY()); 290 } 285 291 } 286 292 } … … 353 359 while (git.hasComp()) { 354 360 git.nextComp(); 355 point = context.getPoint(git.next()); 356 p.moveTo(point.getX(), point.getY()); 357 while (git.hasNode()) { 361 while (git.hasEdge()) { 362 git.nextEdge(); 358 363 point = context.getPoint(git.next()); 359 p.lineTo(point.getX(), point.getY()); 364 p.moveTo(point.getX(), point.getY()); 365 while (git.hasNode()) { 366 point = context.getPoint(git.next()); 367 p.lineTo(point.getX(), point.getY()); 368 } 360 369 } 361 370 } … … 500 509 git.nextComp(); 501 510 boolean first = true; 502 while (git.hasNode()) { 503 prev = next; 504 next = context.getPoint(git.next()); 505 angle = Math.atan2(next.getY() - prev.getY(), next.getX() - prev.getX()); 506 piv = true; 507 if (first) { 508 curr = succ = next; 509 // len = psize; 510 first = false; 511 } else { 512 while (curr.distance(next) >= len) { 513 if (piv) { 514 double rem = len; 515 double s = prev.distance(next); 516 double p = curr.distance(prev); 517 if ((s > 0) && (p > 0)) { 518 double n = curr.distance(next); 519 double theta = Math.acos((s * s + p * p - n * n) / 2 / s / p); 520 double phi = Math.asin(p / len * Math.sin(theta)); 521 rem = len * Math.sin(Math.PI - theta - phi) / Math.sin(theta); 511 while (git.hasEdge()) { 512 git.nextEdge(); 513 while (git.hasNode()) { 514 prev = next; 515 next = context.getPoint(git.next()); 516 angle = Math.atan2(next.getY() - prev.getY(), next.getX() - prev.getX()); 517 piv = true; 518 if (first) { 519 curr = succ = next; 520 // len = psize; 521 first = false; 522 } else { 523 while (curr.distance(next) >= len) { 524 if (piv) { 525 double rem = len; 526 double s = prev.distance(next); 527 double p = curr.distance(prev); 528 if ((s > 0) && (p > 0)) { 529 double n = curr.distance(next); 530 double theta = Math.acos((s * s + p * p - n * n) / 2 / s / p); 531 double phi = Math.asin(p / len * Math.sin(theta)); 532 rem = len * Math.sin(Math.PI - theta - phi) / Math.sin(theta); 533 } 534 succ = new Point2D.Double(prev.getX() + (rem * Math.cos(angle)), prev.getY() + (rem * Math.sin(angle))); 535 piv = false; 536 } else { 537 succ = new Point2D.Double(curr.getX() + (len * Math.cos(angle)), curr.getY() + (len * Math.sin(angle))); 522 538 } 523 succ = new Point2D.Double(prev.getX() + (rem * Math.cos(angle)), prev.getY() + (rem * Math.sin(angle))); 524 piv = false; 525 } else { 526 succ = new Point2D.Double(curr.getX() + (len * Math.cos(angle)), curr.getY() + (len * Math.sin(angle))); 539 // Symbols.drawSymbol(g2, symbol, sScale, curr.getX(), 540 // curr.getY(), new Delta(Handle.BC, 541 // AffineTransform.getRotateInstance(Math.atan2((succ.getY() - 542 // curr.getY()), (succ.getX() - curr.getX())) + 543 // Math.toRadians(90))), null); 544 curr = succ; 545 // len = psize; 527 546 } 528 // Symbols.drawSymbol(g2, symbol, sScale, curr.getX(), curr.getY(), new Delta(Handle.BC, AffineTransform.getRotateInstance(Math.atan2((succ.getY() - curr.getY()), (succ.getX() - curr.getX())) + Math.toRadians(90))), null);529 curr = succ;530 // len = psize;531 547 } 532 548 } -
applications/editors/josm/plugins/smed2/src/render/Rules.java
r30285 r30314 628 628 Renderer.symbol(feature, Harbours.Post); 629 629 break; 630 default: 631 break; 630 632 } 631 633 Signals.addSignals(feature); -
applications/editors/josm/plugins/smed2/src/s57/S57map.java
r30285 r30314 171 171 } 172 172 173 public class Comp { 174 public long ref; 175 public int size; 173 public class Comp { // Composite spatial element 174 public long ref; // ID of Comp 175 public int size; // Number of Prims in this Comp 176 176 public Comp(long r, int s) { 177 177 ref = r; … … 316 316 for (long id : index.keySet()) { 317 317 Feature feature = index.get(id); 318 if ((feature.geom.prim == Pflag.LINE) || (feature.geom.prim == Pflag.AREA)) { 319 feature.geom.outers = 1; 320 feature.geom.inners = 0; 321 feature.geom.refs = new ArrayList<Comp>(); 322 Comp comp = new Comp(ref++, 0); 323 feature.geom.refs.add(comp); 324 ListIterator<S57map.Prim> ite = feature.geom.elems.listIterator(); 325 long first = 0; 326 while (ite.hasNext()) { 327 Prim prim = ite.next(); 328 Edge edge = edges.get(prim.id); 329 if (!prim.outer) { 330 if (first == 0) { 331 feature.geom.inners++; 332 comp = new Comp(ref++, 0); 333 feature.geom.refs.add(comp); 334 first = edge.first; 335 } else { 336 if (edge.last == first) { 337 first = 0; 338 } 339 } 340 } 341 comp.size++; 342 } 343 } 344 } 345 for (long id : index.keySet()) { 346 Feature feature = index.get(id); 318 sortGeom(feature); 347 319 for (Reln reln : feature.rels) { 348 320 Feature rel = index.get(reln.id); … … 426 398 feature.reln = Rflag.UNKN; 427 399 feature.geom.prim = Pflag.AREA; 428 feature.geom.elems.add(new Prim(id));429 400 edge = null; 430 401 } … … 503 474 nodes.get(edge.first).flg = Nflag.CONN; 504 475 nodes.get(edge.last).flg = Nflag.CONN; 505 feature.geom.length = calcLength(feature.geom);506 476 if (edge.first == edge.last) { 507 477 feature.geom.prim = Pflag.AREA; 478 } 479 sortGeom(feature); 480 feature.geom.length = calcLength(feature.geom); 481 if (feature.geom.prim == Pflag.AREA) { 508 482 feature.geom.area = calcArea(feature.geom); 509 483 } else { … … 512 486 break; 513 487 case AREA: 488 sortGeom(feature); 489 feature.geom.length = calcLength(feature.geom); 490 feature.geom.area = calcArea(feature.geom); 514 491 break; 515 492 default: … … 528 505 // Utility methods 529 506 530 public void sortGeom() { 531 for (long id : index.keySet()) { 532 feature = index.get(id); 533 Geom sort = new Geom(feature.geom.prim); 534 long first = 0; 535 long last = 0; 536 Comp comp = null; 537 boolean next = true; 538 if ((feature.geom.prim == Pflag.LINE) || (feature.geom.prim == Pflag.AREA)) { 539 int sweep = feature.geom.elems.size(); 540 while (!feature.geom.elems.isEmpty()) { 541 Prim prim = feature.geom.elems.remove(0); 542 Edge edge = edges.get(prim.id); 543 if (next == true) { 544 next = false; 545 if (prim.forward) { 507 public void sortGeom(Feature feature) { 508 Geom sort = new Geom(feature.geom.prim); 509 long first = 0; 510 long last = 0; 511 Comp comp = null; 512 boolean next = true; 513 if ((feature.geom.prim == Pflag.LINE) || (feature.geom.prim == Pflag.AREA)) { 514 int sweep = feature.geom.elems.size(); 515 while (!feature.geom.elems.isEmpty()) { 516 Prim prim = feature.geom.elems.remove(0); 517 Edge edge = edges.get(prim.id); 518 if (next == true) { 519 next = false; 520 if (prim.forward) { 521 first = edge.first; 522 last = edge.last; 523 } else { 524 first = edge.last; 525 last = edge.first; 526 } 527 sort.elems.add(prim); 528 if (prim.outer) { 529 sort.outers++; 530 } else { 531 sort.inners++; 532 } 533 comp = new Comp(ref++, 1); 534 sort.refs.add(comp); 535 } else { 536 if (prim.forward) { 537 if (edge.first == last) { 538 sort.elems.add(prim); 539 last = edge.last; 540 comp.size++; 541 } else if (edge.last == first) { 542 sort.elems.add(0, prim); 546 543 first = edge.first; 547 last = edge.last;544 comp.size++; 548 545 } else { 549 first = edge.last; 550 last = edge.first; 551 } 552 sort.elems.add(prim); 553 if (prim.outer) { 554 sort.outers++; 555 } else { 556 sort.inners++; 557 } 558 comp = new Comp(ref++, 1); 559 sort.refs.add(comp); 560 } else { 561 if (prim.forward) { 562 if (edge.first == last) { 563 sort.elems.add(prim); 564 last = edge.last; 565 comp.size++; 566 } else if (edge.last == first) { 567 sort.elems.add(0, prim); 568 first = edge.first; 569 comp.size++; 570 } else { 571 feature.geom.elems.add(prim); 572 } 573 } else { 574 if (edge.last == last) { 575 sort.elems.add(prim); 576 last = edge.first; 577 comp.size++; 578 } else if (edge.first == first) { 579 sort.elems.add(0, prim); 580 first = edge.last; 581 comp.size++; 582 } else { 583 feature.geom.elems.add(prim); 584 } 585 } 586 } 587 if (--sweep == 0) { 588 next = true; 589 sweep = feature.geom.elems.size(); 590 } 591 } 592 if ((sort.prim == Pflag.LINE) && (sort.outers == 1) && (sort.inners == 0) && (first == last)) { 593 sort.prim = Pflag.AREA; 594 } 595 feature.geom = sort; 596 } 597 if (feature.geom.prim == Pflag.AREA) { 598 ArrayList<Prim> outers = new ArrayList<Prim>(); 599 ArrayList<Prim> inners = new ArrayList<Prim>(); 600 for (Prim prim : feature.geom.elems) { 601 if (prim.outer) { 602 outers.add(prim); 603 } else { 604 inners.add(prim); 605 } 606 } 607 ArrayList<Prim> sorting = outers; 608 ArrayList<Prim> closed = null; 609 sort = new Geom(feature.geom.prim); 610 sort.outers = feature.geom.outers; 611 sort.inners = feature.geom.inners; 612 sort.refs = feature.geom.refs; 613 next = true; 614 while (!sorting.isEmpty()) { 615 Prim prim = sorting.remove(0); 616 Edge edge = edges.get(prim.id); 617 if (next == true) { 618 next = false; 619 closed = new ArrayList<Prim>(); 620 closed.add(prim); 621 if (prim.forward) { 622 first = edge.first; 623 last = edge.last; 624 } else { 625 first = edge.last; 626 last = edge.first; 546 feature.geom.elems.add(prim); 627 547 } 628 548 } else { 629 if ( prim.forward) {630 if (edge.first == last) {631 last = edge.last;632 closed.add(prim);633 } else{634 sorting.add(0, prim);635 next = true;636 }549 if (edge.last == last) { 550 sort.elems.add(prim); 551 last = edge.first; 552 comp.size++; 553 } else if (edge.first == first) { 554 sort.elems.add(0, prim); 555 first = edge.last; 556 comp.size++; 637 557 } else { 638 if (edge.last == last) { 639 last = edge.first; 640 closed.add(prim); 641 } else { 642 sorting.add(0, prim); 643 next = true; 644 } 558 feature.geom.elems.add(prim); 645 559 } 646 560 } 647 if (first == last) { 648 sort.elems.addAll(closed); 649 next = true; 650 } 651 if (sorting.isEmpty() && sorting == outers) { 652 sorting = inners; 653 next = true; 654 } 655 } 656 feature.geom = sort; 657 } 561 } 562 if (--sweep == 0) { 563 next = true; 564 sweep = feature.geom.elems.size(); 565 } 566 } 567 if ((sort.prim == Pflag.LINE) && (sort.outers == 1) && (sort.inners == 0) && (first == last)) { 568 sort.prim = Pflag.AREA; 569 } 570 feature.geom = sort; 571 } 572 if (feature.geom.prim == Pflag.AREA) { 573 ArrayList<Prim> outers = new ArrayList<Prim>(); 574 ArrayList<Prim> inners = new ArrayList<Prim>(); 575 for (Prim prim : feature.geom.elems) { 576 if (prim.outer) { 577 outers.add(prim); 578 } else { 579 inners.add(prim); 580 } 581 } 582 ArrayList<Prim> sorting = outers.size() > 0 ? outers : inners; 583 ArrayList<Prim> closed = null; 584 sort = new Geom(feature.geom.prim); 585 sort.outers = feature.geom.outers; 586 sort.inners = feature.geom.inners; 587 sort.refs = feature.geom.refs; 588 next = true; 589 while (!sorting.isEmpty()) { 590 Prim prim = sorting.remove(0); 591 Edge edge = edges.get(prim.id); 592 if (next == true) { 593 next = false; 594 closed = new ArrayList<Prim>(); 595 closed.add(prim); 596 if (prim.forward) { 597 first = edge.first; 598 last = edge.last; 599 } else { 600 first = edge.last; 601 last = edge.first; 602 } 603 } else { 604 if (prim.forward) { 605 if (edge.first == last) { 606 last = edge.last; 607 closed.add(prim); 608 } else { 609 sorting.add(0, prim); 610 next = true; 611 } 612 } else { 613 if (edge.last == last) { 614 last = edge.first; 615 closed.add(prim); 616 } else { 617 sorting.add(0, prim); 618 next = true; 619 } 620 } 621 } 622 if (first == last) { 623 sort.elems.addAll(closed); 624 next = true; 625 } 626 if (sorting.isEmpty() && sorting == outers) { 627 sorting = inners; 628 next = true; 629 } 630 } 631 feature.geom = sort; 658 632 } 659 633 } … … 779 753 lat = lon = llon = llat = 0; 780 754 double sigma = 0; 781 GeomIterator it = new GeomIterator(geom); 782 it.nextComp(); 783 while (it.hasNode()) { 784 llon = lon; 785 llat = lat; 786 node = it.next(); 787 lat = node.lat; 788 lon = node.lon; 789 sigma += (lon * Math.sin(llat)) - (llon * Math.sin(lat)); 755 GeomIterator git = new GeomIterator(geom); 756 if (git.hasComp()) { 757 git.nextComp(); 758 while (git.hasEdge()) { 759 git.nextEdge(); 760 while (git.hasNode()) { 761 llon = lon; 762 llat = lat; 763 node = git.next(); 764 lat = node.lat; 765 lon = node.lon; 766 sigma += (lon * Math.sin(llat)) - (llon * Math.sin(lat)); 767 } 768 } 790 769 } 791 770 return sigma / 2.0; … … 805 784 lat = lon = llon = llat = 0; 806 785 double sigma = 0; 807 GeomIterator it = new GeomIterator(geom); 808 it.nextComp(); 809 if (it.hasNode()) { 810 node = it.next(); 811 lat = node.lat; 812 lon = node.lon; 813 while (it.hasNode()) { 814 llon = lon; 815 llat = lat; 816 node = it.next(); 817 lat = node.lat; 818 lon = node.lon; 819 sigma += Math.acos(Math.sin(lat) * Math.sin(llat) + Math.cos(lat) * Math.cos(llat) * Math.cos(llon - lon)); 786 boolean first = true; 787 GeomIterator git = new GeomIterator(geom); 788 while (git.hasComp()) { 789 git.nextComp(); 790 while (git.hasEdge()) { 791 git.nextEdge(); 792 while (git.hasNode()) { 793 node = git.next(); 794 if (first) { 795 first = false; 796 lat = node.lat; 797 lon = node.lon; 798 } else { 799 llat = lat; 800 llon = lon; 801 lat = node.lat; 802 lon = node.lon; 803 sigma += Math.acos(Math.sin(lat) * Math.sin(llat) + Math.cos(lat) * Math.cos(llat) * Math.cos(llon - lon)); 804 } 805 } 820 806 } 821 807 } … … 832 818 return nodes.get(feature.geom.elems.get(0).id); 833 819 case LINE: 834 GeomIterator it = new GeomIterator(feature.geom); 835 it.nextComp(); 836 while (it.hasNode()) { 837 Snode node = it.next(); 838 lat = node.lat; 839 lon = node.lon; 840 if (first) { 841 first = false; 842 } else { 843 sarc += (Math.acos(Math.cos(lon - llon) * Math.cos(lat - llat))); 844 } 845 llat = lat; 846 llon = lon; 820 GeomIterator git = new GeomIterator(feature.geom); 821 while (git.hasComp()) { 822 git.nextComp(); 823 while (git.hasEdge()) { 824 git.nextEdge(); 825 while (git.hasNode()) { 826 Snode node = git.next(); 827 lat = node.lat; 828 lon = node.lon; 829 if (first) { 830 first = false; 831 } else { 832 sarc += (Math.acos(Math.cos(lon - llon) * Math.cos(lat - llat))); 833 } 834 llat = lat; 835 llon = lon; 836 } 837 } 847 838 } 848 839 double harc = sarc / 2; 849 840 sarc = 0; 850 841 first = true; 851 it = new GeomIterator(feature.geom); 852 while (it.hasNode()) { 853 it.nextComp(); 854 Snode node = it.next(); 855 lat = node.lat; 856 lon = node.lon; 857 if (first) { 858 first = false; 859 } else { 860 sarc = (Math.acos(Math.cos(lon - llon) * Math.cos(lat - llat))); 861 if (sarc > harc) 862 break; 863 } 864 harc -= sarc; 865 llat = lat; 866 llon = lon; 842 git = new GeomIterator(feature.geom); 843 while (git.hasComp()) { 844 git.nextComp(); 845 while (git.hasEdge()) { 846 git.nextEdge(); 847 while (git.hasNode()) { 848 git.nextComp(); 849 Snode node = git.next(); 850 lat = node.lat; 851 lon = node.lon; 852 if (first) { 853 first = false; 854 } else { 855 sarc = (Math.acos(Math.cos(lon - llon) * Math.cos(lat - llat))); 856 if (sarc > harc) 857 break; 858 } 859 harc -= sarc; 860 llat = lat; 861 llon = lon; 862 } 863 } 867 864 } 868 865 return new Snode(llat + ((lat - llat) * harc / sarc), llon + ((lon - llon) * harc / sarc)); 869 866 case AREA: 870 GeomIterator bit = new GeomIterator(feature.geom); 871 bit.nextComp(); 872 while (bit.hasNode()) { 873 Snode node = bit.next(); 874 lat = node.lat; 875 lon = node.lon; 876 if (first) { 877 first = false; 878 } else { 879 double arc = (Math.acos(Math.cos(lon - llon) * Math.cos(lat - llat))); 880 slat += ((lat + llat) / 2 * arc); 881 slon += ((lon + llon) / 2 * arc); 882 sarc += arc; 883 } 884 llon = lon; 885 llat = lat; 867 git = new GeomIterator(feature.geom); 868 while (git.hasComp()) { 869 git.nextComp(); 870 while (git.hasEdge()) { 871 git.nextEdge(); 872 while (git.hasNode()) { 873 Snode node = git.next(); 874 lat = node.lat; 875 lon = node.lon; 876 if (first) { 877 first = false; 878 } else { 879 double arc = (Math.acos(Math.cos(lon - llon) * Math.cos(lat - llat))); 880 slat += ((lat + llat) / 2 * arc); 881 slon += ((lon + llon) / 2 * arc); 882 sarc += arc; 883 } 884 llon = lon; 885 llat = lat; 886 } 887 } 886 888 } 887 889 return new Snode((sarc > 0.0 ? slat / sarc : 0.0), (sarc > 0.0 ? slon / sarc : 0.0)); -
applications/editors/josm/plugins/smed2/src/smed2/MapImage.java
r30285 r30314 34 34 public class MapImage extends ImageryLayer implements ZoomChangeListener, MapContext { 35 35 36 private Smed2Action dlg;37 38 36 double top; 39 37 double bottom; … … 44 42 int zoom; 45 43 46 public MapImage(ImageryInfo info , Smed2Action d) {44 public MapImage(ImageryInfo info) { 47 45 super(info); 48 dlg = d;49 46 MapView.addZoomChangeListener(this); 50 47 zoomChanged(); … … 79 76 g2.setFont(new Font("Arial", Font.BOLD, 20)); 80 77 g2.drawString(("Z" + zoom), (rect.x + rect.width - 40), (rect.y + rect.height - 10)); 81 Renderer.reRender(g2, zoom, Math.pow(2, (zoom-12)), dlg.map, this);78 Renderer.reRender(g2, zoom, Math.pow(2, (zoom-12)), Smed2Action.map, this); 82 79 } 83 80 -
applications/editors/josm/plugins/smed2/src/smed2/Smed2Action.java
r30298 r30314 134 134 135 135 // System.out.println("hello"); 136 rendering = new MapImage(new ImageryInfo("OpenSeaMap") , this);136 rendering = new MapImage(new ImageryInfo("OpenSeaMap")); 137 137 rendering.setBackgroundLayer(true); 138 138 Main.main.addLayer(rendering); … … 162 162 newLayer.data.addDataSetListener(dataSetListener); 163 163 data = newLayer.data; 164 //makeMap();164 makeMap(); 165 165 } else { 166 166 data = null; … … 184 184 Feature id = map.index.get(feature.getUniqueId()); 185 185 if (id != null) { 186 //panelMain.parseMark(id);186 panelMain.parseMark(id); 187 187 showFrame.setVisible(true); 188 188 showFrame.showFeature(feature, map); … … 214 214 } 215 215 for (Way way : data.getWays()) { 216 map.addEdge(way.getUniqueId()); 217 for (Node node : way.getNodes()) { 218 map.addToEdge((node.getUniqueId())); 219 } 220 for (Entry<String, String> entry : way.getKeys().entrySet()) { 221 map.addTag(entry.getKey(), entry.getValue()); 222 } 223 map.tagsDone(way.getUniqueId()); 216 if (way.getNodesCount() > 0) { 217 map.addEdge(way.getUniqueId()); 218 for (Node node : way.getNodes()) { 219 map.addToEdge((node.getUniqueId())); 220 } 221 for (Entry<String, String> entry : way.getKeys().entrySet()) { 222 map.addTag(entry.getKey(), entry.getValue()); 223 } 224 map.tagsDone(way.getUniqueId()); 225 } 224 226 } 225 227 for (Relation rel : data.getRelations()) { 226 if (rel.isMultipolygon() ) {228 if (rel.isMultipolygon() && (rel.getMembersCount() > 0)) { 227 229 map.addArea(rel.getUniqueId()); 228 230 for (RelationMember mem : rel.getMembers()) { … … 230 232 map.addToArea(mem.getUniqueId(), (mem.getRole().equals("outer"))); 231 233 } 232 }233 for (Entry<String, String> entry : rel.getKeys().entrySet()) {234 map.addTag(entry.getKey(), entry.getValue());235 }236 map.tagsDone(rel.getUniqueId());234 for (Entry<String, String> entry : rel.getKeys().entrySet()) { 235 map.addTag(entry.getKey(), entry.getValue()); 236 } 237 map.tagsDone(rel.getUniqueId()); 238 } 237 239 } 238 240 if (rendering != null) rendering.zoomChanged();
Note:
See TracChangeset
for help on using the changeset viewer.