Changeset 7575 in josm


Ignore:
Timestamp:
2014-09-21T23:00:38+02:00 (10 years ago)
Author:
Don-vip
Message:

fix #7976 - Get downloaded gpx areas, on the same model as osm data

Location:
trunk/src/org/openstreetmap/josm
Files:
1 added
13 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/UpdateDataAction.java

    r7434 r7575  
    1414import org.openstreetmap.josm.Main;
    1515import org.openstreetmap.josm.actions.downloadtasks.DownloadTaskList;
    16 import org.openstreetmap.josm.data.osm.DataSource;
     16import org.openstreetmap.josm.data.DataSource;
    1717import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor;
    1818import org.openstreetmap.josm.io.OnlineResource;
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java

    r6990 r7575  
    106106        }
    107107
    108         @Override public void realRun() throws IOException, SAXException, OsmTransferException {
     108        @Override
     109        public void realRun() throws IOException, SAXException, OsmTransferException {
    109110            try {
    110111                if (isCanceled())
     
    123124        }
    124125
    125         @Override protected void finish() {
     126        @Override
     127        protected void finish() {
    126128            if (isCanceled() || isFailed())
    127129                return;
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java

    r7149 r7575  
    1414import org.openstreetmap.josm.Main;
    1515import org.openstreetmap.josm.data.Bounds;
     16import org.openstreetmap.josm.data.DataSource;
    1617import org.openstreetmap.josm.data.coor.LatLon;
    1718import org.openstreetmap.josm.data.osm.DataSet;
    18 import org.openstreetmap.josm.data.osm.DataSource;
    1919import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
    2020import org.openstreetmap.josm.gui.PleaseWaitRunnable;
  • trunk/src/org/openstreetmap/josm/data/DataSource.java

    r7573 r7575  
    11// License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.data.osm;
     2package org.openstreetmap.josm.data;
    33
    4 import org.openstreetmap.josm.data.Bounds;
     4import java.awt.geom.Area;
     5import java.util.ArrayList;
     6import java.util.Collection;
     7import java.util.List;
     8
    59import org.openstreetmap.josm.tools.CheckParameterUtil;
    610
    711/**
    812 * A data source, defined by bounds and textual description for the origin.
    9  * @since 247
     13 * @since 247 (creation)
     14 * @since 7575 (moved package)
    1015 */
    1116public class DataSource {
     17
    1218    /**
    1319     * The bounds of this data source
    1420     */
    1521    public final Bounds bounds;
     22
    1623    /**
    1724     * The textual description of the origin (example: "OpenStreetMap Server")
     
    3037        this.origin = origin;
    3138    }
     39
     40    @Override
     41    public int hashCode() {
     42        final int prime = 31;
     43        int result = 1;
     44        result = prime * result + ((bounds == null) ? 0 : bounds.hashCode());
     45        result = prime * result + ((origin == null) ? 0 : origin.hashCode());
     46        return result;
     47    }
     48
     49    @Override
     50    public boolean equals(Object obj) {
     51        if (this == obj)
     52            return true;
     53        if (obj == null)
     54            return false;
     55        if (getClass() != obj.getClass())
     56            return false;
     57        DataSource other = (DataSource) obj;
     58        if (bounds == null) {
     59            if (other.bounds != null)
     60                return false;
     61        } else if (!bounds.equals(other.bounds))
     62            return false;
     63        if (origin == null) {
     64            if (other.origin != null)
     65                return false;
     66        } else if (!origin.equals(other.origin))
     67            return false;
     68        return true;
     69    }
     70
     71    @Override
     72    public String toString() {
     73        return "DataSource [bounds=" + bounds + ", origin=" + origin + "]";
     74    }
     75
     76    /**
     77     * Returns the total area of downloaded data (the "yellow rectangles").
     78     * @param dataSources list of data sources
     79     * @return Area object encompassing downloaded data.
     80     * @see Data#getDataSourceArea()
     81     */
     82    public static Area getDataSourceArea(Collection<DataSource> dataSources) {
     83        if (dataSources == null || dataSources.isEmpty()) {
     84            return null;
     85        }
     86        Area a = new Area();
     87        for (DataSource source : dataSources) {
     88            // create area from data bounds
     89            a.add(new Area(source.bounds.asRect()));
     90        }
     91        return a;
     92    }
     93
     94    /**
     95     * <p>Replies the list of data source bounds.</p>
     96     *
     97     * <p>Dataset maintains a list of data sources which have been merged into the
     98     * data set. Each of these sources can optionally declare a bounding box of the
     99     * data it supplied to the dataset.</p>
     100     *
     101     * <p>This method replies the list of defined (non {@code null}) bounding boxes.</p>
     102     * @param dataSources list of data sources
     103     *
     104     * @return the list of data source bounds. An empty list, if no non-null data source
     105     * bounds are defined.
     106     * @see Data#getDataSourceBounds()
     107     */
     108    public static List<Bounds> getDataSourceBounds(Collection<DataSource> dataSources) {
     109        if (dataSources == null) {
     110            return null;
     111        }
     112        List<Bounds> ret = new ArrayList<>(dataSources.size());
     113        for (DataSource ds : dataSources) {
     114            if (ds.bounds != null) {
     115                ret.add(ds.bounds);
     116            }
     117        }
     118        return ret;
     119    }
    32120}
  • trunk/src/org/openstreetmap/josm/data/gpx/GpxConstants.java

    r7518 r7575  
    3939    public static final String META_NAME = META_PREFIX + "name";
    4040    public static final String META_TIME = META_PREFIX + "time";
     41    public static final String META_BOUNDS = META_PREFIX + "bounds";
    4142    public static final String META_EXTENSIONS = META_PREFIX + "extensions";
    4243
  • trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java

    r7518 r7575  
    22package org.openstreetmap.josm.data.gpx;
    33
     4import java.awt.geom.Area;
    45import java.io.File;
    56import java.util.Collection;
    67import java.util.Date;
     8import java.util.HashSet;
    79import java.util.Iterator;
    810import java.util.LinkedList;
     11import java.util.List;
    912import java.util.Map;
     13import java.util.Set;
    1014
    1115import org.openstreetmap.josm.Main;
    1216import org.openstreetmap.josm.data.Bounds;
     17import org.openstreetmap.josm.data.Data;
     18import org.openstreetmap.josm.data.DataSource;
    1319import org.openstreetmap.josm.data.coor.EastNorth;
    1420
     
    2026 * @author Raphael Mack &lt;ramack@raphael-mack.de&gt;
    2127 */
    22 public class GpxData extends WithAttributes {
     28public class GpxData extends WithAttributes implements Data {
    2329
    2430    public File storageFile;
     
    3036    public final Collection<GpxRoute> routes = new LinkedList<>();
    3137    public final Collection<WayPoint> waypoints = new LinkedList<>();
     38
     39    /**
     40     * All data sources (bounds of downloaded bounds) of this GpxData.<br>
     41     * Not part of GPX standard but rather a JOSM extension, needed by the fact that
     42     * OSM API does not provide {@code <bounds>} element in its GPX reply.
     43     * @since 7575
     44     */
     45    public final Set<DataSource> dataSources = new HashSet<>();
    3246
    3347    public void mergeFrom(GpxData other) {
     
    5266        routes.addAll(other.routes);
    5367        waypoints.addAll(other.waypoints);
    54     }
    55 
     68        dataSources.addAll(other.dataSources);
     69    }
     70
     71    /**
     72     * Determines if this GPX data has one or more track points
     73     * @return {@code true} if this GPX data has track points, {@code false} otherwise
     74     */
    5675    public boolean hasTrackPoints() {
    5776        for (GpxTrack trk : tracks) {
     
    6483    }
    6584
     85    /**
     86     * Determines if this GPX data has one or more route points
     87     * @return {@code true} if this GPX data has route points, {@code false} otherwise
     88     */
    6689    public boolean hasRoutePoints() {
    6790        for (GpxRoute rte : routes) {
     
    7295    }
    7396
     97    /**
     98     * Determines if this GPX data is empty (i.e. does not contain any point)
     99     * @return {@code true} if this GPX data is empty, {@code false} otherwise
     100     */
    74101    public boolean isEmpty() {
    75102        return !hasRoutePoints() && !hasTrackPoints() && waypoints.isEmpty();
     
    77104
    78105    /**
    79      * calculates the bounding box of available data and returns it.
     106     * Returns the bounds defining the extend of this data, as read in metadata, if any.
     107     * If no bounds is defined in metadata, {@code null} is returned. There is no guarantee
     108     * that data entirely fit in this bounds, as it is not recalculated. To get recalculated bounds,
     109     * see {@link #recalculateBounds()}. To get downloaded areas, see {@link #dataSources}.
     110     * @return the bounds defining the extend of this data, or {@code null}.
     111     * @see #recalculateBounds()
     112     * @see #dataSources
     113     * @since 7575
     114     */
     115    public Bounds getMetaBounds() {
     116        Object value = get(META_BOUNDS);
     117        if (value instanceof Bounds) {
     118            return (Bounds) value;
     119        }
     120        return null;
     121    }
     122
     123    /**
     124     * Calculates the bounding box of available data and returns it.
    80125     * The bounds are not stored internally, but recalculated every time
    81      * this function is called.
     126     * this function is called.<br>
     127     * To get bounds as read from metadata, see {@link #getMetaBounds()}.<br>
     128     * To get downloaded areas, see {@link #dataSources}.<br>
    82129     *
    83130     * FIXME might perhaps use visitor pattern?
    84131     * @return the bounds
     132     * @see #getMetaBounds()
     133     * @see #dataSources
    85134     */
    86135    public Bounds recalculateBounds() {
     
    119168     * @return the length in meters
    120169     */
    121     public double length(){
     170    public double length() {
    122171        double result = 0.0; // in meters
    123172
     
    402451    }
    403452
     453    @Override
     454    public Collection<DataSource> getDataSources() {
     455        return dataSources;
     456    }
     457
     458    @Override
     459    public Area getDataSourceArea() {
     460        return DataSource.getDataSourceArea(dataSources);
     461    }
     462
     463    @Override
     464    public List<Bounds> getDataSourceBounds() {
     465        return DataSource.getDataSourceBounds(dataSources);
     466    }
    404467}
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r7501 r7575  
    2424import org.openstreetmap.josm.Main;
    2525import org.openstreetmap.josm.data.Bounds;
     26import org.openstreetmap.josm.data.Data;
     27import org.openstreetmap.josm.data.DataSource;
    2628import org.openstreetmap.josm.data.SelectionChangedListener;
    2729import org.openstreetmap.josm.data.coor.EastNorth;
     
    9092 * @author imi
    9193 */
    92 public final class DataSet implements Cloneable, ProjectionChangeListener {
     94public final class DataSet implements Data, Cloneable, ProjectionChangeListener {
    9395
    9496    /**
     
    916918    }
    917919
    918     /**
    919      * Returns the total area of downloaded data (the "yellow rectangles").
    920      * @return Area object encompassing downloaded data.
    921      */
     920    @Override
     921    public Collection<DataSource> getDataSources() {
     922        return dataSources;
     923    }
     924
     925    @Override
    922926    public Area getDataSourceArea() {
    923         if (dataSources.isEmpty()) return null;
    924         Area a = new Area();
    925         for (DataSource source : dataSources) {
    926             // create area from data bounds
    927             a.add(new Area(source.bounds.asRect()));
    928         }
    929         return a;
     927        return DataSource.getDataSourceArea(dataSources);
    930928    }
    931929
     
    13171315    }
    13181316
    1319     /**
    1320      * <p>Replies the list of data source bounds.</p>
    1321      *
    1322      * <p>Dataset maintains a list of data sources which have been merged into the
    1323      * data set. Each of these sources can optionally declare a bounding box of the
    1324      * data it supplied to the dataset.</p>
    1325      *
    1326      * <p>This method replies the list of defined (non {@code null}) bounding boxes.</p>
    1327      *
    1328      * @return the list of data source bounds. An empty list, if no non-null data source
    1329      * bounds are defined.
    1330      */
     1317    @Override
    13311318    public List<Bounds> getDataSourceBounds() {
    1332         List<Bounds> ret = new ArrayList<>(dataSources.size());
    1333         for (DataSource ds : dataSources) {
    1334             if (ds.bounds != null) {
    1335                 ret.add(ds.bounds);
    1336             }
    1337         }
    1338         return ret;
     1319        return DataSource.getDataSourceBounds(dataSources);
    13391320    }
    13401321
  • trunk/src/org/openstreetmap/josm/gui/MapView.java

    r7534 r7575  
    4242import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent;
    4343import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener;
     44import org.openstreetmap.josm.data.DataSource;
    4445import org.openstreetmap.josm.data.SelectionChangedListener;
    4546import org.openstreetmap.josm.data.ViewportData;
     
    4849import org.openstreetmap.josm.data.imagery.ImageryInfo;
    4950import org.openstreetmap.josm.data.osm.DataSet;
    50 import org.openstreetmap.josm.data.osm.DataSource;
    5151import org.openstreetmap.josm.data.osm.OsmPrimitive;
    5252import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/ParentRelationLoadingTask.java

    r7005 r7575  
    1212
    1313import org.openstreetmap.josm.Main;
     14import org.openstreetmap.josm.data.DataSource;
    1415import org.openstreetmap.josm.data.osm.DataSet;
    1516import org.openstreetmap.josm.data.osm.DataSetMerger;
    16 import org.openstreetmap.josm.data.osm.DataSource;
    1717import org.openstreetmap.josm.data.osm.Relation;
    1818import org.openstreetmap.josm.gui.PleaseWaitRunnable;
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r7518 r7575  
    4747import org.openstreetmap.josm.data.APIDataSet;
    4848import org.openstreetmap.josm.data.Bounds;
     49import org.openstreetmap.josm.data.DataSource;
    4950import org.openstreetmap.josm.data.SelectionChangedListener;
    5051import org.openstreetmap.josm.data.conflict.Conflict;
     
    5960import org.openstreetmap.josm.data.osm.DataSet;
    6061import org.openstreetmap.josm.data.osm.DataSetMerger;
    61 import org.openstreetmap.josm.data.osm.DataSource;
    6262import org.openstreetmap.josm.data.osm.DatasetConsistencyTest;
    6363import org.openstreetmap.josm.data.osm.IPrimitive;
  • trunk/src/org/openstreetmap/josm/io/BoundingBoxDownloader.java

    r7531 r7575  
    1010import org.openstreetmap.josm.Main;
    1111import org.openstreetmap.josm.data.Bounds;
     12import org.openstreetmap.josm.data.DataSource;
    1213import org.openstreetmap.josm.data.gpx.GpxData;
    1314import org.openstreetmap.josm.data.notes.Note;
     
    4546    }
    4647
    47     private GpxData downloadRawGps(String url, ProgressMonitor progressMonitor) throws IOException, OsmTransferException, SAXException {
     48    private GpxData downloadRawGps(Bounds b, ProgressMonitor progressMonitor) throws IOException, OsmTransferException, SAXException {
    4849        boolean done = false;
    4950        GpxData result = null;
     51        String url = "trackpoints?bbox="+b.getMinLon()+","+b.getMinLat()+","+b.getMaxLon()+","+b.getMaxLat()+"&page=";
    5052        for (int i = 0;!done;++i) {
    5153            progressMonitor.subTask(tr("Downloading points {0} to {1}...", i * 5000, ((i + 1) * 5000)));
     
    7072        if (result != null) {
    7173            result.fromServer = true;
     74            result.dataSources.add(new DataSource(b, "OpenStreetMap server"));
    7275        }
    7376        return result;
     
    8184            if (crosses180th) {
    8285                // API 0.6 does not support requests crossing the 180th meridian, so make two requests
    83                 GpxData result = downloadRawGps("trackpoints?bbox="+lon1+","+lat1+",180.0,"+lat2+"&page=", progressMonitor);
    84                 result.mergeFrom(downloadRawGps("trackpoints?bbox=-180.0,"+lat1+","+lon2+","+lat2+"&page=", progressMonitor));
     86                GpxData result = downloadRawGps(new Bounds(lat1, lon1, lat2, 180.0), progressMonitor);
     87                result.mergeFrom(downloadRawGps(new Bounds(lat1, -180.0, lat2, lon2), progressMonitor));
    8588                return result;
    8689            } else {
    8790                // Simple request
    88                 return downloadRawGps("trackpoints?bbox="+lon1+","+lat1+","+lon2+","+lat2+"&page=", progressMonitor);
     91                return downloadRawGps(new Bounds(lat1, lon1, lat2, lon2), progressMonitor);
    8992            }
    9093        } catch (IllegalArgumentException e) {
  • trunk/src/org/openstreetmap/josm/io/GpxReader.java

    r7518 r7575  
    2121
    2222import org.openstreetmap.josm.Main;
     23import org.openstreetmap.josm.data.Bounds;
    2324import org.openstreetmap.josm.data.coor.LatLon;
    2425import org.openstreetmap.josm.data.gpx.Extensions;
     
    3839 * Read a gpx file.
    3940 *
    40  * Bounds are not read, as we caluclate them. @see GpxData.recalculateBounds()
     41 * Bounds are read, even if we calculate them, see {@link GpxData#recalculateBounds}.<br>
    4142 * Both GPX version 1.0 and 1.1 are supported.
    4243 *
     
    7374        private boolean nokiaSportsTrackerBug = false;
    7475
    75         @Override public void startDocument() {
     76        @Override
     77        public void startDocument() {
    7678            accumulator = new StringBuffer();
    7779            states = new Stack<>();
     
    162164                    currentState = State.link;
    163165                    currentLink = new GpxLink(atts.getValue("href"));
     166                    break;
     167                case "bounds":
     168                    data.put(META_BOUNDS, new Bounds(
     169                                parseCoord(atts.getValue("minlat")),
     170                                parseCoord(atts.getValue("minlon")),
     171                                parseCoord(atts.getValue("maxlat")),
     172                                parseCoord(atts.getValue("maxlon"))));
    164173                }
    165174                break;
     
    312321                        break;
    313322                    }
     323                case "bounds":
     324                    // do nothing, has been parsed on startElement
     325                    break;
    314326                default:
    315                     //TODO: parse bounds, extensions
     327                    //TODO: parse extensions
    316328                }
    317329                break;
  • trunk/src/org/openstreetmap/josm/io/OsmReader.java

    r7299 r7575  
    2121import org.openstreetmap.josm.Main;
    2222import org.openstreetmap.josm.data.Bounds;
     23import org.openstreetmap.josm.data.DataSource;
    2324import org.openstreetmap.josm.data.coor.LatLon;
    2425import org.openstreetmap.josm.data.osm.Changeset;
    2526import org.openstreetmap.josm.data.osm.DataSet;
    26 import org.openstreetmap.josm.data.osm.DataSource;
    2727import org.openstreetmap.josm.data.osm.Node;
    2828import org.openstreetmap.josm.data.osm.NodeData;
  • trunk/src/org/openstreetmap/josm/io/OsmWriter.java

    r7299 r7575  
    1212import java.util.Map.Entry;
    1313
     14import org.openstreetmap.josm.data.DataSource;
    1415import org.openstreetmap.josm.data.coor.CoordinateFormat;
    1516import org.openstreetmap.josm.data.coor.LatLon;
    1617import org.openstreetmap.josm.data.osm.Changeset;
    1718import org.openstreetmap.josm.data.osm.DataSet;
    18 import org.openstreetmap.josm.data.osm.DataSource;
    1919import org.openstreetmap.josm.data.osm.INode;
    2020import org.openstreetmap.josm.data.osm.IPrimitive;
Note: See TracChangeset for help on using the changeset viewer.