Skip to content
Permalink
Browse files

Add public transform method

  • Loading branch information
nyalldawson committed Feb 21, 2021
1 parent 30245ee commit ef78bf9a5143054ffd574c0f3191368eda92eb7f
@@ -65,6 +65,15 @@ Returns the minimum number of Ground Control Points (GCPs) required for paramete
virtual TransformMethod method() const = 0;
%Docstring
Returns the transformation method.
%End

bool transform( double &x /In,Out/, double &y /In,Out/, bool inverseTransform = false ) const;
%Docstring
Transforms the point (``x``, ``y``) from source to destination coordinates.

If ``inverseTransform`` is set to ``True``, the point will be transformed from the destination to the source.

:return: ``True`` if transformation was successful.
%End

static QString methodToString( TransformMethod method );
@@ -26,6 +26,24 @@
#include <limits>


bool QgsGcpTransformerInterface::transform( double &x, double &y, bool inverseTransform ) const
{
GDALTransformerFunc t = GDALTransformer();
// Fail if no transformer function was returned
if ( !t )
return false;

double z = 0.0;
int success = 0;

// Call GDAL transform function
( *t )( GDALTransformerArgs(), inverseTransform ? 1 : 0, 1, &x, &y, &z, &success );
if ( !success )
return false;

return true;
}

QString QgsGcpTransformerInterface::methodToString( QgsGcpTransformerInterface::TransformMethod method )
{
switch ( method )
@@ -84,6 +84,15 @@ class ANALYSIS_EXPORT QgsGcpTransformerInterface SIP_ABSTRACT
*/
virtual TransformMethod method() const = 0;

/**
* Transforms the point (\a x, \a y) from source to destination coordinates.
*
* If \a inverseTransform is set to TRUE, the point will be transformed from the destination to the source.
*
* \returns TRUE if transformation was successful.
*/
bool transform( double &x SIP_INOUT, double &y SIP_INOUT, bool inverseTransform = false ) const;

/**
* Returns a translated string representing the specified transform \a method.
*/
@@ -188,20 +188,11 @@ bool QgsGeorefTransform::getOriginScaleRotation( QgsPointXY &origin, double &sca

bool QgsGeorefTransform::gdal_transform( const QgsPointXY &src, QgsPointXY &dst, int dstToSrc ) const
{
GDALTransformerFunc t = GDALTransformer();
// Fail if no transformer function was returned
if ( !t )
return false;

// Copy the source coordinate for inplace transform
double x = src.x();
double y = src.y();
double z = 0.0;
int success = 0;

// Call GDAL transform function
( *t )( GDALTransformerArgs(), dstToSrc, 1, &x, &y, &z, &success );
if ( !success )
if ( !QgsGcpTransformerInterface::transform( x, y, dstToSrc == 1 ) )
return false;

dst.setX( x );

0 comments on commit ef78bf9

Please sign in to comment.