Ignore:
Timestamp:
2015-10-21T11:34:01+02:00 (9 years ago)
Author:
malcolmh
Message:

Multipolygon processing

Location:
applications/editors/josm/plugins/seachart
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/seachart/js57toosm/build.xml

    r31598 r31659  
    33  <property name="build" location="build"/>
    44  <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"/>
    75  <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 
    910  <target name="init">
    1011    <mkdir dir="${build}"/>
    1112  </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" />
    1516  </target>
    16 
    17   <target name="dist" depends="compile" description="generate the distribution" >
     17 
     18  <target name="dist" depends="compile" description="generate the distribution">
    1819    <jar jarfile="${jarfile}" basedir="${build}" >
    1920      <manifest>
    2021        <attribute name="Main-Class" value="js57toosm.Js57toosm"/>
    21         <attribute name="Class-Path" value="$jarfile"/>
     22        <attribute name="Class-Path" value="${jarfile}"/>
    2223      </manifest>
    2324      <zipgroupfileset dir="${lang.dir}" includes="**/commons-lang3-3.4.jar" />
    2425    </jar>
    2526  </target>
    26 
    27   <target name="clean" description="clean up" >
     27 
     28  <target name="clean" description="clean up">
    2829    <delete dir="${build}"/>
    2930    <delete file="${jarfile}"/>
  • applications/editors/josm/plugins/seachart/js57toosm/src/js57toosm/Js57toosm.java

    r31598 r31659  
    3030        static PrintStream out;
    3131        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        }
    3236       
    3337        public static void main(String[] args) throws IOException {
     
    3943                        System.exit(-1);
    4044                }
    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                }
    4358                ArrayList<Obj> types = new ArrayList<Obj>();
     59                try {
    4460                        Scanner tin = new Scanner(new FileInputStream(args[1]));
    4561                        while (tin.hasNext()) {
     
    4965                        }
    5066                        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                }
    5173               
    5274                map = new S57map(true);
     
    7294                                                                        if ((feature.type == Obj.SOUNDG) && (node.flg == S57map.Nflag.DPTH))
    7395                                                                                out.format("    <tag k='seamark:sounding:depth' v='%.1f'/>%n", ((Dnode) node).val);
    74                                                                         writeAtts(feature, type);
     96                                                                        writeAtts(feature);
    7597                                                                        out.format("  </node>%n");
    7698                                                                        done.add(ref);
     
    116138                                                        }
    117139                                                        out.format("    <tag k='seamark:type' v='%s'/>%n", type);
    118                                                         writeAtts(feature, type);
     140                                                        writeAtts(feature);
    119141                                                        out.format("  </way>%n");
    120142                                                }
     
    161183                                                }
    162184                                                out.format("    <tag k='seamark:type' v='%s'/>%n", type);
    163                                                 writeAtts(feature, type);
     185                                                writeAtts(feature);
    164186                                                out.format("  </relation>%n");
    165187                                        }
     
    172194        }
    173195       
    174         static void writeAtts(Feature feature, String type) {
     196        static void writeAtts(Feature feature) {
    175197                for (Map.Entry<Att, AttVal<?>> item : feature.atts.entrySet()) {
    176198                        String attstr = S57att.stringAttribute(item.getKey());
    177199                        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                        }
    180207                }
    181208                for (Obj obj : feature.objs.keySet()) {
    182209                        ObjTab tab = feature.objs.get(obj);
    183210                        for (int ix : tab.keySet()) {
    184                                 type = S57obj.stringType(obj);
    185211                                AttMap atts = tab.get(ix);
    186212                                for (Map.Entry<Att, AttVal<?>> item : atts.entrySet()) {
     
    189215                                        if (!attstr.isEmpty() && !valstr.isEmpty()) {
    190216                                                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));
    192218                                                } 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));
    194220                                                }
    195221                                        }
  • applications/editors/josm/plugins/seachart/src/s57/S57map.java

    r31157 r31659  
    767767                feature.geom.area = 0;
    768768                if (feature.geom.prim == Pflag.POINT) {
    769                         feature.geom.centre = findCentroid(feature);
     769                        feature.geom.centre = nodes.get(feature.geom.elems.get(0).id);
    770770                        return true;
    771771                }       else {
     
    826826                }
    827827                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                        }
    832845                }
    833846                feature.geom.length = calcLength(feature.geom);
    834                 feature.geom.centre = findCentroid(feature);
     847                feature.geom.centre = calcCentroid(feature);
    835848                return true;
    836849        }
     
    951964        }
    952965       
    953         double signedArea(Geom geom) {
     966        double calcArea(Geom geom, int comp) {
    954967                Snode node;
    955968                double lat, lon, llon, llat;
     
    957970                double sigma = 0;
    958971                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;
    972990                        }
    973991                }
     
    975993        }
    976994
    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) {
    986996                Snode node;
    987997                double lat, lon, llon, llat;
     
    10131023        }
    10141024
    1015         public Snode findCentroid(Feature feature) {
     1025        Snode calcCentroid(Feature feature) {
    10161026                double lat, lon, slat, slon, llat, llon;
    10171027                llat = llon = lat = lon = slat = slon = 0;
Note: See TracChangeset for help on using the changeset viewer.