Skip to content

Commit

Permalink
Nice and friendly API
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Feb 21, 2021
1 parent fd7149a commit d8a6d36
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
Expand Up @@ -9,6 +9,7 @@




class QgsGcpGeometryTransformer : QgsAbstractGeometryTransformer
{
%Docstring
Expand Down Expand Up @@ -46,6 +47,18 @@ list of source and destination coordinates to transform geometries.
QgsGcpGeometryTransformer cannot be copied
%End

QgsGeometry transform( const QgsGeometry &geometry, bool &ok /Out/, QgsFeedback *feedback = 0 );
%Docstring
Transforms the specified input ``geometry`` using the GCP based transform.

:param geometry: Input geometry to transform
:param feedback: This optional argument can be used to cancel the transformation before it completes.
If this is done, the geometry will be left in a semi-transformed state.

:return: - transformed geometry
- ok: will be set to ``True`` if geometry was successfully transformed, or ``False`` if an error occurred
%End

QgsGcpTransformerInterface *gcpTransformer() const;
%Docstring
Returns the underlying GCP transformer used to transform geometries.
Expand Down
17 changes: 16 additions & 1 deletion src/analysis/georeferencing/qgsgcpgeometrytransformer.cpp
Expand Up @@ -16,7 +16,7 @@
***************************************************************************/

#include "qgsgcpgeometrytransformer.h"

#include "qgsgeometry.h"

QgsGcpGeometryTransformer::QgsGcpGeometryTransformer( QgsGcpTransformerInterface *gcpTransformer )
: mGcpTransformer( gcpTransformer )
Expand All @@ -34,9 +34,24 @@ QgsGcpGeometryTransformer::~QgsGcpGeometryTransformer() = default;

bool QgsGcpGeometryTransformer::transformPoint( double &x, double &y, double &, double & )
{
if ( !mGcpTransformer )
return false;

return mGcpTransformer->transform( x, y );
}

QgsGeometry QgsGcpGeometryTransformer::transform( const QgsGeometry &geometry, bool &ok, QgsFeedback *feedback )
{
if ( geometry.isNull() )
return QgsGeometry();

std::unique_ptr< QgsAbstractGeometry > res( geometry.constGet()->clone() );

ok = res->transform( this, feedback );

return QgsGeometry( std::move( res ) );
}

QgsGcpTransformerInterface *QgsGcpGeometryTransformer::gcpTransformer() const
{
return mGcpTransformer.get();
Expand Down
14 changes: 14 additions & 0 deletions src/analysis/georeferencing/qgsgcpgeometrytransformer.h
Expand Up @@ -23,6 +23,8 @@
#include "qgsgcptransformer.h"
#include <memory>

class QgsGeometry;

/**
* \class QgsGcpGeometryTransformer
* \ingroup analysis
Expand Down Expand Up @@ -58,6 +60,18 @@ class ANALYSIS_EXPORT QgsGcpGeometryTransformer : public QgsAbstractGeometryTran

bool transformPoint( double &x SIP_INOUT, double &y SIP_INOUT, double &z SIP_INOUT, double &m SIP_INOUT ) override;

/**
* Transforms the specified input \a geometry using the GCP based transform.
*
* \param geometry Input geometry to transform
* \param ok will be set to TRUE if geometry was successfully transformed, or FALSE if an error occurred
* \param feedback This optional argument can be used to cancel the transformation before it completes.
* If this is done, the geometry will be left in a semi-transformed state.
*
* \returns transformed geometry
*/
QgsGeometry transform( const QgsGeometry &geometry, bool &ok SIP_OUT, QgsFeedback *feedback = nullptr );

/**
* Returns the underlying GCP transformer used to transform geometries.
*
Expand Down

0 comments on commit d8a6d36

Please sign in to comment.