Ignore:
Timestamp:
2013-02-19T18:02:02+01:00 (12 years ago)
Author:
malcolmh
Message:

save

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/smed2/src/seamap/Renderer.java

    r29215 r29266  
    1010package seamap;
    1111
    12 import java.awt.BasicStroke;
    13 import java.awt.Color;
    14 import java.awt.Font;
    15 import java.awt.Graphics2D;
    16 import java.awt.Rectangle;
    17 import java.awt.RenderingHints;
    18 import java.awt.geom.AffineTransform;
    19 import java.awt.geom.GeneralPath;
    20 import java.awt.geom.Path2D;
    21 import java.awt.geom.Point2D;
    22 import java.util.ArrayList;
    23 import java.util.HashMap;
    24 
    25 import s57.S57att.Att;
    26 import s57.S57obj.Obj;
     12import java.awt.*;
     13import java.awt.geom.*;
     14import java.util.*;
     15
     16import s57.S57att.*;
     17import s57.S57obj.*;
    2718import s57.S57val.*;
    2819import s57.S57val;
     
    7162        }
    7263
    73         public static double signedArea(Feature feature) {
    74           if (feature.flag == Fflag.AREA) {
    75                         ArrayList<Long> way;
    76                         if (map.mpolys.containsKey(feature.refs)) {
    77                                 way = map.ways.get(map.mpolys.get(feature.refs));
    78                         } else {
    79                                 way = map.ways.get(feature.refs);
    80                         }
    81                         Coord coord = map.nodes.get(way.get(0));
    82             double llon = coord.lon;
    83             double llat = coord.lat;
    84             double sigma = 0.0;
    85                         for (long node : way) {
    86                                 coord = map.nodes.get(node);
    87                                 double lat = coord.lat;
    88                                 double lon = coord.lon;
    89                                 sigma += (lon * Math.sin(llat)) - (llon * Math.sin(lat));
    90                                 llon = lon;
    91                                 llat = lat;
    92             }
    93             return sigma;
    94           }
    95           return 0;
    96         }
    97 
    98         public boolean handOfArea(Feature feature) {
    99                 return (signedArea(feature) < 0);
    100         }
    101        
    102         public static double calcArea(Feature feature) {
    103           return Math.abs(signedArea(feature)) * 3444 * 3444 / 2.0;
    104         }
    105 
    106         public static Coord findCentroid(Feature feature) {
    107                 Coord coord;
    108                 ArrayList<Long> way;
    109                 if (map.mpolys.containsKey(feature.refs)) {
    110                         way = map.ways.get(map.mpolys.get(feature.refs).get(0));
    111                 } else {
    112                         way = map.ways.get(feature.refs);
    113                 }
    114                 switch (feature.flag) {
    115                 case NODE:
    116                         return map.nodes.get(feature.refs);
    117                 case LINE:
    118                         coord = map.nodes.get(way.get(1));
    119                         break;
    120                 case AREA:
    121                 default:
    122                         coord = map.nodes.get(way.get(0));
    123                 }
    124     double slat = 0.0;
    125     double slon = 0.0;
    126     double sarc = 0.0;
    127     double llat = coord.lat;
    128     double llon = coord.lon;
    129                 for (long node : way) {
    130                         coord = map.nodes.get(node);
    131       double lon = coord.lon;
    132       double lat = coord.lat;
    133       double arc = (Math.acos(Math.cos(lon-llon) * Math.cos(lat-llat)));
    134       slat += (lat * arc);
    135       slon += (lon * arc);
    136       sarc += arc;
    137       llat = lat;
    138       llon = lon;
    139                 }
    140                 return map.new Coord((sarc > 0.0 ? slat/sarc : 0.0), (sarc > 0.0 ? slon/sarc : 0.0));
    141         }
    142        
    14364        public static void symbol(Feature feature, Symbol symbol, Obj obj, Delta delta) {
    144                 Point2D point = helper.getPoint(findCentroid(feature));
     65                Point2D point = helper.getPoint(feature.centre);
    14566                if (obj == null) {
    14667                        Symbols.drawSymbol(g2, symbol, sScale, point.getX(), point.getY(), delta, null);
     
    17192       
    17293        public static void lineSymbols(Feature feature, Symbol prisymb, double space, Symbol secsymb, int ratio) {
    173                 if (feature.flag != Fflag.NODE) {
     94                if (feature.flag != Fflag.POINT) {
    17495                        Rectangle prect = symbolSize(prisymb);
    17596                        Rectangle srect = symbolSize(secsymb);
     
    180101                                double psize = Math.abs(prect.getY()) * sScale;
    181102                                double ssize = (srect != null) ? Math.abs(srect.getY()) * sScale : 0;
    182                                 if (map.outers.containsKey(feature.refs)) {
    183                                         ways.addAll(map.mpolys.get(map.outers.get(feature.refs)));
    184                                 } else {
    185                                         if (map.mpolys.containsKey(feature.refs)) {
    186                                                 ways.addAll(map.mpolys.get(feature.refs));
    187                                         } else {
    188                                                 ways.add(feature.refs);
    189                                         }
    190                                 }
     103//                              if (map.outers.containsKey(feature.refs)) {
     104//                                      ways.addAll(map.mpolys.get(map.outers.get(feature.refs)));
     105//                              } else {
     106//                                      if (map.mpolys.containsKey(feature.refs)) {
     107//                                              ways.addAll(map.mpolys.get(feature.refs));
     108//                                      } else {
     109//                                              ways.add(feature.refs);
     110//                                      }
     111//                              }
    191112                                Point2D prev = new Point2D.Double();
    192113                                Point2D next = new Point2D.Double();
     
    201122                                for (long way : ways) {
    202123                                        boolean first = true;
    203                                         for (long node : map.ways.get(way)) {
     124/*                                      for (long node : map.ways.get(way)) {
    204125                                                prev = next;
    205                                                 next = helper.getPoint(map.nodes.get(node));
     126                                                next = helper.getPoint(map.points.get(node));
    206127                                                angle = Math.atan2(next.getY() - prev.getY(), next.getX() - prev.getX());
    207128                                                piv = true;
     
    246167                                                }
    247168                                        }
    248                                 }
     169*/                              }
    249170                        }
    250171                }
     
    252173
    253174        public static void lineVector (Feature feature, LineStyle style) {
    254                 if (feature.flag != Fflag.NODE) {
     175                if (feature.flag != Fflag.POINT) {
    255176                        ArrayList<Long> ways = new ArrayList<Long>();
    256                         if (map.outers.containsKey(feature.refs)) {
    257                                 ways.addAll(map.mpolys.get(map.outers.get(feature.refs)));
    258                         } else {
    259                                 if (map.mpolys.containsKey(feature.refs)) {
    260                                         ways.addAll(map.mpolys.get(feature.refs));
    261                                 } else {
    262                                         ways.add(feature.refs);
    263                                 }
    264                         }
     177//                      if (map.outers.containsKey(feature.refs)) {
     178//                              ways.addAll(map.mpolys.get(map.outers.get(feature.refs)));
     179//                      } else {
     180//                              if (map.mpolys.containsKey(feature.refs)) {
     181//                                      ways.addAll(map.mpolys.get(feature.refs));
     182//                              } else {
     183//                                      ways.add(feature.refs);
     184//                              }
     185//                      }
    265186                        Path2D.Double p = new Path2D.Double();
    266187                        p.setWindingRule(GeneralPath.WIND_EVEN_ODD);
    267188                        for (long way : ways) {
    268189                                boolean first = true;
    269                                 for (long node : map.ways.get(way)) {
    270                                         Point2D point = helper.getPoint(map.nodes.get(node));
     190/*                              for (long node : map.ways.get(way)) {
     191                                        Point2D point = helper.getPoint(map.points.get(node));
    271192                                        if (first) {
    272193                                                p.moveTo(point.getX(), point.getY());
     
    294215                                g2.setPaint(style.fill);
    295216                                g2.fill(p);
    296                         }
     217*/                      }
    297218                }
    298219        }
     
    301222                Symbol label = new Symbol();
    302223                label.add(new Instr(Prim.TEXT, new Caption(str, font, colour, (delta == null) ? new Delta(Handle.CC, null) : delta)));
    303                 Point2D point = helper.getPoint(findCentroid(feature));
     224                Point2D point = helper.getPoint(feature.centre);
    304225                Symbols.drawSymbol(g2, label, tScale, point.getX(), point.getY(), null, null);
    305226        }
Note: See TracChangeset for help on using the changeset viewer.