Changeset 32907 in osm for applications/editors/josm/plugins/seachart/js57toosm/src
- Timestamp:
- 2016-09-03T16:43:42+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/seachart/js57toosm/src/js57toosm/Js57toosm.java
r32906 r32907 1 /* Copyright 2014 Malcolm Herring 2 * 3 * This is free software: you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License as published by 5 * the Free Software Foundation, version 3 of the License. 6 * 7 * For a copy of the GNU General Public License, see <http://www.gnu.org/licenses/>. 1 // License: GPL. For details, see LICENSE file. 2 package js57toosm; 3 4 import java.io.FileInputStream; 5 import java.io.IOException; 6 import java.io.PrintStream; 7 import java.util.ArrayList; 8 import java.util.Map; 9 import java.util.Scanner; 10 11 import org.apache.commons.lang3.StringEscapeUtils; 12 13 import s57.S57att; 14 import s57.S57att.Att; 15 import s57.S57dec; 16 import s57.S57map; 17 import s57.S57map.AttMap; 18 import s57.S57map.Feature; 19 import s57.S57map.GeomIterator; 20 import s57.S57map.ObjTab; 21 import s57.S57map.Pflag; 22 import s57.S57map.Prim; 23 import s57.S57map.Rflag; 24 import s57.S57map.Snode; 25 import s57.S57obj; 26 import s57.S57obj.Obj; 27 import s57.S57val; 28 import s57.S57val.AttVal; 29 30 /** 31 * @author Malcolm Herring 8 32 */ 9 10 package js57toosm; 11 12 import java.io.*; 13 import java.util.*; 14 15 import org.apache.commons.lang3.StringEscapeUtils; 16 17 import s57.S57obj; 18 import s57.S57obj.*; 19 import s57.S57att; 20 import s57.S57att.*; 21 import s57.S57val; 22 import s57.S57val.*; 23 import s57.S57map; 24 import s57.S57map.*; 25 import s57.S57dec; 26 27 public class Js57toosm { 28 33 public final class Js57toosm { 34 private Js57toosm() { 35 // Hide default constructor for utilities classes 36 } 37 29 38 static FileInputStream in; 30 39 static PrintStream out; … … 34 43 typatts.add(Att.PEREND); typatts.add(Att.PERSTA); typatts.add(Att.CONDTN); typatts.add(Att.CONRAD); typatts.add(Att.CONVIS); 35 44 } 36 45 37 46 public static void main(String[] args) throws IOException { 38 47 … … 71 80 System.exit(-1); 72 81 } 73 82 74 83 map = new S57map(true); 75 84 S57dec.decodeChart(in, map); … … 78 87 out.format("<osm version='0.6' upload='false' generator='js57toosm'>%n"); 79 88 out.format("<bounds minlat='%.8f' minlon='%.8f' maxlat='%.8f' maxlon='%.8f'/>%n", 80 Math.toDegrees(map.bounds.minlat), Math.toDegrees(map.bounds.minlon), Math.toDegrees(map.bounds.maxlat), Math.toDegrees(map.bounds.maxlon)); 89 Math.toDegrees(map.bounds.minlat), Math.toDegrees(map.bounds.minlon), 90 Math.toDegrees(map.bounds.maxlat), Math.toDegrees(map.bounds.maxlon)); 81 91 82 92 for (long id : map.index.keySet()) { … … 91 101 while ((node = map.nodes.get(ref)) != null) { 92 102 if (!done.contains(ref)) { 93 out.format(" <node id='%d' lat='%.8f' lon='%.8f' version='1'>%n", -ref, Math.toDegrees(node.lat), Math.toDegrees(node.lon)); 103 out.format(" <node id='%d' lat='%.8f' lon='%.8f' version='1'>%n", 104 -ref, Math.toDegrees(node.lat), Math.toDegrees(node.lon)); 94 105 out.format(" <tag k='seamark:type' v=\"%s\"/>%n", type); 95 106 if ((feature.type == Obj.SOUNDG) && (node.flg == S57map.Nflag.DPTH)) 96 out.format(" <tag k='seamark:sounding:depth' v='%.1f'/>%n", ((Snode) node).val);107 out.format(" <tag k='seamark:sounding:depth' v='%.1f'/>%n", node.val); 97 108 writeAtts(feature); 98 109 out.format(" </node>%n"); … … 111 122 if (!type.isEmpty() && (types.isEmpty() || types.contains(feature.type))) { 112 123 if (feature.reln == Rflag.MASTER) { 113 if ((feature.geom.prim == Pflag.LINE) || ((feature.geom.prim == Pflag.AREA) && (feature.geom.outers == 1) && (feature.geom.inners == 0))) { 124 if ((feature.geom.prim == Pflag.LINE) || 125 ((feature.geom.prim == Pflag.AREA) && (feature.geom.outers == 1) && (feature.geom.inners == 0))) { 114 126 GeomIterator git = map.new GeomIterator(feature.geom); 115 127 while (git.hasComp()) { … … 121 133 Snode node = map.nodes.get(ref); 122 134 if (!done.contains(ref)) { 123 out.format(" <node id='%d' lat='%.8f' lon='%.8f' version='1'/>%n", -ref, Math.toDegrees(node.lat), Math.toDegrees(node.lon)); 135 out.format(" <node id='%d' lat='%.8f' lon='%.8f' version='1'/>%n", 136 -ref, Math.toDegrees(node.lat), Math.toDegrees(node.lon)); 124 137 done.add(ref); 125 138 } … … 152 165 Snode node = map.nodes.get(ref); 153 166 if (!done.contains(ref)) { 154 out.format(" <node id='%d' lat='%.8f' lon='%.8f' version='1'/>%n", -ref, Math.toDegrees(node.lat), Math.toDegrees(node.lon)); 167 out.format(" <node id='%d' lat='%.8f' lon='%.8f' version='1'/>%n", 168 -ref, Math.toDegrees(node.lat), Math.toDegrees(node.lon)); 155 169 done.add(ref); 156 170 } … … 194 208 System.err.println("Finished"); 195 209 } 196 210 197 211 static void writeAtts(Feature feature) { 198 212 for (Map.Entry<Att, AttVal<?>> item : feature.atts.entrySet()) { … … 203 217 out.format(" <tag k='seamark:%s' v='%s'/>%n", attstr, StringEscapeUtils.escapeXml10(valstr)); 204 218 } else { 205 out.format(" <tag k='seamark:%s:%s' v='%s'/>%n", S57obj.stringType(feature.type), attstr, StringEscapeUtils.escapeXml10(valstr)); 219 out.format(" <tag k='seamark:%s:%s' v='%s'/>%n", 220 S57obj.stringType(feature.type), attstr, StringEscapeUtils.escapeXml10(valstr)); 206 221 } 207 222 } … … 216 231 if (!attstr.isEmpty() && !valstr.isEmpty()) { 217 232 if ((ix == 0) && (tab.size() == 1)) { 218 out.format(" <tag k='seamark:%s:%s' v='%s'/>%n", S57obj.stringType(obj), attstr, StringEscapeUtils.escapeXml10(valstr)); 233 out.format(" <tag k='seamark:%s:%s' v='%s'/>%n", 234 S57obj.stringType(obj), attstr, StringEscapeUtils.escapeXml10(valstr)); 219 235 } else { 220 out.format(" <tag k='seamark:%s:%d:%s' v='%s'/>%n", S57obj.stringType(obj), ix + 1, attstr, StringEscapeUtils.escapeXml10(valstr)); 236 out.format(" <tag k='seamark:%s:%d:%s' v='%s'/>%n", 237 S57obj.stringType(obj), ix + 1, attstr, StringEscapeUtils.escapeXml10(valstr)); 221 238 } 222 239 }
Note:
See TracChangeset
for help on using the changeset viewer.