Skip to content

Commit

Permalink
[browsers] Prevent users from breaching the OSMF tile usage policy wh…
Browse files Browse the repository at this point in the history
…en exporting

the layer to file (both via the browser panel as well as the layer tree)
  • Loading branch information
nirvn committed Oct 6, 2024
1 parent 0bd1fce commit 35c4f1d
Showing 1 changed file with 17 additions and 0 deletions.
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 @@ -962,6 +964,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 > 5000 )
{
QMessageBox::warning( this, tr( "Save Raster Layer" ),
tr( "The number of OpenStreetMap tiles needed to produce the raster layer is too large and will leads 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 35c4f1d

Please sign in to comment.