Skip to content

Commit

Permalink
Create class QgsGcpGeometryTransformer, which allows transformation
Browse files Browse the repository at this point in the history
of geometry objects via a ground control points based transformation
  • Loading branch information
nyalldawson committed Feb 21, 2021
1 parent ce54321 commit fd7149a
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 0 deletions.
1 change: 1 addition & 0 deletions python/analysis/analysis_auto.sip
@@ -1,5 +1,6 @@
// Include auto-generated SIP files
%Include auto_generated/qgsanalysis.sip
%Include auto_generated/georeferencing/qgsgcpgeometrytransformer.sip
%Include auto_generated/georeferencing/qgsgcptransformer.sip
%Include auto_generated/interpolation/qgsgridfilewriter.sip
%Include auto_generated/interpolation/qgsidwinterpolator.sip
Expand Down
@@ -0,0 +1,75 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/analysis/georeferencing/qgsgcpgeometrytransformer.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsGcpGeometryTransformer : QgsAbstractGeometryTransformer
{
%Docstring
A geometry transformer which uses an underlying Ground Control Points (GCP) based transformation to modify geometries.

.. versionadded:: 3.18
%End

%TypeHeaderCode
#include "qgsgcpgeometrytransformer.h"
%End
public:

QgsGcpGeometryTransformer( QgsGcpTransformerInterface *gcpTransformer /Transfer/ );
%Docstring
Constructor for QgsGcpGeometryTransformer, which uses the specified ``gcpTransformer`` to
modify geometries.

Ownership of ``gcpTransformer`` is transferred to the geometry transformer.
%End

QgsGcpGeometryTransformer( QgsGcpTransformerInterface::TransformMethod method, const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates );
%Docstring
Constructor for QgsGcpGeometryTransformer, which uses the specified transform ``method`` and
list of source and destination coordinates to transform geometries.
%End

~QgsGcpGeometryTransformer();



virtual bool transformPoint( double &x /In,Out/, double &y /In,Out/, double &z /In,Out/, double &m /In,Out/ );

%Docstring
QgsGcpGeometryTransformer cannot be copied
%End

QgsGcpTransformerInterface *gcpTransformer() const;
%Docstring
Returns the underlying GCP transformer used to transform geometries.

.. seealso:: :py:func:`setGcpTransformer`
%End

void setGcpTransformer( QgsGcpTransformerInterface *transformer /Transfer/ );
%Docstring
Sets the underlying GCP ``transformer`` used to transform geometries.

Ownership is transferred to this object.

.. seealso:: :py:func:`gcpTransformer`
%End

private:
QgsGcpGeometryTransformer( const QgsGcpGeometryTransformer &other );
};

/************************************************************************
* This file has been generated automatically from *
* *
* src/analysis/georeferencing/qgsgcpgeometrytransformer.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
3 changes: 3 additions & 0 deletions src/analysis/CMakeLists.txt
Expand Up @@ -3,6 +3,8 @@

set(QGIS_ANALYSIS_SRCS
qgsanalysis.cpp

georeferencing/qgsgcpgeometrytransformer.cpp
georeferencing/qgsgcptransformer.cpp
georeferencing/qgsleastsquares.cpp

Expand Down Expand Up @@ -285,6 +287,7 @@ set(QGIS_ANALYSIS_SRCS
set(QGIS_ANALYSIS_HDRS
qgsanalysis.h

georeferencing/qgsgcpgeometrytransformer.h
georeferencing/qgsgcptransformer.h

interpolation/Bezier3D.h
Expand Down
48 changes: 48 additions & 0 deletions src/analysis/georeferencing/qgsgcpgeometrytransformer.cpp
@@ -0,0 +1,48 @@
/***************************************************************************
qgsgcpgeometrytransformer.cpp
----------------------
begin : February 2021
copyright : (C) 2021 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsgcpgeometrytransformer.h"


QgsGcpGeometryTransformer::QgsGcpGeometryTransformer( QgsGcpTransformerInterface *gcpTransformer )
: mGcpTransformer( gcpTransformer )
{

}

QgsGcpGeometryTransformer::QgsGcpGeometryTransformer( QgsGcpTransformerInterface::TransformMethod method, const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates )
: mGcpTransformer( QgsGcpTransformerInterface::createFromParameters( method, sourceCoordinates, destinationCoordinates ) )
{

}

QgsGcpGeometryTransformer::~QgsGcpGeometryTransformer() = default;

bool QgsGcpGeometryTransformer::transformPoint( double &x, double &y, double &, double & )
{
return mGcpTransformer->transform( x, y );
}

QgsGcpTransformerInterface *QgsGcpGeometryTransformer::gcpTransformer() const
{
return mGcpTransformer.get();
}

void QgsGcpGeometryTransformer::setGcpTransformer( QgsGcpTransformerInterface *gcpTransformer )
{
mGcpTransformer.reset( gcpTransformer );
}
86 changes: 86 additions & 0 deletions src/analysis/georeferencing/qgsgcpgeometrytransformer.h
@@ -0,0 +1,86 @@
/***************************************************************************
qgsgcpgeometrytransformer.h
----------------------
begin : February 2021
copyright : (C) 2021 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSGCPGEOMETRYTRANSFORMER_H
#define QGSGCPGEOMETRYTRANSFORMER_H

#include "qgis_analysis.h"
#include "qgsgeometrytransformer.h"
#include "qgsgcptransformer.h"
#include <memory>

/**
* \class QgsGcpGeometryTransformer
* \ingroup analysis
* A geometry transformer which uses an underlying Ground Control Points (GCP) based transformation to modify geometries.
*
* \since QGIS 3.18
*/
class ANALYSIS_EXPORT QgsGcpGeometryTransformer : public QgsAbstractGeometryTransformer
{
public:

/**
* Constructor for QgsGcpGeometryTransformer, which uses the specified \a gcpTransformer to
* modify geometries.
*
* Ownership of \a gcpTransformer is transferred to the geometry transformer.
*/
QgsGcpGeometryTransformer( QgsGcpTransformerInterface *gcpTransformer SIP_TRANSFER );

/**
* Constructor for QgsGcpGeometryTransformer, which uses the specified transform \a method and
* list of source and destination coordinates to transform geometries.
*/
QgsGcpGeometryTransformer( QgsGcpTransformerInterface::TransformMethod method, const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates );

~QgsGcpGeometryTransformer() override;

//! QgsGcpGeometryTransformer cannot be copied
QgsGcpGeometryTransformer( const QgsGcpGeometryTransformer &other ) = delete;

//! QgsGcpGeometryTransformer cannot be copied
QgsGcpGeometryTransformer &operator=( const QgsGcpGeometryTransformer &other ) = delete;

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

/**
* Returns the underlying GCP transformer used to transform geometries.
*
* \see setGcpTransformer()
*/
QgsGcpTransformerInterface *gcpTransformer() const;

/**
* Sets the underlying GCP \a transformer used to transform geometries.
*
* Ownership is transferred to this object.
*
* \see gcpTransformer()
*/
void setGcpTransformer( QgsGcpTransformerInterface *transformer SIP_TRANSFER );

private:
#ifdef SIP_RUN
QgsGcpGeometryTransformer( const QgsGcpGeometryTransformer &other );
#endif

std::unique_ptr< QgsGcpTransformerInterface > mGcpTransformer;

};

#endif // QGSGCPGEOMETRYTRANSFORMER_H

0 comments on commit fd7149a

Please sign in to comment.