Skip to content

Commit 7a9ba25

Browse files
fanevanjanaharynyalldawson
authored andcommitted
[FEATURE] Add dX, dY and residual on GCP Points (#8513)
* add dX, dY and residual on GCP Points * add option to automatically save GCP Points in the raster-modified path
1 parent 4c3e43b commit 7a9ba25

5 files changed

+209
-186
lines changed

src/plugins/georeferencer/qgsgeorefplugingui.cpp

+14-5
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ bool QgsGeorefPluginGui::getTransformSettings()
341341
}
342342

343343
d.getTransformSettings( mTransformParam, mResamplingMethod, mCompressionMethod,
344-
mModifiedRasterFileName, mProjection, mPdfOutputMapFile, mPdfOutputFile, mUseZeroForTrans, mLoadInQgis, mUserResX, mUserResY );
344+
mModifiedRasterFileName, mProjection, mPdfOutputMapFile, mPdfOutputFile, mSaveGcp, mUseZeroForTrans, mLoadInQgis, mUserResX, mUserResY );
345345
mTransformParamLabel->setText( tr( "Transform: " ) + convertTransformEnumToString( mTransformParam ) );
346346
mGeorefTransform.selectTransformParametrisation( mTransformParam );
347347
mGCPListWidget->setGeorefTransform( &mGeorefTransform );
@@ -1250,7 +1250,7 @@ bool QgsGeorefPluginGui::loadGCPs( /*bool verbose*/ )
12501250

12511251
QgsPointXY mapCoords( ls.at( 0 ).toDouble(), ls.at( 1 ).toDouble() ); // map x,y
12521252
QgsPointXY pixelCoords( ls.at( 2 ).toDouble(), ls.at( 3 ).toDouble() ); // pixel x,y
1253-
if ( ls.count() == 5 )
1253+
if ( ls.count() == 5 || ls.count() == 8 )
12541254
{
12551255
bool enable = ls.at( 4 ).toInt();
12561256
addPoint( pixelCoords, mapCoords, enable, false );
@@ -1280,15 +1280,19 @@ void QgsGeorefPluginGui::saveGCPs()
12801280
if ( pointFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
12811281
{
12821282
QTextStream points( &pointFile );
1283-
points << "mapX,mapY,pixelX,pixelY,enable" << endl;
1283+
points << "mapX,mapY,pixelX,pixelY,enable,dX,dY,residual" << endl;
12841284
Q_FOREACH ( QgsGeorefDataPoint *pt, mPoints )
12851285
{
1286-
points << QStringLiteral( "%1,%2,%3,%4,%5" )
1286+
points << QStringLiteral( "%1,%2,%3,%4,%5,%6,%7,%8" )
12871287
.arg( qgsDoubleToString( pt->mapCoords().x() ),
12881288
qgsDoubleToString( pt->mapCoords().y() ),
12891289
qgsDoubleToString( pt->pixelCoords().x() ),
12901290
qgsDoubleToString( pt->pixelCoords().y() ) )
1291-
.arg( pt->isEnabled() ) << endl;
1291+
.arg( pt->isEnabled() )
1292+
.arg( qgsDoubleToString( pt->residual().x() ),
1293+
qgsDoubleToString( pt->residual().y() ),
1294+
qgsDoubleToString( std::sqrt( pt->residual().x() * pt->residual().x() + pt->residual().y() * pt->residual().y() ) ) )
1295+
<< endl;
12921296
}
12931297

12941298
mInitialPoints = mPoints;
@@ -1410,6 +1414,11 @@ bool QgsGeorefPluginGui::georeference()
14101414
{
14111415
writePDFMapFile( mPdfOutputMapFile, mGeorefTransform );
14121416
}
1417+
if ( !mSaveGcp.isEmpty() )
1418+
{
1419+
mGCPpointsFileName = mModifiedRasterFileName + QLatin1String( ".points" );
1420+
saveGCPs();
1421+
}
14131422
return true;
14141423
}
14151424
}

src/plugins/georeferencer/qgsgeorefplugingui.h

+2
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ class QgsGeorefPluginGui : public QMainWindow, private Ui::QgsGeorefPluginGuiBas
228228
QgsCoordinateReferenceSystem mProjection;
229229
QString mPdfOutputFile;
230230
QString mPdfOutputMapFile;
231+
QString mSaveGcp;
231232
double mUserResX, mUserResY; // User specified target scale
232233

233234
QgsGeorefTransform::TransformParametrisation mTransformParam;
@@ -260,6 +261,7 @@ class QgsGeorefPluginGui : public QMainWindow, private Ui::QgsGeorefPluginGuiBas
260261
bool mGCPsDirty;
261262
bool mLoadInQgis;
262263

264+
263265
QgsDockWidget *mDock = nullptr;
264266
int messageTimeout();
265267
};

src/plugins/georeferencer/qgstransformsettingsdialog.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ QgsTransformSettingsDialog::QgsTransformSettingsDialog( const QString &raster, c
121121

122122
cbxZeroAsTrans->setChecked( settings.value( QStringLiteral( "/Plugin-GeoReferencer/zeroastrans" ), false ).toBool() );
123123
cbxLoadInQgisWhenDone->setChecked( settings.value( QStringLiteral( "/Plugin-GeoReferencer/loadinqgis" ), false ).toBool() );
124+
saveGcpCheckBox->setChecked( settings.value( QStringLiteral( "/Plugin-GeoReferencer/save_gcp_points" ), false ).toBool() );
125+
124126
}
125127

126128
QgsTransformSettingsDialog::~QgsTransformSettingsDialog()
@@ -132,7 +134,7 @@ QgsTransformSettingsDialog::~QgsTransformSettingsDialog()
132134
void QgsTransformSettingsDialog::getTransformSettings( QgsGeorefTransform::TransformParametrisation &tp,
133135
QgsImageWarper::ResamplingMethod &rm,
134136
QString &comprMethod, QString &raster,
135-
QgsCoordinateReferenceSystem &proj, QString &pdfMapFile, QString &pdfReportFile, bool &zt, bool &loadInQgis,
137+
QgsCoordinateReferenceSystem &proj, QString &pdfMapFile, QString &pdfReportFile, QString &gcpPoints, bool &zt, bool &loadInQgis,
136138
double &resX, double &resY )
137139
{
138140
if ( cmbTransformType->currentIndex() == -1 )
@@ -162,6 +164,10 @@ void QgsTransformSettingsDialog::getTransformSettings( QgsGeorefTransform::Trans
162164
resX = dsbHorizRes->value();
163165
resY = dsbVerticalRes->value();
164166
}
167+
if ( saveGcpCheckBox->isChecked() )
168+
{
169+
gcpPoints = mOutputRaster->filePath();
170+
}
165171
}
166172

167173
void QgsTransformSettingsDialog::resetSettings()
@@ -173,6 +179,7 @@ void QgsTransformSettingsDialog::resetSettings()
173179
s.setValue( QStringLiteral( "/Plugin-GeoReferencer/targetsrs" ), QString() );
174180
s.setValue( QStringLiteral( "/Plugin-GeoReferencer/zeroastrans" ), false );
175181
s.setValue( QStringLiteral( "/Plugin-GeoReferencer/loadinqgis" ), false );
182+
s.setValue( QStringLiteral( "/Plugin-GeoReferencer/save_gcp_points" ), false );
176183
s.setValue( QStringLiteral( "/Plugin-GeoReferencer/user_specified_resolution" ), false );
177184
s.setValue( QStringLiteral( "/Plugin-GeoReferencer/user_specified_resx" ), 1.0 );
178185
s.setValue( QStringLiteral( "/Plugin-GeoReferencer/user_specified_resy" ), -1.0 );
@@ -227,6 +234,8 @@ void QgsTransformSettingsDialog::accept()
227234
settings.setValue( QStringLiteral( "/Plugin-GeoReferencer/user_specified_resx" ), dsbHorizRes->value() );
228235
settings.setValue( QStringLiteral( "/Plugin-GeoReferencer/user_specified_resy" ), dsbVerticalRes->value() );
229236
settings.setValue( QStringLiteral( "/Plugin-GeoReferencer/word_file_checkbox" ), mWorldFileCheckBox->isChecked() );
237+
settings.setValue( QStringLiteral( "/Plugin-GeoReferencer/save_gcp_points" ), saveGcpCheckBox->isChecked() );
238+
230239

231240
QDialog::accept();
232241
}

src/plugins/georeferencer/qgstransformsettingsdialog.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class QgsTransformSettingsDialog : public QDialog, private Ui::QgsTransformSetti
3333
~QgsTransformSettingsDialog() override;
3434
void getTransformSettings( QgsGeorefTransform::TransformParametrisation &tp,
3535
QgsImageWarper::ResamplingMethod &rm, QString &comprMethod,
36-
QString &raster, QgsCoordinateReferenceSystem &proj, QString &pdfMapFile, QString &pdfReportFile, bool &zt, bool &loadInQgis,
36+
QString &raster, QgsCoordinateReferenceSystem &proj, QString &pdfMapFile, QString &pdfReportFile, QString &gcpPoints, bool &zt, bool &loadInQgis,
3737
double &resX, double &resY );
3838
static void resetSettings();
3939

0 commit comments

Comments
 (0)