Skip to content
Permalink
Browse files

[georeferencer] NEVER load raster file being referenced into the

current project

This was likely a decades old hack in order to get the layer to
show in the georeferencer canvas, but it's not needed now
and definitely not wanted.

Loading into the project as a hidden layer just complicates things,
and runs into all sorts of issues such as users saving a project
while a georeference is in project leaves around hidden ghost
layers in the project...

(cherry picked from commit ede3ca2)
  • Loading branch information
nyalldawson committed Feb 21, 2021
1 parent 54c76a7 commit ea4bc09867b5dfde7d3cf6285dfeeb46c0ef4638
Showing with 17 additions and 62 deletions.
  1. +10 −51 src/app/georeferencer/qgsgeorefmainwindow.cpp
  2. +7 −11 src/app/georeferencer/qgsgeorefmainwindow.h
@@ -76,12 +76,6 @@ QgsGeorefDockWidget::QgsGeorefDockWidget( const QString &title, QWidget *parent,

QgsGeoreferencerMainWindow::QgsGeoreferencerMainWindow( QWidget *parent, Qt::WindowFlags fl )
: QMainWindow( parent, fl )
, mMousePrecisionDecimalPlaces( 0 )
, mTransformParam( QgsGeorefTransform::InvalidTransform )
, mAgainAddRaster( false )
, mMapCoordsDialog( nullptr )
, mUseZeroForTrans( false )
, mLoadInQgis( false )
{
setupUi( this );
QgsGui::instance()->enableAutoGeometryRestore( this );
@@ -285,7 +279,9 @@ void QgsGeoreferencerMainWindow::openRaster( const QString &fileName )
mGCPpointsFileName = mRasterFileName + ".points";
( void )loadGCPs();

mCanvas->setExtent( mLayer->extent() );
if ( mLayer )
mCanvas->setExtent( mLayer->extent() );

mCanvas->refresh();
QgisApp::instance()->mapCanvas()->refresh();

@@ -689,7 +685,7 @@ void QgsGeoreferencerMainWindow::showRasterPropertiesDialog()
{
if ( mLayer )
{
QgisApp::instance()->showLayerProperties( mLayer );
QgisApp::instance()->showLayerProperties( mLayer.get() );
}
else
{
@@ -734,7 +730,7 @@ void QgsGeoreferencerMainWindow::fullHistogramStretch()

void QgsGeoreferencerMainWindow::localHistogramStretch()
{
QgsRectangle rectangle = QgisApp::instance()->mapCanvas()->mapSettings().outputExtentToLayerExtent( mLayer, QgisApp::instance()->mapCanvas()->extent() );
QgsRectangle rectangle = QgisApp::instance()->mapCanvas()->mapSettings().outputExtentToLayerExtent( mLayer.get(), QgisApp::instance()->mapCanvas()->extent() );

mLayer->setContrastEnhancement( QgsContrastEnhancement::StretchToMinimumMaximum, QgsRasterMinMaxOrigin::MinMax, rectangle );
mCanvas->refresh();
@@ -867,28 +863,6 @@ void QgsGeoreferencerMainWindow::updateMouseCoordinatePrecision()
mMousePrecisionDecimalPlaces = dp;
}

void QgsGeoreferencerMainWindow::extentsChanged()
{
if ( mAgainAddRaster )
{
if ( QFile::exists( mRasterFileName ) )
{
addRaster( mRasterFileName );
}
else
{
mLayer = nullptr;
mAgainAddRaster = false;
}
}
}

// Registry layer QGis
void QgsGeoreferencerMainWindow::layerWillBeRemoved( const QString &layerId )
{
mAgainAddRaster = mLayer && mLayer->id().compare( layerId ) == 0;
}

// ------------------------------ private ---------------------------------- //
// Gui
void QgsGeoreferencerMainWindow::createActions()
@@ -1173,11 +1147,6 @@ void QgsGeoreferencerMainWindow::setupConnections()
// Connect status from ZoomLast/ZoomNext to corresponding action
connect( mCanvas, &QgsMapCanvas::zoomLastStatusChanged, mActionZoomLast, &QAction::setEnabled );
connect( mCanvas, &QgsMapCanvas::zoomNextStatusChanged, mActionZoomNext, &QAction::setEnabled );
// Connect when one Layer is removed - Case where change the Projetct in QGIS
connect( QgsProject::instance(), static_cast<void ( QgsProject::* )( const QString & )>( &QgsProject::layerWillBeRemoved ), this, &QgsGeoreferencerMainWindow::layerWillBeRemoved );

// Connect extents changed - Use for need add again Raster
connect( mCanvas, &QgsMapCanvas::extentsChanged, this, &QgsGeoreferencerMainWindow::extentsChanged );

// Connect mapCanvas rotation widget
connect( mRotationEdit, static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ), this, &QgsGeoreferencerMainWindow::updateCanvasRotation );
@@ -1186,13 +1155,8 @@ void QgsGeoreferencerMainWindow::setupConnections()

void QgsGeoreferencerMainWindow::removeOldLayer()
{
// delete layer (and don't signal it as it's our private layer)
if ( mLayer )
{
QgsProject::instance()->removeMapLayers(
( QStringList() << mLayer->id() ) );
mLayer = nullptr;
}
mLayer.reset();

mCanvas->setLayers( QList<QgsMapLayer *>() );
mCanvas->clearCache();
mRotationEdit->clear();
@@ -1202,16 +1166,11 @@ void QgsGeoreferencerMainWindow::removeOldLayer()
// Mapcanvas Plugin
void QgsGeoreferencerMainWindow::addRaster( const QString &file )
{
mLayer = new QgsRasterLayer( file, QStringLiteral( "Raster" ) );

// so layer is not added to legend
QgsProject::instance()->addMapLayers(
QList<QgsMapLayer *>() << mLayer, false, false );
QgsRasterLayer::LayerOptions options;
mLayer = qgis::make_unique< QgsRasterLayer >( file, QStringLiteral( "Raster" ), QStringLiteral( "gdal" ), options );

// add layer to map canvas
mCanvas->setLayers( QList<QgsMapLayer *>() << mLayer );

mAgainAddRaster = false;
mCanvas->setLayers( QList<QgsMapLayer *>() << mLayer.get() );

mActionLocalHistogramStretch->setEnabled( true );
mActionFullHistogramStretch->setEnabled( true );
@@ -19,6 +19,8 @@
#include "qgsimagewarper.h"
#include "qgscoordinatereferencesystem.h"

#include <memory>

#include <QPointer>

class QAction;
@@ -118,11 +120,6 @@ class QgsGeoreferencerMainWindow : public QMainWindow, private Ui::QgsGeorefPlug
void localHistogramStretch();
void fullHistogramStretch();


// when one Layer is removed
void layerWillBeRemoved( const QString &layerId );
void extentsChanged(); // Use for need add again Raster (case above)

bool updateGeorefTransform();
void invalidateCanvasCoords();

@@ -218,7 +215,7 @@ class QgsGeoreferencerMainWindow : public QMainWindow, private Ui::QgsGeorefPlug
QLabel *mEPSG = nullptr;
QLabel *mRotationLabel = nullptr;
QgsDoubleSpinBox *mRotationEdit = nullptr;
unsigned int mMousePrecisionDecimalPlaces;
unsigned int mMousePrecisionDecimalPlaces = 0;

QString mRasterFileName;
QString mModifiedRasterFileName;
@@ -232,16 +229,15 @@ class QgsGeoreferencerMainWindow : public QMainWindow, private Ui::QgsGeorefPlug
QString mSaveGcp;
double mUserResX, mUserResY; // User specified target scale

QgsGeorefTransform::TransformParametrisation mTransformParam;
QgsGeorefTransform::TransformParametrisation mTransformParam = QgsGeorefTransform::InvalidTransform;
QgsImageWarper::ResamplingMethod mResamplingMethod;
QgsGeorefTransform mGeorefTransform;
QString mCompressionMethod;

QgsGCPList mPoints;
QgsGCPList mInitialPoints;
QgsMapCanvas *mCanvas = nullptr;
QgsRasterLayer *mLayer = nullptr;
bool mAgainAddRaster;
std::unique_ptr< QgsRasterLayer > mLayer;

QgsMapTool *mToolZoomIn = nullptr;
QgsMapTool *mToolZoomOut = nullptr;
@@ -256,10 +252,10 @@ class QgsGeoreferencerMainWindow : public QMainWindow, private Ui::QgsGeorefPlug
QgsGeorefDataPoint *mMovingPointQgis = nullptr;
QPointer<QgsMapCoordsDialog> mMapCoordsDialog;

bool mUseZeroForTrans;
bool mUseZeroForTrans = false;
bool mExtentsChangedRecursionGuard;
bool mGCPsDirty;
bool mLoadInQgis;
bool mLoadInQgis = false;


QgsDockWidget *mDock = nullptr;

0 comments on commit ea4bc09

Please sign in to comment.