Changeset 1210 in josm for trunk


Ignore:
Timestamp:
2009-01-04T23:44:07+01:00 (15 years ago)
Author:
framm
Message:
  • drastically improved performance of "download along track", and removed a bug that would download way too much data.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java

    r1206 r1210  
    1212import java.awt.GridBagLayout;
    1313import java.awt.Point;
    14 import java.awt.Rectangle;
    1514import java.awt.event.ActionEvent;
    1615import java.awt.event.ActionListener;
     
    5857import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask;
    5958import org.openstreetmap.josm.data.coor.EastNorth;
     59import org.openstreetmap.josm.data.coor.LatLon;
    6060import org.openstreetmap.josm.data.gpx.GpxData;
    6161import org.openstreetmap.josm.data.gpx.GpxRoute;
     
    780780                JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) {
    781781                return;
    782 
    783782            }
    784783
     
    803802
    804803            /*
    805              * Compute buffer zone extents and maximum bounding box size. Note how the
     804             * Compute buffer zone extents and maximum bounding box size. Note that the
    806805             * maximum we ever offer is a bbox area of 0.002, while the API theoretically
    807806             * supports 0.25, but as soon as you touch any built-up area, that kind of
     
    810809             */
    811810            Integer i = buffer.getSelectedIndex();
    812             double buffer_y = dist[i < 0 ? 0 : i] / 1000.0;
     811            int buffer_dist = dist[i < 0 ? 0 : i];
     812            double buffer_y = buffer_dist / 100000.0;
    813813            double buffer_x = buffer_y / scale;
    814814            i = maxRect.getSelectedIndex();
    815815            double max_area = area[i < 0 ? 0 : i] / 10000.0 / scale;
    816 
    817816            Area a = new Area();
    818817            Rectangle2D r = new Rectangle2D.Double();
     
    820819            /*
    821820             * Collect the combined area of all gpx points plus buffer zones around them.
    822              * This is rather inefficient (may take 20 seconds and more for large tracks);
    823              * maybe it could be improved by disregarding points that lie really close to
    824              * the previous point.
     821             * We ignore points that lie closer to the previous point than the given buffer
     822             * size because otherwise this operation takes ages.
    825823             */
     824            LatLon previous = null;
    826825            for (GpxTrack trk : data.tracks) {
    827826                for (Collection<WayPoint> segment : trk.trackSegs) {
    828827                    for (WayPoint p : segment) {
    829                         // we add a buffer around the point.
    830                         r.setRect(p.latlon.lon()-buffer_x, p.latlon.lat()-buffer_y, 2*buffer_x, 2*buffer_y);
    831                         a.add(new Area(r));
     828                        if (previous == null || p.latlon.greatCircleDistance(previous) > buffer_dist) {
     829                            // we add a buffer around the point.
     830                            r.setRect(p.latlon.lon()-buffer_x, p.latlon.lat()-buffer_y, 2*buffer_x, 2*buffer_y);
     831                            a.add(new Area(r));
     832                            previous = p.latlon;
     833                        }
    832834                    }
    833835                }
     
    836838            /*
    837839             * Area "a" now contains the hull that we would like to download data for.
    838              * however we can only download rectangles, so the following is an attemt at
     840             * however we can only download rectangles, so the following is an attempt at
    839841             * finding a number of rectangles to download.
    840842             *
Note: See TracChangeset for help on using the changeset viewer.