Ignore:
Timestamp:
2015-02-17T14:05:54+01:00 (10 years ago)
Author:
malcolmh
Message:

coast/land processing

Location:
applications/editors/josm/plugins/seachart/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/seachart/src/render/Renderer.java

    r30894 r31014  
    251251                while (git.hasComp()) {
    252252                        git.nextComp();
     253                        boolean first = true;
    253254                        while (git.hasEdge()) {
    254255                                git.nextEdge();
    255256                                point = context.getPoint(git.next());
    256                                 p.moveTo(point.getX(), point.getY());
     257                                if (first) {
     258                                        p.moveTo(point.getX(), point.getY());
     259                                        first = false;
     260                                } else {
     261                                        p.lineTo(point.getX(), point.getY());
     262                                }
    257263                                while (git.hasNode()) {
    258264                                        point = context.getPoint(git.next());
  • applications/editors/josm/plugins/seachart/src/render/Rules.java

    r30992 r31014  
    2828public class Rules {
    2929
    30         public static final Color Yland = new Color(0xeca818);
    31         public static final Color Bwater = new Color(0x2ea8d8);
     30        public static final Color Yland = new Color(0xdcb820);
     31        public static final Color Bwater = new Color(0x3ea8c8);
     32        public static final Color Gdries = new Color(0x50b050);
    3233        public static final Color Mline = new Color(0xc480ff);
    3334        public static final Color Msymb = new Color(0xa30075);
     
    176177        public static void rules () {
    177178                ArrayList<Feature> objects;
     179                if ((objects = Renderer.map.features.get(Obj.LNDARE)) != null) for (Feature feature : objects) if (feature.reln == Rflag.MASTER) areas(feature);
     180                if ((objects = Renderer.map.features.get(Obj.LAKARE)) != null) for (Feature feature : objects) if (feature.reln == Rflag.MASTER) areas(feature);
     181                if ((objects = Renderer.map.features.get(Obj.RIVBNK)) != null) for (Feature feature : objects) if (feature.reln == Rflag.MASTER) areas(feature);
     182                if ((objects = Renderer.map.features.get(Obj.RIVERS)) != null) for (Feature feature : objects) if (feature.reln == Rflag.MASTER) waterways(feature);
     183                if ((objects = Renderer.map.features.get(Obj.CANALS)) != null) for (Feature feature : objects) if (feature.reln == Rflag.MASTER) waterways(feature);
     184                if ((objects = Renderer.map.features.get(Obj.DOCARE)) != null) for (Feature feature : objects) if (feature.reln == Rflag.MASTER) areas(feature);
     185                if ((objects = Renderer.map.features.get(Obj.DEPARE)) != null) for (Feature feature : objects) if (feature.reln == Rflag.MASTER) areas(feature);
    178186                if ((objects = Renderer.map.features.get(Obj.COALNE)) != null) for (Feature feature : objects) if (feature.reln == Rflag.MASTER) areas(feature);
    179187                if ((objects = Renderer.map.features.get(Obj.SLCONS)) != null) for (Feature feature : objects) if (feature.reln == Rflag.MASTER) shoreline(feature);
     
    199207                if ((objects = Renderer.map.features.get(Obj.UWTROC)) != null) for (Feature feature : objects) if (feature.reln == Rflag.MASTER) obstructions(feature);
    200208                if ((objects = Renderer.map.features.get(Obj.MARCUL)) != null) for (Feature feature : objects) if (feature.reln == Rflag.MASTER) areas(feature);
    201                 if ((objects = Renderer.map.features.get(Obj.WTWAXS)) != null) for (Feature feature : objects) if (feature.reln == Rflag.MASTER) waterways(feature);
    202209                if ((objects = Renderer.map.features.get(Obj.RECTRC)) != null) for (Feature feature : objects) if (feature.reln == Rflag.MASTER) transits(feature);
    203210                if ((objects = Renderer.map.features.get(Obj.NAVLNE)) != null) for (Feature feature : objects) if (feature.reln == Rflag.MASTER) transits(feature);
     
    255262                switch (feature.type) {
    256263                case COALNE:
    257                         Renderer.lineVector(feature, new LineStyle(Color.black, 8, Yland));
     264                        Renderer.lineVector(feature, new LineStyle(Color.black, 10));
     265                        break;
     266                case DEPARE:
     267                        Double depmax = 0.0;
     268                        if (((depmax = (Double) getAttVal(feature, feature.type, 0, Att.DRVAL2)) != null) && (depmax <= 0.0)) {
     269                                Renderer.lineVector(feature, new LineStyle(Gdries));
     270                        }
     271                        break;
     272                case DOCARE:
     273                case LAKARE:
     274                case RIVBNK:
     275                        Renderer.lineVector(feature, new LineStyle(Bwater));
    258276                        break;
    259277                case DRGARE:
     
    272290                        } else {
    273291                                if (Renderer.zoom >= 14)
    274                                         Renderer.lineVector(feature, new LineStyle(null, 0, new Color(0x40ffffff, true)));
    275                         }
     292                                        Renderer.lineVector(feature, new LineStyle(new Color(0x40ffffff, true)));
     293                        }
     294                        break;
     295                case LNDARE:
     296                        Renderer.lineVector(feature, new LineStyle(Yland));
    276297                        break;
    277298                case MARCUL:
     
    930951                case TSSRON:
    931952                        if (Renderer.zoom <= 15)
    932                                 Renderer.lineVector(feature, new LineStyle(null, 0, null, new Color(0x80c48080, true)));
     953                                Renderer.lineVector(feature, new LineStyle(new Color(0x80c48080, true)));
    933954                        else
    934955                                Renderer.lineVector(feature, new LineStyle(new Color(0x80c48080, true), 20, null, null));
     
    11081129
    11091130        private static void waterways(Feature feature) {
    1110                
     1131                Renderer.lineVector(feature, new LineStyle(Bwater, 20));
    11111132        }
    11121133
  • applications/editors/josm/plugins/seachart/src/s57/S57att.java

    r30992 r31014  
    1010package s57;
    1111
    12 import java.util.EnumMap;
    13 import java.util.HashMap;
    14 import java.util.Map;
     12import java.util.*;
    1513
    1614import s57.S57obj.*;
  • applications/editors/josm/plugins/seachart/src/s57/S57map.java

    r30996 r31014  
    2727                public double maxlon;
    2828                public MapBounds() {
    29                         minlat = 90;
    30                         minlon = 180;
    31                         maxlat = -90;
    32                         maxlon = -180;
     29                        minlat = Math.toRadians(90);
     30                        minlon = Math.toRadians(180);
     31                        maxlat = Math.toRadians(-90);
     32                        maxlon = Math.toRadians(-180);
    3333                }
    3434        }
     
    221221                }
    222222        }
     223       
     224        class OSMtag {
     225                String key;
     226                String val;
     227                OSMtag(String k, String v) {
     228                        key = k;
     229                        val = v;
     230                }
     231        }
     232       
     233        ArrayList<OSMtag> osmtags;
    223234
    224235        public NodeTab nodes;
     
    227238        public FtrMap features;
    228239        public FtrTab index;
    229 
    230         public long ref;
     240       
     241        public MapBounds bounds;
     242
     243        public long cref;
     244        public long xref;
    231245        private Feature feature;
    232246        private Edge edge;
     
    238252                features = new FtrMap();        // All features in map, grouped by type
    239253                index = new FtrTab();                   // Feature look-up table
    240                 ref = 0x0000ffffffff0000L;// Compound reference generator
     254                bounds = new MapBounds();
     255                cref = 0x0000ffffffff0000L;// Compound reference generator
     256                xref = 0x0fff000000000000L;// Extras reference generator
    241257        }
    242258
     
    371387                feature.geom.prim = Pflag.POINT;
    372388                feature.geom.elems.add(new Prim(id));
     389                osmtags = new ArrayList<OSMtag>();
    373390                edge = null;
    374391        }
     
    379396                feature.geom.prim = Pflag.LINE;
    380397                feature.geom.elems.add(new Prim(id));
     398                osmtags = new ArrayList<OSMtag>();
    381399                edge = new Edge();
    382400        }
     
    398416                feature.reln = Rflag.UNKN;
    399417                feature.geom.prim = Pflag.AREA;
     418                osmtags = new ArrayList<OSMtag>();
    400419                edge = null;
    401420        }
     
    457476                                }
    458477                        }
     478                } else {
     479                        osmtags.add(new OSMtag(key, val));
    459480                }
    460481        }
    461482
    462483        public void tagsDone(long id) {
     484                if (feature.type == Obj.UNKOBJ) {
     485                        for (OSMtag tag : osmtags) {
     486                                Obj obj = S57obj.OSMobj(tag.key, tag.val);
     487                                if (obj != Obj.UNKOBJ) {
     488                                        feature.type = obj;
     489                                        ObjTab objs = feature.objs.get(obj);
     490                                        if (objs == null) {
     491                                                objs = new ObjTab();
     492                                                feature.objs.put(obj, objs);
     493                                        }
     494                                        AttMap atts = objs.get(0);
     495                                        if (atts == null) {
     496                                                atts = new AttMap();
     497                                                objs.put(0, atts);
     498                                        }
     499                                        AttVal<?> attval = S57val.OSMatt(tag.key, tag.val);
     500                                        if (attval.att != Att.UNKATT) {
     501                                                atts.put(attval.att, attval);
     502                                        }
     503                                        break;
     504                                }
     505                        }
     506                }
    463507                switch (feature.geom.prim) {
    464508                case POINT:
     
    490534                }
    491535        }
     536       
     537        public void mapDone() {
     538                ArrayList<Feature> coasts = new ArrayList<Feature>();
     539                ArrayList<Feature> lands = new ArrayList<Feature>();
     540                if (features.get(Obj.LNDARE) == null) {
     541                        features.put(Obj.LNDARE, new ArrayList<Feature>());
     542                }
     543                for (Feature feature : features.get(Obj.COALNE)) {
     544                        Feature land = new Feature();
     545                        land.type = Obj.LNDARE;
     546                        land.reln = Rflag.MASTER;
     547                        land.objs.put(Obj.LNDARE, new ObjTab());
     548                        if (feature.geom.prim == Pflag.AREA) {
     549                                land.geom = feature.geom;
     550                                features.get(Obj.LNDARE).add(land);
     551                        } else if (feature.geom.prim == Pflag.LINE) {
     552                                land.geom.prim = Pflag.LINE;
     553                                for (int i = 0; i < feature.geom.elems.size(); i++) {
     554                                        land.geom.elems.add(feature.geom.elems.get(i));
     555                                }
     556                                coasts.add(land);
     557                        }
     558                }
     559                while (coasts.size() > 0) {
     560                        Feature land = coasts.remove(0);
     561                        Edge fedge = edges.get(land.geom.elems.get(0).id);
     562                        long first = fedge.first;
     563                        long last = edges.get(land.geom.elems.get(land.geom.elems.size() - 1).id).last;
     564                        if (coasts.size() > 0) {
     565                                boolean added = true;
     566                                while (added) {
     567                                        added = false;
     568                                        for (int i = 0; i < coasts.size(); i++) {
     569                                                Feature coast = coasts.get(i);
     570                                                Edge edge = edges.get(coast.geom.elems.get(0).id);
     571                                                if (edge.first == last) {
     572                                                        land.geom.elems.add(coast.geom.elems.get(0));
     573                                                        last = edge.last;
     574                                                        coasts.remove(i--);
     575                                                        added = true;
     576                                                } else if (edge.last == first) {
     577                                                        land.geom.elems.add(0, coast.geom.elems.get(0));
     578                                                        first = edge.first;
     579                                                        coasts.remove(i--);
     580                                                        added = true;
     581                                                }
     582                                        }
     583                                }
     584                        }
     585                        lands.add(land);
     586                }
     587                for (Feature land : lands) {
     588                        long first = edges.get(land.geom.elems.get(0).id).first;
     589                        long last = edges.get(land.geom.elems.get(land.geom.elems.size()-1).id).last;
     590                        Ext fext = outsideBounds(first);
     591                        Ext lext = outsideBounds(last);
     592                        Edge nedge = new Edge();
     593                        nedge.first = last;
     594                        nedge.last = first;
     595                        switch (lext) {
     596                        case NE:
     597                        case N:
     598                                if ((fext != Ext.NE) && (fext != Ext.N)) {
     599                                        nedge.nodes.add(1L);
     600                                        if ((fext != Ext.NW) && (fext != Ext.W)) {
     601                                                nedge.nodes.add(2L);
     602                                                if ((fext != Ext.SW) && (fext != Ext.S)) {
     603                                                        nedge.nodes.add(3L);
     604                                                        if ((fext != Ext.SE) && (fext != Ext.W)) {
     605                                                                nedge.nodes.add(4L);
     606                                                        }
     607                                                }
     608                                        }
     609                                }
     610                                break;
     611                        case NW:
     612                        case W:
     613                                if ((fext != Ext.NW) && (fext != Ext.W)) {
     614                                        nedge.nodes.add(2L);
     615                                        if ((fext != Ext.SW) && (fext != Ext.S)) {
     616                                                nedge.nodes.add(3L);
     617                                                if ((fext != Ext.SE) && (fext != Ext.E)) {
     618                                                        nedge.nodes.add(4L);
     619                                                        if ((fext != Ext.NE) && (fext != Ext.N)) {
     620                                                                nedge.nodes.add(1L);
     621                                                        }
     622                                                }
     623                                        }
     624                                }
     625                                break;
     626                        case SW:
     627                        case S:
     628                                if ((fext != Ext.SW) && (fext != Ext.S)) {
     629                                        nedge.nodes.add(3L);
     630                                        if ((fext != Ext.SE) && (fext != Ext.E)) {
     631                                                nedge.nodes.add(4L);
     632                                                if ((fext != Ext.NE) && (fext != Ext.N)) {
     633                                                        nedge.nodes.add(1L);
     634                                                        if ((fext != Ext.NW) && (fext != Ext.W)) {
     635                                                                nedge.nodes.add(2L);
     636                                                        }
     637                                                }
     638                                        }
     639                                }
     640                                break;
     641                        case SE:
     642                        case E:
     643                                if ((fext != Ext.SE) && (fext != Ext.E)) {
     644                                        nedge.nodes.add(4L);
     645                                        if ((fext != Ext.NE) && (fext != Ext.N)) {
     646                                                nedge.nodes.add(1L);
     647                                                if ((fext != Ext.NW) && (fext != Ext.W)) {
     648                                                        nedge.nodes.add(2L);
     649                                                        if ((fext != Ext.SW) && (fext != Ext.S)) {
     650                                                                nedge.nodes.add(3L);
     651                                                        }
     652                                                }
     653                                        }
     654                                }
     655                                break;
     656                        default:
     657                        }
     658                        edges.put(++xref, nedge);
     659                        land.geom.elems.add(new Prim(xref));
     660                        sortGeom(land);
     661                        features.get(Obj.LNDARE).add(land);
     662                }
     663        }
    492664
    493665        // Utility methods
     666       
     667        enum Ext {I, N, NW, W, SW, S, SE, E, NE }
     668        Ext outsideBounds(long ref) {
     669                Snode node = nodes.get(ref);
     670                if (node.lat >= bounds.maxlat) {
     671                        if (node.lon <= bounds.minlon) {
     672                                return Ext.NW;
     673                        } else if (node.lon >= bounds.maxlon) {
     674                                return Ext.NE;
     675                        }
     676                        return Ext.N;
     677                }
     678                if (node.lat <= bounds.minlat) {
     679                        if (node.lon <= bounds.minlon) {
     680                                return Ext.SW;
     681                        } else if (node.lon >= bounds.maxlon) {
     682                                return Ext.SE;
     683                        }
     684                        return Ext.S;
     685                }
     686                if (node.lon >= bounds.maxlon) {
     687                        if (node.lat <= bounds.minlat) {
     688                                return Ext.SE;
     689                        } else if (node.lat >= bounds.maxlat) {
     690                                return Ext.NE;
     691                        }
     692                        return Ext.E;
     693                }
     694                if (node.lon <= bounds.minlon) {
     695                        if (node.lat <= bounds.minlat) {
     696                                return Ext.SW;
     697                        } else if (node.lat >= bounds.maxlat) {
     698                                return Ext.NW;
     699                        }
     700                        return Ext.W;
     701                }
     702                return Ext.I;
     703        }
    494704       
    495705        public boolean sortGeom(Feature feature) {
     
    526736                                                sort.inners++;
    527737                                        }
    528                                         comp = new Comp(ref++, 1);
     738                                        comp = new Comp(cref++, 1);
    529739                                        sort.refs.add(comp);
    530740                                } else {
  • applications/editors/josm/plugins/seachart/src/s57/S57obj.java

    r30992 r31014  
    1010package s57;
    1111
    12 import java.util.EnumMap;
    13 import java.util.HashMap;
    14 import java.util.Map;
     12import java.util.*;
    1513
    1614public class S57obj {
     
    179177                        return Obj.UNKOBJ;
    180178        }
     179       
     180        private static final HashMap<String, Obj> OSMtags = new HashMap<String, Obj>();
     181        static {
     182                OSMtags.put("natural=coastline", Obj.COALNE); OSMtags.put("natural=water", Obj.LAKARE);
     183                OSMtags.put("waterway=riverbank", Obj.RIVBNK); OSMtags.put("waterway=river", Obj.RIVERS); OSMtags.put("waterway=canal", Obj.CANALS);
     184                OSMtags.put("wetland=tidalflat", Obj.DEPARE);
     185        }
     186       
     187        public static Obj OSMobj(String key, String val) {
     188                Obj obj = OSMtags.get(key + "=" + val);
     189                if (obj != null) {
     190                        return obj;
     191                }
     192                return Obj.UNKOBJ;
     193        }
    181194
    182195}
  • applications/editors/josm/plugins/seachart/src/s57/S57val.java

    r30992 r31014  
    1010package s57;
    1111
    12 import java.util.ArrayList;
    13 import java.util.EnumMap;
     12import java.util.*;
    1413
    1514import s57.S57att.*;
     
    12431242        }
    12441243
     1244        static class KeyVal {
     1245                Att key;
     1246                Object val;
     1247                KeyVal(Att k, Object v) {
     1248                        key = k;
     1249                        val = v;
     1250                }
     1251        }
     1252       
     1253        private static final HashMap<String, KeyVal> OSMtags = new HashMap<String, KeyVal>();
     1254        static {
     1255                OSMtags.put("wetland=tidalflat", new KeyVal(Att.DRVAL2, (double)0));
     1256        }
     1257       
     1258        public static AttVal OSMatt(String key, String val) {
     1259                KeyVal att = OSMtags.get(key + "=" + val);
     1260                if (att != null) {
     1261                        return new AttVal(att.key, Conv.F, att.val);
     1262                }
     1263                return new AttVal(Att.UNKATT, Conv.A, null);
     1264        }
     1265
    12451266}
  • applications/editors/josm/plugins/seachart/src/seachart/SeachartAction.java

    r30996 r31014  
    2121import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    2222import org.openstreetmap.josm.gui.layer.*;
     23import org.openstreetmap.josm.data.Bounds;
    2324import org.openstreetmap.josm.data.coor.LatLon;
    2425import org.openstreetmap.josm.data.imagery.ImageryInfo;
     
    146147                map = new S57map();
    147148                if (data != null) {
     149                        double minlat = 90;
     150                        double maxlat = -90;
     151                        double minlon = 180;
     152                        double maxlon = -180;
     153                        for (Bounds bounds : data.getDataSourceBounds()) {
     154                                if (bounds.getMinLat() < minlat) {
     155                                        minlat = bounds.getMinLat();
     156                                }
     157                                if (bounds.getMaxLat() > maxlat) {
     158                                        maxlat = bounds.getMaxLat();
     159                                }
     160                                if (bounds.getMinLon() < minlon) {
     161                                        minlon = bounds.getMinLon();
     162                                }
     163                                if (bounds.getMaxLon() > maxlon) {
     164                                        maxlon = bounds.getMaxLon();
     165                                }
     166                        }
     167                        map.addNode(1, maxlat, minlon);
     168                        map.addNode(2, minlat, minlon);
     169                        map.addNode(3, minlat, maxlon);
     170                        map.addNode(4, maxlat, maxlon);
     171                        map.bounds.minlat = Math.toRadians(minlat);
     172                        map.bounds.maxlat = Math.toRadians(maxlat);
     173                        map.bounds.minlon = Math.toRadians(minlon);
     174                        map.bounds.maxlon = Math.toRadians(maxlon);
    148175                        for (Node node : data.getNodes()) {
    149176                                LatLon coor = node.getCoor();
     
    181208                                }
    182209                        }
     210                        map.mapDone();
    183211                        if (rendering != null) rendering.zoomChanged();
    184212                }
  • applications/editors/josm/plugins/seachart/src/symbols/Symbols.java

    r30894 r31014  
    9595                public Color fill;
    9696
     97                public LineStyle(Color ifill) {
     98                        line = null;
     99                        width = 0;
     100                        dash = null;
     101                        fill = ifill;
     102                }
    97103                public LineStyle(Color iline, float iwidth) {
    98104                        line = iline;
Note: See TracChangeset for help on using the changeset viewer.