Changeset 30226 in osm for applications/editors/josm/plugins
- Timestamp:
- 2014-01-25T17:56:23+01:00 (11 years ago)
- Location:
- applications/editors/josm/plugins/smed2
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/smed2/jrender/src/jrender/Jrender.java
r30184 r30226 11 11 12 12 import java.io.File; 13 import java.io.FileOutputStream; 14 import java.io.IOException; 15 import java.io.OutputStreamWriter; 16 import java.io.Writer; 17 import java.util.ArrayList; 13 18 import java.awt.Color; 19 import java.awt.Dimension; 14 20 import java.awt.Graphics; 15 21 import java.awt.Graphics2D; … … 21 27 import javax.swing.JFrame; 22 28 29 import org.apache.batik.svggen.SVGGraphics2D; 30 import org.apache.batik.svggen.SVGGraphics2DIOException; 31 import org.apache.batik.dom.GenericDOMImplementation; 32 import org.w3c.dom.Document; 33 import org.w3c.dom.DOMImplementation; 34 23 35 import symbols.*; 24 import symbols.Symbols. Scheme;36 import symbols.Symbols.*; 25 37 import render.*; 26 38 27 39 public class Jrender extends Panel { 28 private static final long serialVersionUID = 1L;29 40 30 41 public static void main(String[] args) { … … 38 49 frame.setSize(256, 256); 39 50 frame.setVisible(true); 40 /*41 for (int x = 0; x < 4; x++) {42 for (int y = 0; y < 4; y++) {43 img = new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB);44 g2 = img.createGraphics();45 g2.translate(-(x*256), -(y*256));46 drawRendering(g2);47 try {48 ImageIO.write(img, "png", new File("tst" + x + "_" + y + ".png"));49 } catch (IOException e) {50 System.out.println("IO Exception");51 }52 }53 }*/54 51 55 img = new BufferedImage( 64, 64, BufferedImage.TYPE_INT_ARGB);52 img = new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB); 56 53 g2 = img.createGraphics(); 57 g2.translate(-32, -32);58 54 drawRendering(g2); 59 55 try { … … 63 59 } 64 60 61 DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation(); 62 String svgNS = "http://www.w3.org/2000/svg"; 63 Document document = domImpl.createDocument(svgNS, "svg", null); 64 SVGGraphics2D svgGenerator = new SVGGraphics2D(document); 65 svgGenerator.setSVGCanvasSize(new Dimension(256, 256)); 66 drawRendering(svgGenerator); 67 boolean useCSS = true; 68 Writer out = null; 69 try { 70 out = new OutputStreamWriter(new FileOutputStream("/Users/mherring/Desktop/export.svg"), "UTF-8"); 71 } catch (IOException e1) { 72 System.out.println("Exception"); 73 } 74 try { 75 svgGenerator.stream(out, useCSS); 76 } catch (SVGGraphics2DIOException e) { 77 System.out.println("Exception"); 78 } 65 79 } 66 80 67 81 public static void drawRendering(Graphics2D g2) { 68 double scale = Renderer.symbolScale[ 7];82 double scale = Renderer.symbolScale[8]; 69 83 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 70 84 g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP); 71 // System.out.println("hello"); 72 73 Symbols.drawSymbol(g2, Areas.Seaplane, scale/2, 64.0, 64.0, new Scheme(Color.green), null); 85 Scheme scheme = new Scheme(); scheme.pat.add(Patt.H); scheme.col.add(Color.red); scheme.col.add(Color.yellow); scheme.col.add(Color.green); 86 Symbols.drawSymbol(g2, Buoys.Pillar, scale, 128.0, 128.0, scheme, null); 74 87 } 75 88 -
applications/editors/josm/plugins/smed2/js57toosm/src/js57toosm/Js57toosm.java
r30215 r30226 25 25 public class Js57toosm { 26 26 27 static FileInputStream in; 28 static PrintStream out; 29 static S57map map; 30 27 31 public static void main(String[] args) throws IOException { 28 32 29 FileInputStream in = new FileInputStream("/Users/mherring/boatsw/oseam/josm/plugins/smed2/js57toosm/tst.000"); 30 PrintStream out = System.out; 33 in = new FileInputStream("/Users/mherring/boatsw/oseam/josm/plugins/smed2/js57toosm/tst.000"); 34 out = System.out; 35 map = new S57map(); 31 36 32 37 S57dat.rnum = 0; … … 48 53 S57map.Pflag prim = S57map.Pflag.NOSP; 49 54 long objl = 0; 50 S57map map = new S57map();51 55 double minlat = 90, minlon = 180, maxlat = -90, maxlon = -180; 52 56 … … 206 210 if (feature.reln != Rflag.SLAVE) { 207 211 if (feature.geom.prim == Pflag.POINT) { 208 Snode node = map.nodes.get(feature.geom.elems.get(0).id); 212 long ref = feature.geom.elems.get(0).id; 213 Snode node = map.nodes.get(ref); 209 214 String type = S57obj.stringType(feature.type); 210 out.format(" <node id='%d' lat='%f' lon='%f' version='1'>%n", -id, Math.toDegrees(node.lat), Math.toDegrees(node.lon));215 out.format(" <node id='%d' lat='%f' lon='%f' version='1'>%n", -ref, Math.toDegrees(node.lat), Math.toDegrees(node.lon)); 211 216 out.format(" <tag k='seamark:type' v=\"%s\"/>%n", type); 212 for (Map.Entry<Att, AttVal<?>> item : feature.atts.entrySet()) { 213 out.format(" <tag k='seamark:%s:%s' v=\"%s\"/>%n", type, S57att.stringAttribute(item.getKey()), S57val.stringValue(item.getValue())); 217 writeAtts(feature, type); 218 out.format(" </node>%n"); 219 map.nodes.remove(ref); 220 } 221 } 222 } 223 224 for (long id : map.index.keySet()) { 225 Feature feature = map.index.get(id); 226 if (feature.reln != Rflag.SLAVE) { 227 if (feature.geom.prim == Pflag.LINE) { 228 GeomIterator git = map.new GeomIterator(feature.geom); 229 while (git.hasMore()) { 230 git.more(); 231 while (git.hasNext()) { 232 long ref = git.nextRef(); 233 Snode node = map.nodes.get(ref); 234 if (node != null) { 235 out.format(" <node id='%d' lat='%f' lon='%f' version='1'/>%n", -ref, Math.toDegrees(node.lat), Math.toDegrees(node.lon)); 236 map.nodes.remove(ref); 237 } 238 } 214 239 } 215 for (Reln rel : feature.rels) {216 if (rel.reln == Rflag.SLAVE) {217 Feature slave = map.index.get(rel.id);218 type = S57obj.stringType(slave.type);219 for (Map.Entry<Att, AttVal<?>> item : slave.atts.entrySet()) {220 out.format(" <tag k='seamark:%s:%s' v=\"%s\"/>%n", type, S57att.stringAttribute(item.getKey()), S57val.stringValue(item.getValue()));221 }240 out.format(" <way id='%d' version='1'>%n", -id); 241 git = map.new GeomIterator(feature.geom); 242 while (git.hasMore()) { 243 git.more(); 244 while (git.hasNext()) { 245 long ref = git.nextRef(); 246 out.format(" <nd ref='%d'/>%n", -ref); 222 247 } 223 248 } 224 out.format(" </node>%n"); 225 } 226 } 227 } 228 /* 229 for (long id : map.nodes.keySet()) { 249 String type = S57obj.stringType(feature.type); 250 out.format(" <tag k='seamark:type' v=\"%s\"/>%n", type); 251 writeAtts(feature, type); 252 out.format(" </way>%n"); 253 } 254 } 255 } 256 /* for (long id : map.nodes.keySet()) { 230 257 Snode node = map.nodes.get(id); 231 258 if (node.flg == S57map.Nflag.DPTH) { … … 234 261 out.format(" <tag k='seamark:sounding:depth' v='%.1f'/>%n", ((Dnode)node).val); 235 262 out.format(" </node>%n"); 236 } else { 237 out.format(" <node id='%d' lat='%f' lon='%f' version='1'/>%n",-id, Math.toDegrees(node.lat), Math.toDegrees(node.lon)); 263 map.nodes.remove(id); 238 264 } 239 265 } … … 252 278 out.println("</osm>\n"); 253 279 } 280 281 static void writeAtts(Feature feature, String type) { 282 for (Map.Entry<Att, AttVal<?>> item : feature.atts.entrySet()) { 283 String attstr = S57att.stringAttribute(item.getKey()); 284 String valstr = S57val.stringValue(item.getValue()); 285 if (!attstr.isEmpty() && !valstr.isEmpty()) 286 out.format(" <tag k='seamark:%s:%s' v=\"%s\"/>%n", type, attstr, valstr); 287 } 288 for (Reln rel : feature.rels) { 289 if (rel.reln == Rflag.SLAVE) { 290 Feature slave = map.index.get(rel.id); 291 type = S57obj.stringType(slave.type); 292 for (Map.Entry<Att, AttVal<?>> item : slave.atts.entrySet()) { 293 String attstr = S57att.stringAttribute(item.getKey()); 294 String valstr = S57val.stringValue(item.getValue()); 295 if (!attstr.isEmpty() && !valstr.isEmpty()) 296 out.format(" <tag k='seamark:%s:%s' v=\"%s\"/>%n", type, attstr, valstr); 297 } 298 } 299 } 300 301 } 254 302 255 303 } -
applications/editors/josm/plugins/smed2/src/s57/S57att.java
r30215 r30226 50 50 AttS57.put(Att.ORIENT, 117); AttS57.put(Att.PEREND, 118); AttS57.put(Att.PERSTA, 119); AttS57.put(Att.PICREP, 120); AttS57.put(Att.PILDST, 121); AttS57.put(Att.PRCTRY, 122); 51 51 AttS57.put(Att.PRODCT, 123); AttS57.put(Att.PUBREF, 124); AttS57.put(Att.QUASOU, 125); AttS57.put(Att.RADWAL, 126); AttS57.put(Att.RADIUS, 127); AttS57.put(Att.RECDAT, 128); 52 AttS57.put(Att.RECIND, 129); AttS57.put(Att.RYRMGV, 130); AttS57.put(Att.RESTRN, 131); AttS57.put(Att.SCAMIN, 133);53 AttS57.put(Att.S ECTR1, 136); AttS57.put(Att.SECTR2, 137); AttS57.put(Att.SHIPAM, 138);52 AttS57.put(Att.RECIND, 129); AttS57.put(Att.RYRMGV, 130); AttS57.put(Att.RESTRN, 131); AttS57.put(Att.SCAMAX, 132); AttS57.put(Att.SCAMIN, 133); AttS57.put(Att.SCVAL1, 134); 53 AttS57.put(Att.SCVAL2, 135); AttS57.put(Att.SECTR1, 136); AttS57.put(Att.SECTR2, 137); AttS57.put(Att.SHIPAM, 138); 54 54 AttS57.put(Att.SIGFRQ, 139); AttS57.put(Att.SIGGEN, 140); AttS57.put(Att.SIGGRP, 141); AttS57.put(Att.SIGPER, 142); AttS57.put(Att.SIGSEQ, 143); AttS57.put(Att.SOUACC, 144); 55 55 AttS57.put(Att.SDISMX, 145); AttS57.put(Att.SDISMN, 146); AttS57.put(Att.SORDAT, 147); AttS57.put(Att.SORIND, 148); AttS57.put(Att.STATUS, 149); AttS57.put(Att.SURATH, 150); … … 152 152 AttStr.put(Att.CATVTR, "category"); AttStr.put(Att.CATTAB, "operation"); AttStr.put(Att.SCHREF, "schedule"); AttStr.put(Att.USESHP, "use"); AttStr.put(Att.CURVHW, "high_velocity"); 153 153 AttStr.put(Att.CURVLW, "low_velocity"); AttStr.put(Att.CURVMW, "mean_velocity"); AttStr.put(Att.CURVOW, "other_velocity"); AttStr.put(Att.APTREF, "passing_time"); 154 AttStr.put(Att.CATCOM, "category"); AttStr.put(Att.CATCVR, "category"); AttStr.put(Att.SCAMIN, "scale_minimum");154 AttStr.put(Att.CATCOM, "category"); AttStr.put(Att.CATCVR, "category"); 155 155 AttStr.put(Att.CATEXS, "category"); AttStr.put(Att.CATWWM, "category"); AttStr.put(Att.SHPTYP, "ship"); AttStr.put(Att.UPDMSG, "message"); AttStr.put(Att.LITRAD, "radius"); 156 156 } -
applications/editors/josm/plugins/smed2/src/s57/S57map.java
r30215 r30226 319 319 } 320 320 } 321 sortGeom(); 321 322 } 322 323 … … 450 451 // Utility methods 451 452 453 public void sortGeom() { 454 for (long id : index.keySet()) { 455 feature = index.get(id); 456 Geom geom = feature.geom; 457 Geom sort = new Geom(geom.prim); 458 long first = 0; 459 long last = 0; 460 boolean next = true; 461 if ((geom.prim == Pflag.LINE) || (geom.prim == Pflag.AREA)) { 462 int sweep = geom.elems.size(); 463 while (!geom.elems.isEmpty()) { 464 Prim prim = geom.elems.remove(0); 465 Edge edge = edges.get(prim.id); 466 if (next == true) { 467 next = false; 468 if (prim.forward) { 469 first = edge.first; 470 last = edge.last; 471 } else { 472 first = edge.last; 473 last = edge.first; 474 } 475 sort.elems.add(prim); 476 } else { 477 if (prim.forward) { 478 if (edge.first == last) { 479 sort.elems.add(prim); 480 last = edge.last; 481 } else if (edge.last == first) { 482 sort.elems.add(0, prim); 483 first = edge.first; 484 } else { 485 geom.elems.add(prim); 486 } 487 } else { 488 if (edge.last == last) { 489 sort.elems.add(prim); 490 last = edge.first; 491 } else if (edge.first == first) { 492 sort.elems.add(0, prim); 493 first = edge.last; 494 } else { 495 geom.elems.add(prim); 496 } 497 } 498 } 499 if (--sweep == 0) { 500 next = true; 501 sweep = geom.elems.size(); 502 } 503 } 504 feature.geom = sort; 505 } 506 if (geom.prim == Pflag.AREA) { 507 ArrayList<Prim> outers = new ArrayList<Prim>(); 508 ArrayList<Prim> inners = new ArrayList<Prim>(); 509 for (Prim prim : feature.geom.elems) { 510 if (prim.outer) { 511 outers.add(prim); 512 } else { 513 inners.add(prim); 514 } 515 } 516 ArrayList<Prim> sorting = outers; 517 ArrayList<Prim> closed = null; 518 sort = new Geom(geom.prim); 519 next = true; 520 while (!sorting.isEmpty()) { 521 Prim prim = sorting.remove(0); 522 Edge edge = edges.get(prim.id); 523 if (next == true) { 524 next = false; 525 closed = new ArrayList<Prim>(); 526 closed.add(prim); 527 if (prim.forward) { 528 first = edge.first; 529 last = edge.last; 530 } else { 531 first = edge.last; 532 last = edge.first; 533 } 534 } else { 535 if (prim.forward) { 536 if (edge.first == last) { 537 last = edge.last; 538 closed.add(prim); 539 } else { 540 sorting.add(0, prim); 541 next = true; 542 } 543 } else { 544 if (edge.last == last) { 545 last = edge.first; 546 closed.add(prim); 547 } else { 548 sorting.add(0, prim); 549 next = true; 550 } 551 } 552 } 553 if (first == last) { 554 sort.elems.addAll(closed); 555 next = true; 556 } 557 if (sorting.isEmpty() && sorting == outers) { 558 sorting = inners; 559 next = true; 560 } 561 } 562 feature.geom = sort; 563 } 564 } 565 } 566 452 567 public class EdgeIterator { 453 568 Edge edge; … … 465 580 } 466 581 467 public Snode next() {582 public long nextRef() { 468 583 long ref = 0; 469 584 if (forward) { … … 492 607 } 493 608 } 494 return nodes.get(ref); 609 return ref; 610 } 611 612 public Snode next() { 613 return nodes.get(nextRef()); 495 614 } 496 615 } … … 501 620 EdgeIterator eit; 502 621 ListIterator<S57map.Prim> it; 503 Snodefirst;504 Snodelast;622 long first; 623 long last; 505 624 506 625 public GeomIterator(Geom g) { 507 626 geom = g; 508 627 eit = null; 509 first = last = null; 628 first = 0; 629 last = -1; 510 630 if ((geom.prim != Pflag.NOSP) && (geom.prim != Pflag.POINT)) { 511 631 it = geom.elems.listIterator(); … … 522 642 if ((it != null) && it.hasNext()) { 523 643 prim = it.next(); 644 eit = new EdgeIterator(edges.get(prim.id), prim.forward); 524 645 return prim.outer; 525 646 } … … 528 649 529 650 public boolean hasNext() { 530 return (first != last) && ( eit.hasNext() ||it.hasNext());651 return (first != last) && (it.hasNext() || eit.hasNext()); 531 652 } 532 653 533 public Snode next() {534 if ( !eit.hasNext()) {654 public long nextRef() { 655 if ((eit == null) || !eit.hasNext()) { 535 656 if (it.hasNext()) { 536 657 prim = it.next(); 537 658 eit = new EdgeIterator(edges.get(prim.id), prim.forward); 538 659 } else { 539 return null; 540 } 541 } 542 last = eit.next(); 543 return last; 660 return 0; 661 } 662 } 663 long ref = eit.nextRef(); 664 if (ref == last) 665 ref = eit.nextRef(); 666 if (first == 0) { 667 first = ref; 668 last = 0; 669 } else { 670 last = ref; 671 } 672 return ref; 673 } 674 675 public Snode next() { 676 return nodes.get(nextRef()); 544 677 } 545 678 } -
applications/editors/josm/plugins/smed2/src/symbols/Symbols.java
r30215 r30226 68 68 col = new ArrayList<Color>(); 69 69 col.add(icol); 70 } 71 public Scheme() { 72 pat = new ArrayList<Patt>(); 73 col = new ArrayList<Color>(); 70 74 } 71 75 }
Note:
See TracChangeset
for help on using the changeset viewer.