Skip to content

Commit

Permalink
Merge pull request #58584 from nirvn/processing_openstreetmap_policy
Browse files Browse the repository at this point in the history
Further safeguards from (perceived or actual) bulk download of OpenStreetMap tiles
  • Loading branch information
nirvn authored Sep 12, 2024
2 parents 8448cf8 + 7fa383d commit 73ab085
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions python/PyQt6/core/auto_generated/qgsmaplayerutils.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@




class QgsMapLayerUtils
{
%Docstring(signature="appended")
Expand Down
1 change: 1 addition & 0 deletions python/core/auto_generated/qgsmaplayerutils.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@




class QgsMapLayerUtils
{
%Docstring(signature="appended")
Expand Down
1 change: 1 addition & 0 deletions resources/qgis_global_settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ xyz\items\OpenStreetMap\url=https://tile.openstreetmap.org/{z}/{x}/{y}.png
xyz\items\OpenStreetMap\username=
xyz\items\OpenStreetMap\zmax=19
xyz\items\OpenStreetMap\zmin=0
xyz\items\OpenStreetMap\tile-pixel-ratio=1

xyz\items\Mapzen Global Terrain\authcfg=
xyz\items\Mapzen Global Terrain\password=
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/processing/qgsalgorithmrasterize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ QVariantMap QgsRasterizeAlgorithm::processAlgorithm( const QVariantMap &paramete
}
feedback->pushInfo( QStringLiteral( "%1" ).arg( totalTiles ) );

if ( totalTiles > 5000 )
if ( totalTiles > MAXIMUM_OPENSTREETMAP_TILES_FETCH )
{
// Prevent bulk downloading of tiles from openstreetmap.org as per OSMF tile usage policy
feedback->pushFormattedMessage( QObject::tr( "Layer %1 will be skipped as the algorithm leads to bulk downloading behavior which is prohibited by the %2OpenStreetMap Foundation tile usage policy%3" ).arg( rasterLayer->name(), QStringLiteral( "<a href=\"https://operations.osmfoundation.org/policies/tiles/\">" ), QStringLiteral( "</a>" ) ),
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/processing/qgsalgorithmxyztiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ bool QgsXyzTilesBaseAlgorithm::prepareAlgorithm( const QVariantMap &parameters,

void QgsXyzTilesBaseAlgorithm::checkLayersUsagePolicy( QgsProcessingFeedback *feedback )
{
if ( mTotalTiles > 5000 )
if ( mTotalTiles > MAXIMUM_OPENSTREETMAP_TILES_FETCH )
{
for ( QgsMapLayer *layer : std::as_const( mLayers ) )
{
Expand Down
2 changes: 2 additions & 0 deletions src/core/qgsmaplayerutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#ifndef QGSMAPLAYERUTILS_H
#define QGSMAPLAYERUTILS_H

#define MAXIMUM_OPENSTREETMAP_TILES_FETCH 5000

#include "qgis_sip.h"
#include "qgis_core.h"
#include "qgis.h"
Expand Down
17 changes: 17 additions & 0 deletions src/gui/qgsrasterlayersaveasdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsapplication.h"
#include "qgsgdalutils.h"
#include "qgslogger.h"
#include "qgscoordinatetransform.h"
#include "qgsmaplayerutils.h"
#include "qgsrasterlayer.h"
#include "qgsrasterlayersaveasdialog.h"
#include "qgsrasterdataprovider.h"
Expand Down Expand Up @@ -963,6 +965,21 @@ void QgsRasterLayerSaveAsDialog::accept()
return;
}

if ( QgsMapLayerUtils::isOpenStreetMapLayer( mRasterLayer ) )
{
const int nbTilesWidth = std::ceil( nColumns() / 256 );
const int nbTilesHeight = std::ceil( nRows() / 256 );
int64_t totalTiles = static_cast<int64_t>( nbTilesWidth ) * nbTilesHeight;

if ( totalTiles > MAXIMUM_OPENSTREETMAP_TILES_FETCH )
{
QMessageBox::warning( this, tr( "Save Raster Layer" ),
tr( "The number of OpenStreetMap tiles needed to produce the raster layer is too large and will lead to bulk downloading behavior which is prohibited by the %1OpenStreetMap Foundation tile usage policy%2." ).arg( QStringLiteral( "<a href=\"https://operations.osmfoundation.org/policies/tiles/\">" ), QStringLiteral( "</a>" ) ),
QMessageBox::Ok );
return;
}
}

if ( outputFormat() == QLatin1String( "GPKG" ) && outputLayerExists() &&
QMessageBox::warning( this, tr( "Save Raster Layer" ),
tr( "The layer %1 already exists in the target file, and overwriting layers in GeoPackage is not supported. "
Expand Down

0 comments on commit 73ab085

Please sign in to comment.