Changeset 15447 in josm


Ignore:
Timestamp:
2019-10-10T12:05:16+02:00 (5 years ago)
Author:
GerdP
Message:

see #18122: Don't set download bounds for incomplete Overpass queries
apply 18122-v1.patch so that Overpass queries don't set download bounds unless they are detected to return a complete result. For now, this is only detected when the user query is empty or just a comment.
TODO: This detection should also detect user written queries which return complete data

Location:
trunk/src/org/openstreetmap/josm
Files:
4 edited

Legend:

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

    r15358 r15447  
    477477                    rememberErrorMessage(remark);
    478478                }
    479                 // need to synthesize a download bounds lest the visual indication of downloaded area doesn't work
    480                 dataSet.addDataSource(new DataSource(currentBounds != null ? currentBounds :
    481                     new Bounds(LatLon.ZERO), "OpenStreetMap server"));
     479                if (!(reader instanceof BoundingBoxDownloader)
     480                        || ((BoundingBoxDownloader) reader).considerAsFullDownload()) {
     481                    // need to synthesize a download bounds lest the visual indication of downloaded area doesn't work
     482                    dataSet.addDataSource(new DataSource(
     483                            currentBounds != null ? currentBounds : new Bounds(LatLon.ZERO), "OpenStreetMap server"));
     484                }
    482485            }
    483486
  • trunk/src/org/openstreetmap/josm/gui/download/OverpassDownloadSource.java

    r14418 r15447  
    5252 */
    5353public class OverpassDownloadSource implements DownloadSource<OverpassDownloadSource.OverpassDownloadData> {
     54    /** Overpass query to retrieve all nodes and related parent objects, */
     55    public static final String FULL_DOWNLOAD_QUERY = "[out:xml]; \n"
     56            + "(\n"
     57            + "    node({{bbox}});\n"
     58            + "<;\n"
     59            + ");\n"
     60            + "(._;>;);"
     61            + "out meta;";
    5462
    5563    @Override
     
    249257                        JOptionPane.YES_OPTION);
    250258                if (doFix) {
    251                     String repairedQuery = "[out:xml]; \n"
    252                             + query + "\n"
    253                             + "(\n"
    254                             + "    node({{bbox}});\n"
    255                             + "<;\n"
    256                             + ");\n"
    257                             + "(._;>;);"
    258                             + "out meta;";
    259                     this.overpassQuery.setText(repairedQuery);
     259                    this.overpassQuery.setText(FULL_DOWNLOAD_QUERY);
    260260                } else {
    261261                    return false;
  • trunk/src/org/openstreetmap/josm/io/BoundingBoxDownloader.java

    r14762 r15447  
    256256        }
    257257    }
     258
     259    /**
     260     * @return true if download is complete for the given bounding box (not filtered)
     261     */
     262    public boolean considerAsFullDownload() {
     263        return true;
     264    }
     265
    258266}
  • trunk/src/org/openstreetmap/josm/io/OverpassDownloadReader.java

    r14439 r15447  
    3131import org.openstreetmap.josm.data.osm.BBox;
    3232import org.openstreetmap.josm.data.osm.DataSet;
     33import org.openstreetmap.josm.data.osm.DataSetMerger;
    3334import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    3435import org.openstreetmap.josm.data.osm.PrimitiveId;
     
    3637import org.openstreetmap.josm.data.preferences.ListProperty;
    3738import org.openstreetmap.josm.data.preferences.StringProperty;
     39import org.openstreetmap.josm.gui.download.OverpassDownloadSource;
    3840import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    3941import org.openstreetmap.josm.io.NameFinder.SearchResult;
     
    385387
    386388        DataSet ds = super.parseOsm(progressMonitor);
    387 
    388         // add bounds if necessary (note that Overpass API does not return bounds in the response XML)
    389         if (ds != null && ds.getDataSources().isEmpty() && overpassQuery.contains("{{bbox}}")) {
    390             if (crosses180th) {
    391                 Bounds bounds = new Bounds(lat1, lon1, lat2, 180.0);
    392                 DataSource src = new DataSource(bounds, getBaseUrl());
    393                 ds.addDataSource(src);
    394 
    395                 bounds = new Bounds(lat1, -180.0, lat2, lon2);
    396                 src = new DataSource(bounds, getBaseUrl());
    397                 ds.addDataSource(src);
    398             } else {
    399                 Bounds bounds = new Bounds(lat1, lon1, lat2, lon2);
    400                 DataSource src = new DataSource(bounds, getBaseUrl());
    401                 ds.addDataSource(src);
    402             }
    403         }
    404 
    405         return ds;
     389        if (!considerAsFullDownload()) {
     390            DataSet noBounds = new DataSet();
     391            DataSetMerger dsm = new DataSetMerger(noBounds, ds);
     392            dsm.merge(null, false);
     393            return dsm.getTargetDataSet();
     394        } else {
     395            // add bounds if necessary (note that Overpass API does not return bounds in the response XML)
     396            if (ds != null && ds.getDataSources().isEmpty() && overpassQuery.contains("{{bbox}}")) {
     397                if (crosses180th) {
     398                    Bounds bounds = new Bounds(lat1, lon1, lat2, 180.0);
     399                    DataSource src = new DataSource(bounds, getBaseUrl());
     400                    ds.addDataSource(src);
     401
     402                    bounds = new Bounds(lat1, -180.0, lat2, lon2);
     403                    src = new DataSource(bounds, getBaseUrl());
     404                    ds.addDataSource(src);
     405                } else {
     406                    Bounds bounds = new Bounds(lat1, lon1, lat2, lon2);
     407                    DataSource src = new DataSource(bounds, getBaseUrl());
     408                    ds.addDataSource(src);
     409                }
     410            }
     411            return ds;
     412        }
    406413    }
    407414
     
    417424                .replaceAll("(?s)\\[out:(csv)[^\\]]*\\]", "[out:xml]");
    418425    }
     426
     427    @Override
     428    public boolean considerAsFullDownload() {
     429        return overpassQuery.equals(OverpassDownloadSource.FULL_DOWNLOAD_QUERY);
     430    }
    419431}
Note: See TracChangeset for help on using the changeset viewer.