Ignore:
Timestamp:
2013-08-05T11:15:02+02:00 (12 years ago)
Author:
malcolmh
Message:

save

File:
1 edited

Legend:

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

    r29286 r29826  
    163163                public AttMap atts;
    164164                public ObjMap objs;
    165                 public long area;
     165                public double area;
     166                public double length;
    166167                public Snode centre;
    167168
     
    173174                        objs = new ObjMap();
    174175                        area = 0;
     176                        length = 0;
    175177                        centre = new Snode();
    176178                }
     
    377379                                node.flg = Nflag.ISOL;
    378380                        }
     381                        feature.length = 0;
     382                        feature.area = 0;
    379383                        break;
    380384                case LINE:
     
    382386                        nodes.get(edge.first).flg = Nflag.CONN;
    383387                        nodes.get(edge.last).flg = Nflag.CONN;
     388                        Bound ebound = (new Bound(new Side(edge, edge.forward), true));
     389                        feature.length = calcLength(ebound);
    384390                        if (edge.first == edge.last) {
    385391                                feature.flag = Fflag.AREA;
    386392                                Area area = new Area();
    387                                 area.add(new Bound(new Side(edge, edge.forward), true));
     393                                area.add(ebound);
     394                                feature.area = calcArea(ebound);
    388395                                areas.put(id, area);
     396                        } else {
     397                                feature.area = 0;
    389398                        }
    390399                        break;
    391400                case AREA:
     401                        Bound bound = null;
    392402                        Area area = new Area();
    393403                        ArrayList<Long> role = outers;
     
    397407                                        long node1 = edge.first;
    398408                                        long node2 = edge.last;
    399                                         Bound bound = new Bound(new Side(edge, edge.forward), (role == outers));
     409                                        bound = new Bound(new Side(edge, edge.forward), (role == outers));
    400410                                        if (node1 != node2) {
    401411                                                for (ListIterator<Long> it = role.listIterator(0); it.hasNext();) {
     
    417427                                }
    418428                                if (role == outers) {
     429                                        feature.length = calcLength(bound);
     430                                        feature.area = calcArea(bound);
    419431                                        role = inners;
    420432                                } else {
     
    435447        }
    436448
    437         public double signedArea(Bound bound) {
     449        double signedArea(Bound bound) {
    438450                Snode node;
    439451                double lat, lon, llon, llat;
     
    449461                        sigma += (lon * Math.sin(llat)) - (llon * Math.sin(lat));
    450462                }
    451                 return sigma;
     463                return sigma / 2.0;
    452464        }
    453465
     
    457469
    458470        public double calcArea(Bound bound) {
    459                 return Math.abs(signedArea(bound)) * 3444 * 3444 / 2.0;
     471                return Math.abs(signedArea(bound)) * 3444 * 3444;
     472        }
     473
     474        public double calcLength(Bound bound) {
     475                Snode node;
     476                double lat, lon, llon, llat;
     477                lat = lon = llon = llat = 0;
     478                double sigma = 0;
     479                BoundIterator it = new BoundIterator(bound);
     480                if (it.hasNext()) {
     481                        node = it.next();
     482                        lat = node.lat;
     483                        lon = node.lon;
     484                        while (it.hasNext()) {
     485                                llon = lon;
     486                                llat = lat;
     487                                node = it.next();
     488                                lat = node.lat;
     489                                lon = node.lon;
     490                                sigma += Math.acos(Math.sin(lat) * Math.sin(llat) + Math.cos(lat) * Math.cos(llat) * Math.cos(llon - lon));
     491                        }
     492                }
     493                return sigma * 3444;
    460494        }
    461495
Note: See TracChangeset for help on using the changeset viewer.