Changeset 31659 in osm
- Timestamp:
- 2015-10-21T11:34:01+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/seachart
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/seachart/js57toosm/build.xml
r31598 r31659 3 3 <property name="build" location="build"/> 4 4 <property name="jarfile" location="./js57toosm.jar"/> 5 <property name="ant.build.javac.target" value="1.7"/>6 <property name="ant.build.javac.source" value="1.7"/>7 5 <property name="lang.dir" value="/usr/local/bin/commons-lang3-3.4/"/> 8 6 <path id="classpath"> 7 <fileset dir="${lang.dir}" includes="**/commons-lang3-3.4.jar"/> 8 </path> 9 9 10 <target name="init"> 10 11 <mkdir dir="${build}"/> 11 12 </target> 12 13 <target name="compile" depends="init" description="compile the source ">14 <javac includeantruntime="false" srcdir="${src}" destdir="${build}" encoding="UTF-8"/>13 14 <target name="compile" depends="init" description="compile the source"> 15 <javac includeantruntime="false" srcdir="${src}" destdir="${build}" classpathref="classpath" encoding="UTF-8" /> 15 16 </target> 16 17 <target name="dist" depends="compile" description="generate the distribution" 17 18 <target name="dist" depends="compile" description="generate the distribution"> 18 19 <jar jarfile="${jarfile}" basedir="${build}" > 19 20 <manifest> 20 21 <attribute name="Main-Class" value="js57toosm.Js57toosm"/> 21 <attribute name="Class-Path" value="$ jarfile"/>22 <attribute name="Class-Path" value="${jarfile}"/> 22 23 </manifest> 23 24 <zipgroupfileset dir="${lang.dir}" includes="**/commons-lang3-3.4.jar" /> 24 25 </jar> 25 26 </target> 26 27 <target name="clean" description="clean up" 27 28 <target name="clean" description="clean up"> 28 29 <delete dir="${build}"/> 29 30 <delete file="${jarfile}"/> -
applications/editors/josm/plugins/seachart/js57toosm/src/js57toosm/Js57toosm.java
r31598 r31659 30 30 static PrintStream out; 31 31 static S57map map; 32 static final ArrayList<Att> typatts = new ArrayList<Att>(); static { 33 typatts.add(Att.OBJNAM); typatts.add(Att.NOBJNM); typatts.add(Att.STATUS); typatts.add(Att.INFORM); typatts.add(Att.NINFOM); 34 typatts.add(Att.PEREND); typatts.add(Att.PERSTA); typatts.add(Att.CONDTN); typatts.add(Att.CONRAD); typatts.add(Att.CONVIS); 35 } 32 36 33 37 public static void main(String[] args) throws IOException { … … 39 43 System.exit(-1); 40 44 } 41 in = new FileInputStream(args[0]); 42 out = new PrintStream(args[2]); 45 try { 46 in = new FileInputStream(args[0]); 47 } catch (IOException e) { 48 System.err.println("Input file: " + e.getMessage()); 49 System.exit(-1); 50 } 51 try { 52 out = new PrintStream(args[2]); 53 } catch (IOException e) { 54 System.err.println("Output file: " + e.getMessage()); 55 in.close(); 56 System.exit(-1); 57 } 43 58 ArrayList<Obj> types = new ArrayList<Obj>(); 59 try { 44 60 Scanner tin = new Scanner(new FileInputStream(args[1])); 45 61 while (tin.hasNext()) { … … 49 65 } 50 66 tin.close(); 67 } catch (IOException e) { 68 System.err.println("Types file: " + e.getMessage()); 69 in.close(); 70 out.close(); 71 System.exit(-1); 72 } 51 73 52 74 map = new S57map(true); … … 72 94 if ((feature.type == Obj.SOUNDG) && (node.flg == S57map.Nflag.DPTH)) 73 95 out.format(" <tag k='seamark:sounding:depth' v='%.1f'/>%n", ((Dnode) node).val); 74 writeAtts(feature , type);96 writeAtts(feature); 75 97 out.format(" </node>%n"); 76 98 done.add(ref); … … 116 138 } 117 139 out.format(" <tag k='seamark:type' v='%s'/>%n", type); 118 writeAtts(feature , type);140 writeAtts(feature); 119 141 out.format(" </way>%n"); 120 142 } … … 161 183 } 162 184 out.format(" <tag k='seamark:type' v='%s'/>%n", type); 163 writeAtts(feature , type);185 writeAtts(feature); 164 186 out.format(" </relation>%n"); 165 187 } … … 172 194 } 173 195 174 static void writeAtts(Feature feature , String type) {196 static void writeAtts(Feature feature) { 175 197 for (Map.Entry<Att, AttVal<?>> item : feature.atts.entrySet()) { 176 198 String attstr = S57att.stringAttribute(item.getKey()); 177 199 String valstr = S57val.stringValue(item.getValue(), item.getKey()); 178 if (!attstr.isEmpty() && !valstr.isEmpty()) 179 out.format(" <tag k='seamark:%s:%s' v='%s'/>%n", type, attstr, StringEscapeUtils.escapeXml10(valstr)); 200 if (!attstr.isEmpty() && !valstr.isEmpty()) { 201 if (typatts.contains(item.getKey())) { 202 out.format(" <tag k='seamark:%s' v='%s'/>%n", attstr, StringEscapeUtils.escapeXml10(valstr)); 203 } else { 204 out.format(" <tag k='seamark:%s:%s' v='%s'/>%n", S57obj.stringType(feature.type), attstr, StringEscapeUtils.escapeXml10(valstr)); 205 } 206 } 180 207 } 181 208 for (Obj obj : feature.objs.keySet()) { 182 209 ObjTab tab = feature.objs.get(obj); 183 210 for (int ix : tab.keySet()) { 184 type = S57obj.stringType(obj);185 211 AttMap atts = tab.get(ix); 186 212 for (Map.Entry<Att, AttVal<?>> item : atts.entrySet()) { … … 189 215 if (!attstr.isEmpty() && !valstr.isEmpty()) { 190 216 if ((ix == 0) && (tab.size() == 1)) { 191 out.format(" <tag k='seamark:%s:%s' v='%s'/>%n", type, attstr, StringEscapeUtils.escapeXml10(valstr));217 out.format(" <tag k='seamark:%s:%s' v='%s'/>%n", S57obj.stringType(obj), attstr, StringEscapeUtils.escapeXml10(valstr)); 192 218 } else { 193 out.format(" <tag k='seamark:%s:%d:%s' v='%s'/>%n", type, ix + 1, attstr, StringEscapeUtils.escapeXml10(valstr));219 out.format(" <tag k='seamark:%s:%d:%s' v='%s'/>%n", S57obj.stringType(obj), ix + 1, attstr, StringEscapeUtils.escapeXml10(valstr)); 194 220 } 195 221 } -
applications/editors/josm/plugins/seachart/src/s57/S57map.java
r31157 r31659 767 767 feature.geom.area = 0; 768 768 if (feature.geom.prim == Pflag.POINT) { 769 feature.geom.centre = findCentroid(feature);769 feature.geom.centre = nodes.get(feature.geom.elems.get(0).id); 770 770 return true; 771 771 } else { … … 826 826 } 827 827 if (feature.geom.prim == Pflag.AREA) { 828 if (signedArea(feature.geom) < 0.0) { 829 830 }; 831 feature.geom.area = calcArea(feature.geom); 828 int ie = 0; 829 int ic = 0; 830 while (ie < feature.geom.elems.size()) { 831 double area = calcArea(feature.geom, ic); 832 if (ie == 0) feature.geom.area = Math.abs(area) * 3444 * 3444; 833 if (((ie == 0) && (area < 0.0)) || ((ie > 0) && (area >= 0.0))) { 834 ArrayList<Prim> tmp = new ArrayList<Prim>(); 835 for (int i = 0; i < feature.geom.comps.get(ic).size; i++) { 836 Prim p = feature.geom.elems.remove(ie); 837 p.forward = !p.forward; 838 tmp.add(0, p); 839 } 840 feature.geom.elems.addAll(ie, tmp); 841 } 842 ie += feature.geom.comps.get(ic).size; 843 ic++; 844 } 832 845 } 833 846 feature.geom.length = calcLength(feature.geom); 834 feature.geom.centre = findCentroid(feature);847 feature.geom.centre = calcCentroid(feature); 835 848 return true; 836 849 } … … 951 964 } 952 965 953 double signedArea(Geom geom) {966 double calcArea(Geom geom, int comp) { 954 967 Snode node; 955 968 double lat, lon, llon, llat; … … 957 970 double sigma = 0; 958 971 GeomIterator git = new GeomIterator(geom); 959 if (git.hasComp()) { 960 git.nextComp(); 961 while (git.hasEdge()) { 962 git.nextEdge(); 963 while (git.hasNode()) { 964 node = git.next(); 965 if (node == null) continue; 966 llon = lon; 967 llat = lat; 968 lat = node.lat; 969 lon = node.lon; 970 sigma += (lon * Math.sin(llat)) - (llon * Math.sin(lat)); 971 } 972 for (int i = 0; i <= comp; i++) { 973 if (git.hasComp()) { 974 git.nextComp(); 975 while (git.hasEdge()) { 976 git.nextEdge(); 977 while (git.hasNode()) { 978 node = git.next(); 979 if (node == null) 980 continue; 981 llon = lon; 982 llat = lat; 983 lat = node.lat; 984 lon = node.lon; 985 sigma += (lon * Math.sin(llat)) - (llon * Math.sin(lat)); 986 } 987 } 988 if (i != comp) 989 sigma = lat = lon = llon = llat = 0; 972 990 } 973 991 } … … 975 993 } 976 994 977 public boolean handOfArea(Geom geom) { 978 return (signedArea(geom) < 0); 979 } 980 981 public double calcArea(Geom geom) { 982 return Math.abs(signedArea(geom)) * 3444 * 3444; 983 } 984 985 public double calcLength(Geom geom) { 995 double calcLength(Geom geom) { 986 996 Snode node; 987 997 double lat, lon, llon, llat; … … 1013 1023 } 1014 1024 1015 public Snode findCentroid(Feature feature) {1025 Snode calcCentroid(Feature feature) { 1016 1026 double lat, lon, slat, slon, llat, llon; 1017 1027 llat = llon = lat = lon = slat = slon = 0;
Note:
See TracChangeset
for help on using the changeset viewer.