Skip to content

Commit

Permalink
Cleanup handling of 'Create world file only' option
Browse files Browse the repository at this point in the history
(cherry picked from commit 4877003)
  • Loading branch information
nyalldawson committed Feb 14, 2022
1 parent c7423f2 commit f188c09
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 36 deletions.
16 changes: 10 additions & 6 deletions src/app/georeferencer/qgsgeorefmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ void QgsGeoreferencerMainWindow::reset()
{
mRasterFileName.clear();
mModifiedRasterFileName.clear();
mCreateWorldFileOnly = false;
setWindowTitle( tr( "Georeferencer" ) );

//delete old points
Expand Down Expand Up @@ -237,6 +238,7 @@ void QgsGeoreferencerMainWindow::openRaster( const QString &fileName )
mRasterFileName = fileName;
}
mModifiedRasterFileName.clear();
mCreateWorldFileOnly = false;

QString errMsg;
if ( !QgsRasterLayer::isValidRasterFileName( mRasterFileName, errMsg ) )
Expand Down Expand Up @@ -337,7 +339,7 @@ void QgsGeoreferencerMainWindow::doGeoreference()
mMessageBar->pushMessage( tr( "Georeference Successful" ), tr( "Raster was successfully georeferenced." ), Qgis::MessageLevel::Success );
if ( mLoadInQgis )
{
if ( mModifiedRasterFileName.isEmpty() )
if ( mCreateWorldFileOnly )
{
QgisApp::instance()->addRasterLayer( mRasterFileName, QFileInfo( mRasterFileName ).completeBaseName(), QString() );
}
Expand All @@ -353,13 +355,15 @@ bool QgsGeoreferencerMainWindow::getTransformSettings()
{
QgsTransformSettingsDialog d( mRasterFileName, mModifiedRasterFileName );
d.setTargetCrs( mTargetCrs );
d.setCreateWorldFileOnly( mCreateWorldFileOnly );
if ( !d.exec() )
{
return false;
}

d.getTransformSettings( mTransformParam, mResamplingMethod, mCompressionMethod,
mModifiedRasterFileName, mPdfOutputMapFile, mPdfOutputFile, mSaveGcp, mUseZeroForTrans, mLoadInQgis, mUserResX, mUserResY );
mCreateWorldFileOnly = d.createWorldFileOnly();
mTargetCrs = d.targetCrs();

mTransformParamLabel->setText( tr( "Transform: " ) + QgsGcpTransformerInterface::methodToString( mTransformParam ) );
Expand Down Expand Up @@ -1254,8 +1258,8 @@ bool QgsGeoreferencerMainWindow::georeference()
if ( !checkReadyGeoref() )
return false;

if ( mModifiedRasterFileName.isEmpty() && ( QgsGcpTransformerInterface::TransformMethod::Linear == mGeorefTransform.transformParametrisation() ||
QgsGcpTransformerInterface::TransformMethod::Helmert == mGeorefTransform.transformParametrisation() ) )
if ( mCreateWorldFileOnly && ( QgsGcpTransformerInterface::TransformMethod::Linear == mGeorefTransform.transformParametrisation() ||
QgsGcpTransformerInterface::TransformMethod::Helmert == mGeorefTransform.transformParametrisation() ) )
{
QgsPointXY origin;
double pixelXSize, pixelYSize, rotation;
Expand Down Expand Up @@ -1301,7 +1305,7 @@ bool QgsGeoreferencerMainWindow::georeference()
}
return true;
}
else // Helmert, Polinom 1, Polinom 2, Polinom 3
else
{
QgsImageWarper warper( this );
int res = warper.warpFile( mRasterFileName, mModifiedRasterFileName, mGeorefTransform,
Expand Down Expand Up @@ -1848,8 +1852,8 @@ bool QgsGeoreferencerMainWindow::checkReadyGeoref()
return false;
}

//MH: helmert transformation without warping disabled until qgis is able to read rotated rasters efficiently
if ( mModifiedRasterFileName.isEmpty() && QgsGcpTransformerInterface::TransformMethod::Linear != mTransformParam /*&& QgsGeorefTransform::Helmert != mTransformParam*/ )
if ( mCreateWorldFileOnly
&& ( QgsGcpTransformerInterface::TransformMethod::Linear != mTransformParam && QgsGcpTransformerInterface::TransformMethod::Helmert != mTransformParam ) )
{
QMessageBox::information( this, tr( "Georeferencer" ), tr( "Please set output raster name." ) );
getTransformSettings();
Expand Down
1 change: 1 addition & 0 deletions src/app/georeferencer/qgsgeorefmainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ class QgsGeoreferencerMainWindow : public QMainWindow, private Ui::QgsGeorefPlug
QgsImageWarper::ResamplingMethod mResamplingMethod;
QgsGeorefTransform mGeorefTransform;
QString mCompressionMethod;
bool mCreateWorldFileOnly = false;

QgsGCPList mPoints;
QList< QgsGcpPoint > mSavedPoints;
Expand Down
42 changes: 13 additions & 29 deletions src/app/georeferencer/qgstransformsettingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ QgsTransformSettingsDialog::QgsTransformSettingsDialog( const QString &raster, c
cmbResampling->setCurrentIndex( settings.value( QStringLiteral( "/Plugin-GeoReferencer/lastresampling" ), 0 ).toInt() );
cmbCompressionComboBox->setCurrentIndex( settings.value( QStringLiteral( "/Plugin-GeoReferencer/lastcompression" ), 0 ).toInt() );

mWorldFileCheckBox->setChecked( settings.value( QStringLiteral( "/Plugin-Georeferencer/word_file_checkbox" ), false ).toBool() );

cbxUserResolution->setChecked( settings.value( QStringLiteral( "/Plugin-Georeferencer/user_specified_resolution" ), false ).toBool() );
bool ok;
dsbHorizRes->setValue( settings.value( QStringLiteral( "/Plugin-GeoReferencer/user_specified_resx" ), .0 ).toDouble( &ok ) );
Expand All @@ -132,6 +130,17 @@ QgsCoordinateReferenceSystem QgsTransformSettingsDialog::targetCrs() const
return mCrsSelector->crs();
}

bool QgsTransformSettingsDialog::createWorldFileOnly() const
{
return mWorldFileCheckBox->isChecked();
}

void QgsTransformSettingsDialog::setCreateWorldFileOnly( bool enabled )
{
mWorldFileCheckBox->setChecked( enabled );
mWorldFileCheckBox_stateChanged( mWorldFileCheckBox->checkState() );
}

void QgsTransformSettingsDialog::getTransformSettings( QgsGeorefTransform::TransformMethod &tp,
QgsImageWarper::ResamplingMethod &rm,
QString &comprMethod, QString &raster, QString &pdfMapFile, QString &pdfReportFile, bool &saveGcpPoints, bool &zt, bool &loadInQgis,
Expand All @@ -144,14 +153,8 @@ void QgsTransformSettingsDialog::getTransformSettings( QgsGeorefTransform::Trans

rm = static_cast< QgsImageWarper::ResamplingMethod >( cmbResampling->currentData().toInt() );
comprMethod = cmbCompressionComboBox->currentData().toString();
if ( mWorldFileCheckBox->isChecked() )
{
raster.clear();
}
else
{
raster = mOutputRaster->filePath();
}
raster = mOutputRaster->filePath();

pdfMapFile = mPdfMap->filePath();
pdfReportFile = mPdfReport->filePath();
zt = cbxZeroAsTrans->isChecked();
Expand All @@ -166,23 +169,6 @@ void QgsTransformSettingsDialog::getTransformSettings( QgsGeorefTransform::Trans
saveGcpPoints = saveGcpCheckBox->isChecked();
}

void QgsTransformSettingsDialog::resetSettings()
{
QgsSettings s;
s.setValue( QStringLiteral( "/Plugin-GeoReferencer/lasttransformation" ), -1 );
s.setValue( QStringLiteral( "/Plugin-GeoReferencer/lastresampling" ), 0 );
s.setValue( QStringLiteral( "/Plugin-GeoReferencer/lastcompression" ), 0 );
s.setValue( QStringLiteral( "/Plugin-GeoReferencer/targetsrs" ), QString() );
s.setValue( QStringLiteral( "/Plugin-GeoReferencer/zeroastrans" ), false );
s.setValue( QStringLiteral( "/Plugin-GeoReferencer/loadinqgis" ), false );
s.setValue( QStringLiteral( "/Plugin-GeoReferencer/save_gcp_points" ), false );
s.setValue( QStringLiteral( "/Plugin-GeoReferencer/user_specified_resolution" ), false );
s.setValue( QStringLiteral( "/Plugin-GeoReferencer/user_specified_resx" ), 1.0 );
s.setValue( QStringLiteral( "/Plugin-GeoReferencer/user_specified_resy" ), -1.0 );
s.setValue( QStringLiteral( "/Plugin-GeoReferencer/word_file_checkbox" ), false );
s.setValue( QStringLiteral( "/Plugin-GeoReferencer/lastPDFReportDir" ), QDir::homePath() );
}

void QgsTransformSettingsDialog::accept()
{
if ( !mOutputRaster->filePath().isEmpty() )
Expand Down Expand Up @@ -216,10 +202,8 @@ void QgsTransformSettingsDialog::accept()
settings.setValue( QStringLiteral( "/Plugin-GeoReferencer/user_specified_resolution" ), cbxUserResolution->isChecked() );
settings.setValue( QStringLiteral( "/Plugin-GeoReferencer/user_specified_resx" ), dsbHorizRes->value() );
settings.setValue( QStringLiteral( "/Plugin-GeoReferencer/user_specified_resy" ), dsbVerticalRes->value() );
settings.setValue( QStringLiteral( "/Plugin-GeoReferencer/word_file_checkbox" ), mWorldFileCheckBox->isChecked() );
settings.setValue( QStringLiteral( "/Plugin-GeoReferencer/save_gcp_points" ), saveGcpCheckBox->isChecked() );


QDialog::accept();
}

Expand Down
11 changes: 10 additions & 1 deletion src/app/georeferencer/qgstransformsettingsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,20 @@ class QgsTransformSettingsDialog : public QDialog, private Ui::QgsTransformSetti
*/
QgsCoordinateReferenceSystem targetCrs() const;

/**
* Returns TRUE if the create world file only option is set.
*/
bool createWorldFileOnly() const;

/**
* Sets whether the create world file only option should be set.
*/
void setCreateWorldFileOnly( bool enabled );

void getTransformSettings( QgsGeorefTransform::TransformMethod &tp,
QgsImageWarper::ResamplingMethod &rm, QString &comprMethod,
QString &raster, QString &pdfMapFile, QString &pdfReportFile, bool &saveGcpPoints, bool &zt, bool &loadInQgis,
double &resX, double &resY );
static void resetSettings();

protected:
void accept() override;
Expand Down

0 comments on commit f188c09

Please sign in to comment.