Changeset 29272 in osm


Ignore:
Timestamp:
2013-02-21T21:01:44+01:00 (11 years ago)
Author:
malcolmh
Message:

save

Location:
applications/editors/josm/plugins/smed2/src
Files:
2 edited

Legend:

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

    r29271 r29272  
    201201
    202202                public boolean hasNext() {
    203                         return (edge != null) && ((it == null) || (forward && it.hasNext()) || (!forward && it.hasPrevious()));
     203                        return (edge != null) && ((it == null) || (edge.nodes.isEmpty()) || (forward && it.hasNext()) || (!forward && it.hasPrevious()));
    204204                }
    205205
     
    371371
    372372        public void tagsDone(long id) {
    373                 if ((feature.type != Obj.UNKOBJ) && !((edge != null) && (edge.last == 0))) {
    374                         index.put(id, feature);
    375                         if (features.get(feature.type) == null) {
    376                                 features.put(feature.type, new ArrayList<Feature>());
    377                         }
    378                         features.get(feature.type).add(feature);
    379                 }
    380373                switch (feature.flag) {
    381374                case POINT:
     
    432425                        break;
    433426                }
    434                 feature.centre = findCentroid(feature);
     427                if ((feature.type != Obj.UNKOBJ) && !((edge != null) && (edge.last == 0))) {
     428                        index.put(id, feature);
     429                        if (features.get(feature.type) == null) {
     430                                features.put(feature.type, new ArrayList<Feature>());
     431                        }
     432                        feature.centre = findCentroid(feature);
     433                        features.get(feature.type).add(feature);
     434                }
    435435        }
    436436
     
    461461
    462462        public Snode findCentroid(Feature feature) {
    463                 double lat, lon, slat, slon, sarc, llat, llon;
    464                 lat = lon = slat = slon = sarc = llat = llon = 0;
     463                double lat, lon, slat, slon, llat, llon;
     464                llat = llon = lat = lon = slat = slon = 0;
     465                double sarc = 0;
     466                boolean first = true;
    465467                switch (feature.flag) {
    466468                case POINT:
     
    473475                                lat = node.lat;
    474476                                lon = node.lon;
    475                                 sarc += (Math.acos(Math.cos(lon - llon) * Math.cos(lat - llat)));
     477                                if (first) {
     478                                        first = false;
     479                                } else {
     480                                        sarc += (Math.acos(Math.cos(lon - llon) * Math.cos(lat - llat)));
     481                                }
    476482                                llat = lat;
    477483                                llon = lon;
     
    479485                        double harc = sarc / 2;
    480486                        sarc = 0;
     487                        first = true;
    481488                        eit = new EdgeIterator(edge, true);
    482489                        while (eit.hasNext()) {
     
    484491                                lat = node.lat;
    485492                                lon = node.lon;
    486                                 sarc = (Math.acos(Math.cos(lon - llon) * Math.cos(lat - llat)));
    487                                 if (sarc > harc)
    488                                         break;
     493                                if (first) {
     494                                        first = false;
     495                                } else {
     496                                        sarc = (Math.acos(Math.cos(lon - llon) * Math.cos(lat - llat)));
     497                                        if (sarc > harc)
     498                                                break;
     499                                }
    489500                                harc -= sarc;
    490501                                llat = lat;
     
    497508                        BoundIterator bit = new BoundIterator(bound);
    498509                        while (bit.hasNext()) {
    499                                 llon = lon;
    500                                 llat = lat;
    501510                                Snode node = bit.next();
    502511                                lat = node.lat;
    503512                                lon = node.lon;
    504                                 double arc = (Math.acos(Math.cos(lon - llon) * Math.cos(lat - llat)));
    505                                 slat += (lat * arc);
    506                                 slon += (lon * arc);
    507                                 sarc += arc;
     513                                if (first) {
     514                                        first = false;
     515                                } else {
     516                                        double arc = (Math.acos(Math.cos(lon - llon) * Math.cos(lat - llat)));
     517                                        slat += (lat * arc);
     518                                        slon += (lon * arc);
     519                                        sarc += arc;
     520                                }
     521                                llon = lon;
     522                                llat = lat;
    508523                        }
    509524                        return new Snode((sarc > 0.0 ? slat / sarc : 0.0), (sarc > 0.0 ? slon / sarc : 0.0));
  • applications/editors/josm/plugins/smed2/src/smed2/Smed2Action.java

    r29266 r29272  
    3535        public MapImage rendering;
    3636        public SeaMap map = null;
    37         public Collection<OsmPrimitive> data = null;
     37        public DataSet data = null;
    3838
    3939        private final DataSetListener dataSetListener = new DataSetListener() {
     
    4646                @Override
    4747                public void nodeMoved(NodeMovedEvent e) {
    48                         if (map != null) {
    49                                 makeMap();
    50                         }
     48                        System.out.println("NodeMovedEvent");
    5149                }
    5250
     
    154152                if (newLayer != null) {
    155153                        newLayer.data.addDataSetListener(dataSetListener);
    156                         data = newLayer.data.allPrimitives();
     154                        data = newLayer.data;
    157155                        makeMap();
    158156                        if (rendering != null) rendering.zoomChanged();
     
    205203                map = new SeaMap();
    206204                if (data != null) {
    207                         for (OsmPrimitive osm : data) {
    208                                 if (osm instanceof Node) {
    209                                         map.addNode(((Node) osm).getUniqueId(), ((Node) osm).getCoor().lat(), ((Node) osm).getCoor().lon());
    210                                 } else if (osm instanceof Way) {
    211                                         map.addEdge(((Way) osm).getUniqueId());
    212                                         for (Node node : ((Way) osm).getNodes()) {
    213                                                 map.addToEdge((node.getUniqueId()));
    214                                         }
    215                                 } else if ((osm instanceof Relation) && ((Relation) osm).isMultipolygon()) {
    216                                         map.addArea(((Relation) osm).getUniqueId());
    217                                         for (RelationMember mem : ((Relation) osm).getMembers()) {
     205                        for (Node node : data.getNodes()) {
     206                                map.addNode(node.getUniqueId(), node.getCoor().lat(), node.getCoor().lon());
     207                                for (Entry<String, String> entry : node.getKeys().entrySet()) {
     208                                        map.addTag(entry.getKey(), entry.getValue());
     209                                }
     210                                map.tagsDone(node.getUniqueId());
     211                        }
     212                        for (Way way : data.getWays()) {
     213                                map.addEdge(way.getUniqueId());
     214                                for (Node node : way.getNodes()) {
     215                                        map.addToEdge((node.getUniqueId()));
     216                                }
     217                                for (Entry<String, String> entry : way.getKeys().entrySet()) {
     218                                        map.addTag(entry.getKey(), entry.getValue());
     219                                }
     220                                map.tagsDone(way.getUniqueId());
     221                        }
     222                        for (Relation rel : data.getRelations()) {
     223                                if (rel.isMultipolygon()) {
     224                                        map.addArea(rel.getUniqueId());
     225                                        for (RelationMember mem : rel.getMembers()) {
    218226                                                if (mem.getType() == OsmPrimitiveType.WAY)
    219227                                                        map.addToArea(mem.getUniqueId(), (mem.getRole().equals("outer")));
    220228                                        }
    221229                                }
    222                                 for (Entry<String, String> entry : osm.getKeys().entrySet()) {
     230                                for (Entry<String, String> entry : rel.getKeys().entrySet()) {
    223231                                        map.addTag(entry.getKey(), entry.getValue());
    224232                                }
    225                                 map.tagsDone(osm.getUniqueId());
     233                                map.tagsDone(rel.getUniqueId());
    226234                        }
    227235                }
Note: See TracChangeset for help on using the changeset viewer.