Skip to content

Commit

Permalink
[FEATURE] Add dX, dY and residual on GCP Points (#8513)
Browse files Browse the repository at this point in the history
* add dX, dY and residual on GCP Points
* add option to automatically save GCP Points in the raster-modified path
  • Loading branch information
Fanevanjanahary authored and nyalldawson committed Nov 26, 2018
1 parent 4c3e43b commit 7a9ba25
Show file tree
Hide file tree
Showing 5 changed files with 209 additions and 186 deletions.
19 changes: 14 additions & 5 deletions src/plugins/georeferencer/qgsgeorefplugingui.cpp
Expand Up @@ -341,7 +341,7 @@ bool QgsGeorefPluginGui::getTransformSettings()
}

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

QgsPointXY mapCoords( ls.at( 0 ).toDouble(), ls.at( 1 ).toDouble() ); // map x,y
QgsPointXY pixelCoords( ls.at( 2 ).toDouble(), ls.at( 3 ).toDouble() ); // pixel x,y
if ( ls.count() == 5 )
if ( ls.count() == 5 || ls.count() == 8 )
{
bool enable = ls.at( 4 ).toInt();
addPoint( pixelCoords, mapCoords, enable, false );
Expand Down Expand Up @@ -1280,15 +1280,19 @@ void QgsGeorefPluginGui::saveGCPs()
if ( pointFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
{
QTextStream points( &pointFile );
points << "mapX,mapY,pixelX,pixelY,enable" << endl;
points << "mapX,mapY,pixelX,pixelY,enable,dX,dY,residual" << endl;
Q_FOREACH ( QgsGeorefDataPoint *pt, mPoints )
{
points << QStringLiteral( "%1,%2,%3,%4,%5" )
points << QStringLiteral( "%1,%2,%3,%4,%5,%6,%7,%8" )
.arg( qgsDoubleToString( pt->mapCoords().x() ),
qgsDoubleToString( pt->mapCoords().y() ),
qgsDoubleToString( pt->pixelCoords().x() ),
qgsDoubleToString( pt->pixelCoords().y() ) )
.arg( pt->isEnabled() ) << endl;
.arg( pt->isEnabled() )
.arg( qgsDoubleToString( pt->residual().x() ),
qgsDoubleToString( pt->residual().y() ),
qgsDoubleToString( std::sqrt( pt->residual().x() * pt->residual().x() + pt->residual().y() * pt->residual().y() ) ) )
<< endl;
}

mInitialPoints = mPoints;
Expand Down Expand Up @@ -1410,6 +1414,11 @@ bool QgsGeorefPluginGui::georeference()
{
writePDFMapFile( mPdfOutputMapFile, mGeorefTransform );
}
if ( !mSaveGcp.isEmpty() )
{
mGCPpointsFileName = mModifiedRasterFileName + QLatin1String( ".points" );
saveGCPs();
}
return true;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/georeferencer/qgsgeorefplugingui.h
Expand Up @@ -228,6 +228,7 @@ class QgsGeorefPluginGui : public QMainWindow, private Ui::QgsGeorefPluginGuiBas
QgsCoordinateReferenceSystem mProjection;
QString mPdfOutputFile;
QString mPdfOutputMapFile;
QString mSaveGcp;
double mUserResX, mUserResY; // User specified target scale

QgsGeorefTransform::TransformParametrisation mTransformParam;
Expand Down Expand Up @@ -260,6 +261,7 @@ class QgsGeorefPluginGui : public QMainWindow, private Ui::QgsGeorefPluginGuiBas
bool mGCPsDirty;
bool mLoadInQgis;


QgsDockWidget *mDock = nullptr;
int messageTimeout();
};
Expand Down
11 changes: 10 additions & 1 deletion src/plugins/georeferencer/qgstransformsettingsdialog.cpp
Expand Up @@ -121,6 +121,8 @@ QgsTransformSettingsDialog::QgsTransformSettingsDialog( const QString &raster, c

cbxZeroAsTrans->setChecked( settings.value( QStringLiteral( "/Plugin-GeoReferencer/zeroastrans" ), false ).toBool() );
cbxLoadInQgisWhenDone->setChecked( settings.value( QStringLiteral( "/Plugin-GeoReferencer/loadinqgis" ), false ).toBool() );
saveGcpCheckBox->setChecked( settings.value( QStringLiteral( "/Plugin-GeoReferencer/save_gcp_points" ), false ).toBool() );

}

QgsTransformSettingsDialog::~QgsTransformSettingsDialog()
Expand All @@ -132,7 +134,7 @@ QgsTransformSettingsDialog::~QgsTransformSettingsDialog()
void QgsTransformSettingsDialog::getTransformSettings( QgsGeorefTransform::TransformParametrisation &tp,
QgsImageWarper::ResamplingMethod &rm,
QString &comprMethod, QString &raster,
QgsCoordinateReferenceSystem &proj, QString &pdfMapFile, QString &pdfReportFile, bool &zt, bool &loadInQgis,
QgsCoordinateReferenceSystem &proj, QString &pdfMapFile, QString &pdfReportFile, QString &gcpPoints, bool &zt, bool &loadInQgis,
double &resX, double &resY )
{
if ( cmbTransformType->currentIndex() == -1 )
Expand Down Expand Up @@ -162,6 +164,10 @@ void QgsTransformSettingsDialog::getTransformSettings( QgsGeorefTransform::Trans
resX = dsbHorizRes->value();
resY = dsbVerticalRes->value();
}
if ( saveGcpCheckBox->isChecked() )
{
gcpPoints = mOutputRaster->filePath();
}
}

void QgsTransformSettingsDialog::resetSettings()
Expand All @@ -173,6 +179,7 @@ void QgsTransformSettingsDialog::resetSettings()
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 );
Expand Down Expand Up @@ -227,6 +234,8 @@ void QgsTransformSettingsDialog::accept()
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
2 changes: 1 addition & 1 deletion src/plugins/georeferencer/qgstransformsettingsdialog.h
Expand Up @@ -33,7 +33,7 @@ class QgsTransformSettingsDialog : public QDialog, private Ui::QgsTransformSetti
~QgsTransformSettingsDialog() override;
void getTransformSettings( QgsGeorefTransform::TransformParametrisation &tp,
QgsImageWarper::ResamplingMethod &rm, QString &comprMethod,
QString &raster, QgsCoordinateReferenceSystem &proj, QString &pdfMapFile, QString &pdfReportFile, bool &zt, bool &loadInQgis,
QString &raster, QgsCoordinateReferenceSystem &proj, QString &pdfMapFile, QString &pdfReportFile, QString &gcpPoints, bool &zt, bool &loadInQgis,
double &resX, double &resY );
static void resetSettings();

Expand Down

0 comments on commit 7a9ba25

Please sign in to comment.