Skip to content
Permalink
Browse files

Move transform enum to base class

  • Loading branch information
nyalldawson committed Feb 21, 2021
1 parent 8bf253d commit fe8c768682796385e56d3f23ee2964ff03517cd4
@@ -0,0 +1,12 @@
# The following has been generated automatically from src/analysis/georeferencing/qgsgcptransformer.h
# monkey patching scoped based enum
QgsGcpTransformerInterface.TransformMethod.Linear.__doc__ = "Linear transform"
QgsGcpTransformerInterface.TransformMethod.Helmert.__doc__ = "Helmert transform"
QgsGcpTransformerInterface.TransformMethod.PolynomialOrder1.__doc__ = "Polynomial order 1"
QgsGcpTransformerInterface.TransformMethod.PolynomialOrder2.__doc__ = "Polyonmial order 2"
QgsGcpTransformerInterface.TransformMethod.PolynomialOrder3.__doc__ = "Polynomial order"
QgsGcpTransformerInterface.TransformMethod.ThinPlateSpline.__doc__ = "Thin plate splines"
QgsGcpTransformerInterface.TransformMethod.Projective.__doc__ = "Projective"
QgsGcpTransformerInterface.TransformMethod.InvalidTransform.__doc__ = "Invalid transform"
QgsGcpTransformerInterface.TransformMethod.__doc__ = 'Available transformation methods.\n\n' + '* ``Linear``: ' + QgsGcpTransformerInterface.TransformMethod.Linear.__doc__ + '\n' + '* ``Helmert``: ' + QgsGcpTransformerInterface.TransformMethod.Helmert.__doc__ + '\n' + '* ``PolynomialOrder1``: ' + QgsGcpTransformerInterface.TransformMethod.PolynomialOrder1.__doc__ + '\n' + '* ``PolynomialOrder2``: ' + QgsGcpTransformerInterface.TransformMethod.PolynomialOrder2.__doc__ + '\n' + '* ``PolynomialOrder3``: ' + QgsGcpTransformerInterface.TransformMethod.PolynomialOrder3.__doc__ + '\n' + '* ``ThinPlateSpline``: ' + QgsGcpTransformerInterface.TransformMethod.ThinPlateSpline.__doc__ + '\n' + '* ``Projective``: ' + QgsGcpTransformerInterface.TransformMethod.Projective.__doc__ + '\n' + '* ``InvalidTransform``: ' + QgsGcpTransformerInterface.TransformMethod.InvalidTransform.__doc__
# --
@@ -24,6 +24,18 @@ based on a transformation method and a list of GCPs.
%End
public:

enum class TransformMethod
{
Linear,
Helmert,
PolynomialOrder1,
PolynomialOrder2,
PolynomialOrder3,
ThinPlateSpline,
Projective,
InvalidTransform
};

QgsGcpTransformerInterface();

virtual ~QgsGcpTransformerInterface();
@@ -42,6 +54,11 @@ Fits transformation parameters using the specified Ground Control Points (GCPs)
Returns the minimum number of Ground Control Points (GCPs) required for parameter fitting.
%End

virtual TransformMethod method() const = 0;
%Docstring
Returns the transformation method.
%End


private:
QgsGcpTransformerInterface( const QgsGcpTransformerInterface &other );
@@ -60,6 +60,11 @@ void *QgsLinearGeorefTransform::GDALTransformerArgs() const
return ( void * )&mParameters;
}

QgsGcpTransformerInterface::TransformMethod QgsLinearGeorefTransform::method() const
{
return TransformMethod::Linear;
}

int QgsLinearGeorefTransform::linearTransform( void *pTransformerArg, int bDstToSrc, int nPointCount,
double *x, double *y, double *z, int *panSuccess )
{
@@ -128,6 +133,11 @@ void *QgsHelmertGeorefTransform::GDALTransformerArgs() const
return ( void * )&mHelmertParameters;
}

QgsGcpTransformerInterface::TransformMethod QgsHelmertGeorefTransform::method() const
{
return TransformMethod::Helmert;
}

bool QgsHelmertGeorefTransform::getOriginScaleRotation( QgsPointXY &origin, double &scale, double &rotation ) const
{
origin = mHelmertParameters.origin;
@@ -266,6 +276,23 @@ void *QgsGDALGeorefTransform::GDALTransformerArgs() const
return mGDALTransformerArgs;
}

QgsGcpTransformerInterface::TransformMethod QgsGDALGeorefTransform::method() const
{
if ( mIsTPSTransform )
return TransformMethod::ThinPlateSpline;

switch ( mPolynomialOrder )
{
case 1:
return TransformMethod::PolynomialOrder1;
case 2:
return TransformMethod::PolynomialOrder2;
case 3:
return TransformMethod::PolynomialOrder3;
}
return TransformMethod::InvalidTransform;
}

void QgsGDALGeorefTransform::destroyGdalArgs()
{
if ( mGDALTransformerArgs )
@@ -349,6 +376,11 @@ void *QgsProjectiveGeorefTransform::GDALTransformerArgs() const
return ( void * )&mParameters;
}

QgsGcpTransformerInterface::TransformMethod QgsProjectiveGeorefTransform::method() const
{
return TransformMethod::Projective;
}

int QgsProjectiveGeorefTransform::projectiveTransform( void *pTransformerArg, int bDstToSrc, int nPointCount,
double *x, double *y, double *z, int *panSuccess )
{
@@ -34,6 +34,21 @@ class ANALYSIS_EXPORT QgsGcpTransformerInterface SIP_ABSTRACT
{
public:

/**
* Available transformation methods.
*/
enum class TransformMethod : int
{
Linear, //!< Linear transform
Helmert, //!< Helmert transform
PolynomialOrder1, //!< Polynomial order 1
PolynomialOrder2, //!< Polyonmial order 2
PolynomialOrder3, //!< Polynomial order
ThinPlateSpline, //!< Thin plate splines
Projective, //!< Projective
InvalidTransform = 65535 //!< Invalid transform
};

QgsGcpTransformerInterface() = default;

virtual ~QgsGcpTransformerInterface() = default;
@@ -56,6 +71,11 @@ class ANALYSIS_EXPORT QgsGcpTransformerInterface SIP_ABSTRACT
*/
virtual int minimumGcpCount() const = 0;

/**
* Returns the transformation method.
*/
virtual TransformMethod method() const = 0;

#ifndef SIP_RUN

/**
@@ -96,6 +116,7 @@ class ANALYSIS_EXPORT QgsLinearGeorefTransform : public QgsGcpTransformerInterfa
int minimumGcpCount() const override;
GDALTransformerFunc GDALTransformer() const override;
void *GDALTransformerArgs() const override;
TransformMethod method() const override;

private:
struct LinearParameters
@@ -129,6 +150,7 @@ class ANALYSIS_EXPORT QgsHelmertGeorefTransform : public QgsGcpTransformerInterf
int minimumGcpCount() const override;
GDALTransformerFunc GDALTransformer() const override;
void *GDALTransformerArgs() const override;
TransformMethod method() const override;

private:

@@ -161,14 +183,16 @@ class ANALYSIS_EXPORT QgsGDALGeorefTransform : public QgsGcpTransformerInterface
int minimumGcpCount() const override;
GDALTransformerFunc GDALTransformer() const override;
void *GDALTransformerArgs() const override;
TransformMethod method() const override;

private:
void destroyGdalArgs();

const int mPolynomialOrder;
const int mPolynomialOrder;
const bool mIsTPSTransform;

GDALTransformerFunc mGDALTransformer;
void *mGDALTransformerArgs = nullptr;
GDALTransformerFunc mGDALTransformer;
void *mGDALTransformerArgs = nullptr;

};

@@ -190,6 +214,8 @@ class ANALYSIS_EXPORT QgsProjectiveGeorefTransform : public QgsGcpTransformerInt
int minimumGcpCount() const override;
GDALTransformerFunc GDALTransformer() const override;
void *GDALTransformerArgs() const override;
TransformMethod method() const override;

private:
struct ProjectiveParameters
{
@@ -387,7 +387,7 @@ bool QgsGeoreferencerMainWindow::getTransformSettings()
// logTransformOptions();
// logRequaredGCPs();

if ( QgsGeorefTransform::InvalidTransform != mTransformParam )
if ( QgsGcpTransformerInterface::TransformMethod::InvalidTransform != mTransformParam )
{
mActionLinkGeorefToQgis->setEnabled( true );
mActionLinkQGisToGeoref->setEnabled( true );
@@ -409,10 +409,10 @@ void QgsGeoreferencerMainWindow::generateGDALScript()

switch ( mTransformParam )
{
case QgsGeorefTransform::PolynomialOrder1:
case QgsGeorefTransform::PolynomialOrder2:
case QgsGeorefTransform::PolynomialOrder3:
case QgsGeorefTransform::ThinPlateSpline:
case QgsGcpTransformerInterface::TransformMethod::PolynomialOrder1:
case QgsGcpTransformerInterface::TransformMethod::PolynomialOrder2:
case QgsGcpTransformerInterface::TransformMethod::PolynomialOrder3:
case QgsGcpTransformerInterface::TransformMethod::ThinPlateSpline:
{
// CAVEAT: generateGDALwarpCommand() relies on some member variables being set
// by generateGDALtranslateCommand(), so this method must be called before
@@ -504,7 +504,7 @@ void QgsGeoreferencerMainWindow::linkQGisToGeoref( bool link )
{
if ( link )
{
if ( QgsGeorefTransform::InvalidTransform != mTransformParam )
if ( QgsGcpTransformerInterface::TransformMethod::InvalidTransform != mTransformParam )
{
// Indicate that georeferencer canvas extent has changed
extentsChangedGeorefCanvas();
@@ -520,7 +520,7 @@ void QgsGeoreferencerMainWindow::linkGeorefToQgis( bool link )
{
if ( link )
{
if ( QgsGeorefTransform::InvalidTransform != mTransformParam )
if ( QgsGcpTransformerInterface::TransformMethod::InvalidTransform != mTransformParam )
{
// Indicate that qgis main canvas extent has changed
extentsChangedQGisCanvas();
@@ -1033,7 +1033,7 @@ void QgsGeoreferencerMainWindow::createMapCanvas()

mExtentsChangedRecursionGuard = false;

mGeorefTransform.selectTransformParametrisation( QgsGeorefTransform::Linear );
mGeorefTransform.selectTransformParametrisation( QgsGcpTransformerInterface::TransformMethod::Linear );
mGCPsDirty = true;

// Connect main canvas and georef canvas signals so we are aware if any of the viewports change
@@ -1228,7 +1228,7 @@ void QgsGeoreferencerMainWindow::writeSettings()
s.setValue( QStringLiteral( "/Plugin-GeoReferencer/uistate" ), saveState() );

// warp options
s.setValue( QStringLiteral( "/Plugin-GeoReferencer/transformparam" ), mTransformParam );
s.setValue( QStringLiteral( "/Plugin-GeoReferencer/transformparam" ), static_cast< int >( mTransformParam ) );
s.setValue( QStringLiteral( "/Plugin-GeoReferencer/resamplingmethod" ), mResamplingMethod );
s.setValue( QStringLiteral( "/Plugin-GeoReferencer/compressionmethod" ), mCompressionMethod );
s.setValue( QStringLiteral( "/Plugin-GeoReferencer/usezerofortrans" ), mUseZeroForTrans );
@@ -1363,8 +1363,8 @@ bool QgsGeoreferencerMainWindow::georeference()
if ( !checkReadyGeoref() )
return false;

if ( mModifiedRasterFileName.isEmpty() && ( QgsGeorefTransform::Linear == mGeorefTransform.transformParametrisation() ||
QgsGeorefTransform::Helmert == mGeorefTransform.transformParametrisation() ) )
if ( mModifiedRasterFileName.isEmpty() && ( QgsGcpTransformerInterface::TransformMethod::Linear == mGeorefTransform.transformParametrisation() ||
QgsGcpTransformerInterface::TransformMethod::Helmert == mGeorefTransform.transformParametrisation() ) )
{
QgsPointXY origin;
double pixelXSize, pixelYSize, rotation;
@@ -1480,7 +1480,7 @@ bool QgsGeoreferencerMainWindow::writeWorldFile( const QgsPointXY &origin, doubl

bool QgsGeoreferencerMainWindow::calculateMeanError( double &error ) const
{
if ( mGeorefTransform.transformParametrisation() == QgsGeorefTransform::InvalidTransform )
if ( mGeorefTransform.transformParametrisation() == QgsGcpTransformerInterface::TransformMethod::InvalidTransform )
{
return false;
}
@@ -1961,15 +1961,15 @@ bool QgsGeoreferencerMainWindow::checkReadyGeoref()
return false;
}

if ( QgsGeorefTransform::InvalidTransform == mTransformParam )
if ( QgsGcpTransformerInterface::TransformMethod::InvalidTransform == mTransformParam )
{
QMessageBox::information( this, tr( "Georeferencer" ), tr( "Please set transformation type." ) );
getTransformSettings();
return false;
}

//MH: helmert transformation without warping disabled until qgis is able to read rotated rasters efficiently
if ( mModifiedRasterFileName.isEmpty() && QgsGeorefTransform::Linear != mTransformParam /*&& QgsGeorefTransform::Helmert != mTransformParam*/ )
if ( mModifiedRasterFileName.isEmpty() && QgsGcpTransformerInterface::TransformMethod::Linear != mTransformParam /*&& QgsGeorefTransform::Helmert != mTransformParam*/ )
{
QMessageBox::information( this, tr( "Georeferencer" ), tr( "Please set output raster name." ) );
getTransformSettings();
@@ -2061,23 +2061,23 @@ QgsRectangle QgsGeoreferencerMainWindow::transformViewportBoundingBox( const Qgs
return QgsRectangle( minX, minY, maxX, maxY );
}

QString QgsGeoreferencerMainWindow::convertTransformEnumToString( QgsGeorefTransform::TransformParametrisation transform )
QString QgsGeoreferencerMainWindow::convertTransformEnumToString( QgsGeorefTransform::TransformMethod transform )
{
switch ( transform )
{
case QgsGeorefTransform::Linear:
case QgsGcpTransformerInterface::TransformMethod::Linear:
return tr( "Linear" );
case QgsGeorefTransform::Helmert:
case QgsGcpTransformerInterface::TransformMethod::Helmert:
return tr( "Helmert" );
case QgsGeorefTransform::PolynomialOrder1:
case QgsGcpTransformerInterface::TransformMethod::PolynomialOrder1:
return tr( "Polynomial 1" );
case QgsGeorefTransform::PolynomialOrder2:
case QgsGcpTransformerInterface::TransformMethod::PolynomialOrder2:
return tr( "Polynomial 2" );
case QgsGeorefTransform::PolynomialOrder3:
case QgsGcpTransformerInterface::TransformMethod::PolynomialOrder3:
return tr( "Polynomial 3" );
case QgsGeorefTransform::ThinPlateSpline:
case QgsGcpTransformerInterface::TransformMethod::ThinPlateSpline:
return tr( "Thin plate spline (TPS)" );
case QgsGeorefTransform::Projective:
case QgsGcpTransformerInterface::TransformMethod::Projective:
return tr( "Projective" );
default:
return tr( "Not set" );
@@ -2102,17 +2102,17 @@ QString QgsGeoreferencerMainWindow::convertResamplingEnumToString( QgsImageWarpe
return QString();
}

int QgsGeoreferencerMainWindow::polynomialOrder( QgsGeorefTransform::TransformParametrisation transform )
int QgsGeoreferencerMainWindow::polynomialOrder( QgsGeorefTransform::TransformMethod transform )
{
switch ( transform )
{
case QgsGeorefTransform::PolynomialOrder1:
case QgsGcpTransformerInterface::TransformMethod::PolynomialOrder1:
return 1;
case QgsGeorefTransform::PolynomialOrder2:
case QgsGcpTransformerInterface::TransformMethod::PolynomialOrder2:
return 2;
case QgsGeorefTransform::PolynomialOrder3:
case QgsGcpTransformerInterface::TransformMethod::PolynomialOrder3:
return 3;
case QgsGeorefTransform::ThinPlateSpline:
case QgsGcpTransformerInterface::TransformMethod::ThinPlateSpline:
return -1;

default:
@@ -179,9 +179,9 @@ class QgsGeoreferencerMainWindow : public QMainWindow, private Ui::QgsGeorefPlug
bool checkReadyGeoref();
QgsRectangle transformViewportBoundingBox( const QgsRectangle &canvasExtent, QgsGeorefTransform &t,
bool rasterToWorld = true, uint numSamples = 4 );
QString convertTransformEnumToString( QgsGeorefTransform::TransformParametrisation transform );
QString convertTransformEnumToString( QgsGeorefTransform::TransformMethod transform );
QString convertResamplingEnumToString( QgsImageWarper::ResamplingMethod resampling );
int polynomialOrder( QgsGeorefTransform::TransformParametrisation transform );
int polynomialOrder( QgsGeorefTransform::TransformMethod transform );
QString guessWorldFileName( const QString &rasterFileName );
bool checkFileExisting( const QString &fileName, const QString &title, const QString &question );
bool equalGCPlists( const QgsGCPList &list1, const QgsGCPList &list2 );
@@ -230,7 +230,7 @@ class QgsGeoreferencerMainWindow : public QMainWindow, private Ui::QgsGeorefPlug
QString mSaveGcp;
double mUserResX, mUserResY; // User specified target scale

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

0 comments on commit fe8c768

Please sign in to comment.