Ignore:
Timestamp:
2014-02-15T16:22:45+01:00 (11 years ago)
Author:
malcolmh
Message:

save

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/smed2/js57toosm/src/js57toosm/Js57toosm.java

    r30282 r30283  
    3333        public static void main(String[] args) throws IOException {
    3434
    35                 in = new FileInputStream("/Users/mherring/boatsw/oseam/josm/plugins/smed2/js57toosm/tst.000");
     35                if (args.length < 1) {
     36                        System.err.println("Usage: java -jar js57toosm.jar S57_filename [types_filename]");
     37                        System.exit(-1);
     38                }
     39                in = new FileInputStream(args[0]);
    3640                out = System.out;
     41                ArrayList<Obj> types = new ArrayList<Obj>();
     42                if (args.length == 2) {
     43                        Scanner tin = new Scanner(new FileInputStream(args[1]));
     44                        while (tin.hasNext()) {
     45                                types.add(S57obj.enumType(tin.next()));
     46                        }
     47                        tin.close();
     48                }
     49               
    3750                map = new S57map();
    38 
    3951                S57dat.rnum = 0;
    4052
     
    5769                double minlat = 90, minlon = 180, maxlat = -90, maxlon = -180;
    5870               
    59                 HashMap<Long, Boolean> done = new HashMap<Long, Boolean>();
     71                ArrayList<Long> done = new ArrayList<Long>();
    6072
    6173                while (in.read(leader) == 24) {
     
    221233                        Feature feature = map.index.get(id);
    222234                        String type = S57obj.stringType(feature.type);
    223                         if (!type.isEmpty()) {
     235                        if (!type.isEmpty() && (types.isEmpty() || types.contains(feature.type))) {
    224236                                if (feature.reln == Rflag.MASTER) {
    225237                                        if (feature.geom.prim == Pflag.POINT) {
     
    228240                                                        Snode node;
    229241                                                        while ((node = map.nodes.get(ref)) != null) {
    230                                                                 if (!done.containsKey(ref)) {
     242                                                                if (!done.contains(ref)) {
    231243                                                                        out.format("  <node id='%d' lat='%.8f' lon='%.8f' version='1'>%n", -ref, Math.toDegrees(node.lat), Math.toDegrees(node.lon));
    232244                                                                        out.format("    <tag k='seamark:type' v=\"%s\"/>%n", type);
     
    235247                                                                        writeAtts(feature, type);
    236248                                                                        out.format("  </node>%n");
    237                                                                         done.put(ref, true);
     249                                                                        done.add(ref);
    238250                                                                }
    239251                                                                ref++;
     
    247259                        Feature feature = map.index.get(id);
    248260                        String type = S57obj.stringType(feature.type);
    249                         if (!type.isEmpty()) {
     261                        if (!type.isEmpty() && (types.isEmpty() || types.contains(feature.type))) {
    250262                                if (feature.reln == Rflag.MASTER) {
    251263                                        if (feature.geom.prim == Pflag.LINE) {
     
    258270                                                                        long ref = git.nextRef();
    259271                                                                        Snode node = map.nodes.get(ref);
    260                                                                         if (!done.containsKey(ref)) {
     272                                                                        if (!done.contains(ref)) {
    261273                                                                                out.format("  <node id='%d' lat='%.8f' lon='%.8f' version='1'/>%n", -ref, Math.toDegrees(node.lat), Math.toDegrees(node.lon));
    262                                                                                 done.put(ref, true);
     274                                                                                done.add(ref);
    263275                                                                        }
    264276                                                                }
     
    279291                                                        }
    280292                                                        out.format("  </way>%n");
    281                                                         done.put(way, true);
     293                                                        done.add(way);
    282294                                                }
    283295                                        } else if (feature.geom.prim == Pflag.AREA) {
     
    290302                                                                        long ref = git.nextRef();
    291303                                                                        Snode node = map.nodes.get(ref);
    292                                                                         if (!done.containsKey(ref)) {
     304                                                                        if (!done.contains(ref)) {
    293305                                                                                out.format("  <node id='%d' lat='%.8f' lon='%.8f' version='1'/>%n", -ref, Math.toDegrees(node.lat), Math.toDegrees(node.lon));
    294                                                                                 done.put(ref, true);
     306                                                                                done.add(ref);
    295307                                                                        }
    296308                                                                }
     
    302314                                                        while (git.hasEdge()) {
    303315                                                                long way = git.nextEdge();
    304                                                                 if (!done.containsKey(way)) {
     316                                                                if (!done.contains(way)) {
    305317                                                                        out.format("  <way id='%d' version='1'>%n", -way);
    306318                                                                        while (git.hasNode()) {
     
    309321                                                                        }
    310322                                                                        out.format("  </way>%n");
    311                                                                         done.put(way, true);
     323                                                                        done.add(way);
    312324                                                                }
    313325                                                        }
     
    317329                                                git = map.new GeomIterator(feature.geom);
    318330                                                int outers = feature.geom.refs.get(0).size;
    319 if (feature.geom.inners != 0){
    320         int x=0;
    321 }
    322331                                                while (git.hasComp()) {
    323332                                                        git.nextComp();
Note: See TracChangeset for help on using the changeset viewer.