diff --git a/python/analysis/analysis_auto.sip b/python/analysis/analysis_auto.sip index 39cc162c4ef..452ae21dadb 100644 --- a/python/analysis/analysis_auto.sip +++ b/python/analysis/analysis_auto.sip @@ -1,6 +1,7 @@ // Include auto-generated SIP files %Include auto_generated/qgsanalysis.sip %Include auto_generated/georeferencing/qgsgcpgeometrytransformer.sip +%Include auto_generated/georeferencing/qgsgcppoint.sip %Include auto_generated/georeferencing/qgsgcptransformer.sip %Include auto_generated/interpolation/qgsgridfilewriter.sip %Include auto_generated/interpolation/qgsidwinterpolator.sip diff --git a/python/analysis/auto_additions/qgsgcppoint.py b/python/analysis/auto_additions/qgsgcppoint.py new file mode 100644 index 00000000000..2ee989b7db2 --- /dev/null +++ b/python/analysis/auto_additions/qgsgcppoint.py @@ -0,0 +1,6 @@ +# The following has been generated automatically from src/analysis/georeferencing/qgsgcppoint.h +# monkey patching scoped based enum +QgsGcpPoint.PointType.Source.__doc__ = "Source point" +QgsGcpPoint.PointType.Destination.__doc__ = "Destination point" +QgsGcpPoint.PointType.__doc__ = 'Coordinate point types\n\n' + '* ``Source``: ' + QgsGcpPoint.PointType.Source.__doc__ + '\n' + '* ``Destination``: ' + QgsGcpPoint.PointType.Destination.__doc__ +# -- diff --git a/python/analysis/auto_generated/georeferencing/qgsgcppoint.sip.in b/python/analysis/auto_generated/georeferencing/qgsgcppoint.sip.in new file mode 100644 index 00000000000..d07de56acbe --- /dev/null +++ b/python/analysis/auto_generated/georeferencing/qgsgcppoint.sip.in @@ -0,0 +1,119 @@ +/************************************************************************ + * This file has been generated automatically from * + * * + * src/analysis/georeferencing/qgsgcppoint.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ + + + + +class QgsGcpPoint +{ +%Docstring(signature="appended") +Contains properties of a ground control point (GCP). + +.. versionadded:: 3.26 +%End + +%TypeHeaderCode +#include "qgsgcppoint.h" +%End + public: + + enum class PointType + { + Source, + Destination, + }; + + QgsGcpPoint( const QgsPointXY &sourcePoint, const QgsPointXY &destinationPoint, + const QgsCoordinateReferenceSystem &destinationPointCrs, bool enabled ); +%Docstring +Constructor for QgsGcpPoint. + +:param sourceCoordinates: source coordinates. This may either be in pixels (for completely non-referenced images) OR in the source layer CRS. +:param destinationPoint: destination coordinates +:param destinationPointCrs: CRS of destination point +:param enabled: whether the point is currently enabled +%End + + QgsPointXY sourcePoint() const; +%Docstring +Returns the source coordinates. + +This may either be in pixels (for completely non-referenced images) OR in the source layer CRS. + +.. seealso:: :py:func:`setSourcePoint` +%End + + void setSourcePoint( QgsPointXY point ); +%Docstring +Sets the source coordinates. + +This may either be in pixels (for completely non-referenced images) OR in the source layer CRS. + +.. seealso:: :py:func:`sourcePoint` +%End + + QgsPointXY destinationPoint() const; +%Docstring +Returns the destination coordinates. + +.. seealso:: :py:func:`setDestinationPoint` +%End + + void setDestinationPoint( QgsPointXY point ); +%Docstring +Sets the destination coordinates. + +.. seealso:: :py:func:`destinationPoint` +%End + + QgsCoordinateReferenceSystem destinationPointCrs() const; +%Docstring +Returns the CRS of the destination point. + +.. seealso:: :py:func:`setDestinationCrs` +%End + + void setDestinationPointCrs( const QgsCoordinateReferenceSystem &crs ); +%Docstring +Sets the ``crs`` of the destination point. + +.. seealso:: :py:func:`destinationCrs` +%End + + QgsPointXY transformedDestinationPoint( const QgsCoordinateReferenceSystem &targetCrs, const QgsCoordinateTransformContext &context ) const; +%Docstring +Returns the :py:func:`~QgsGcpPoint.destionationPoint` transformed to the given target CRS. +%End + + bool isEnabled() const; +%Docstring +Returns ``True`` if the point is currently enabled. + +.. seealso:: :py:func:`setEnabled` +%End + + void setEnabled( bool enabled ); +%Docstring +Sets whether the point is currently enabled. + +.. seealso:: :py:func:`enabled` +%End + + bool operator==( const QgsGcpPoint &other ) const; + + bool operator!=( const QgsGcpPoint &other ) const; + +}; + +/************************************************************************ + * This file has been generated automatically from * + * * + * src/analysis/georeferencing/qgsgcppoint.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ diff --git a/src/analysis/CMakeLists.txt b/src/analysis/CMakeLists.txt index f2a700670ec..e92ce910d22 100644 --- a/src/analysis/CMakeLists.txt +++ b/src/analysis/CMakeLists.txt @@ -13,6 +13,7 @@ set(QGIS_ANALYSIS_SRCS ${BISON_QgsRasterCalcParser_OUTPUTS} georeferencing/qgsgcpgeometrytransformer.cpp + georeferencing/qgsgcppoint.cpp georeferencing/qgsgcptransformer.cpp georeferencing/qgsleastsquares.cpp @@ -305,6 +306,7 @@ set(QGIS_ANALYSIS_HDRS qgsanalysis.h georeferencing/qgsgcpgeometrytransformer.h + georeferencing/qgsgcppoint.h georeferencing/qgsgcptransformer.h interpolation/Bezier3D.h diff --git a/src/analysis/georeferencing/qgsgcppoint.cpp b/src/analysis/georeferencing/qgsgcppoint.cpp new file mode 100644 index 00000000000..fbfcf8f4e93 --- /dev/null +++ b/src/analysis/georeferencing/qgsgcppoint.cpp @@ -0,0 +1,54 @@ +/*************************************************************************** + qgsgcppoint.h + -------------------------------------- + Date : February 2022 + Copyright : (C) 2022 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 + +#include "qgscoordinatereferencesystem.h" +#include "qgsgcppoint.h" +#include "qgscoordinatetransform.h" +#include "qgsexception.h" +#include "qgslogger.h" + +QgsGcpPoint::QgsGcpPoint( const QgsPointXY &sourcePoint, const QgsPointXY &destinationPoint, const QgsCoordinateReferenceSystem &destinationPointCrs, bool enabled ) + : mSourcePoint( sourcePoint ) + , mDestinationPoint( destinationPoint ) + , mDestinationCrs( destinationPointCrs ) + , mEnabled( enabled ) +{ + +} + +QgsCoordinateReferenceSystem QgsGcpPoint::destinationPointCrs() const +{ + return mDestinationCrs; +} + +void QgsGcpPoint::setDestinationPointCrs( const QgsCoordinateReferenceSystem &crs ) +{ + mDestinationCrs = crs; +} + +QgsPointXY QgsGcpPoint::transformedDestinationPoint( const QgsCoordinateReferenceSystem &targetCrs, const QgsCoordinateTransformContext &context ) const +{ + const QgsCoordinateTransform transform( mDestinationCrs, targetCrs, context ); + try + { + return transform.transform( mDestinationPoint ); + } + catch ( QgsCsException & ) + { + QgsDebugMsg( QStringLiteral( "Error transforming destination point" ) ); + return mDestinationPoint; + } +} diff --git a/src/analysis/georeferencing/qgsgcppoint.h b/src/analysis/georeferencing/qgsgcppoint.h new file mode 100644 index 00000000000..fb70b97fbcd --- /dev/null +++ b/src/analysis/georeferencing/qgsgcppoint.h @@ -0,0 +1,140 @@ +/*************************************************************************** + qgsgcppoint.h + -------------------------------------- + Date : February 2022 + Copyright : (C) 2022 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 QGSGCPPOINT_H +#define QGSGCPPOINT_H + +#include "qgis_analysis.h" +#include "qgscoordinatereferencesystem.h" + +class QgsCoordinateTransformContext; + +/** + * \ingroup analysis + * \brief Contains properties of a ground control point (GCP). + * + * \since QGIS 3.26 +*/ +class ANALYSIS_EXPORT QgsGcpPoint +{ + public: + + //! Coordinate point types + enum class PointType + { + Source, //!< Source point + Destination, //!< Destination point + }; + + /** + * Constructor for QgsGcpPoint. + * + * \param sourceCoordinates source coordinates. This may either be in pixels (for completely non-referenced images) OR in the source layer CRS. + * \param destinationPoint destination coordinates + * \param destinationPointCrs CRS of destination point + * \param enabled whether the point is currently enabled + */ + QgsGcpPoint( const QgsPointXY &sourcePoint, const QgsPointXY &destinationPoint, + const QgsCoordinateReferenceSystem &destinationPointCrs, bool enabled ); + + /** + * Returns the source coordinates. + * + * This may either be in pixels (for completely non-referenced images) OR in the source layer CRS. + * + * \see setSourcePoint() + */ + QgsPointXY sourcePoint() const { return mSourcePoint; } + + /** + * Sets the source coordinates. + * + * This may either be in pixels (for completely non-referenced images) OR in the source layer CRS. + * + * \see sourcePoint() + */ + void setSourcePoint( QgsPointXY point ) { mSourcePoint = point; } + + /** + * Returns the destination coordinates. + * + * \see setDestinationPoint() + */ + QgsPointXY destinationPoint() const { return mDestinationPoint; } + + /** + * Sets the destination coordinates. + * + * \see destinationPoint() + */ + void setDestinationPoint( QgsPointXY point ) { mDestinationPoint = point; } + + /** + * Returns the CRS of the destination point. + * + * \see setDestinationCrs() + */ + QgsCoordinateReferenceSystem destinationPointCrs() const; + + /** + * Sets the \a crs of the destination point. + * + * \see destinationCrs() + */ + void setDestinationPointCrs( const QgsCoordinateReferenceSystem &crs ); + + /** + * Returns the destionationPoint() transformed to the given target CRS. + */ + QgsPointXY transformedDestinationPoint( const QgsCoordinateReferenceSystem &targetCrs, const QgsCoordinateTransformContext &context ) const; + + /** + * Returns TRUE if the point is currently enabled. + * + * \see setEnabled() + */ + bool isEnabled() const { return mEnabled; } + + /** + * Sets whether the point is currently enabled. + * + * \see enabled() + */ + void setEnabled( bool enabled ) { mEnabled = enabled; } + + // TODO c++20 - replace with = default + bool operator==( const QgsGcpPoint &other ) const + { + return mEnabled == other.mEnabled + && mSourcePoint == other.mSourcePoint + && mDestinationPoint == other.mDestinationPoint + && mDestinationCrs == other.mDestinationCrs; + } + + bool operator!=( const QgsGcpPoint &other ) const + { + return !( *this == other ); + } + + private: + + QgsPointXY mSourcePoint; + QgsPointXY mDestinationPoint; + QgsCoordinateReferenceSystem mDestinationCrs; + bool mEnabled = true; + +}; + +#endif //QGSGCPPOINT_H diff --git a/src/app/georeferencer/qgsgeorefdatapoint.cpp b/src/app/georeferencer/qgsgeorefdatapoint.cpp index 727a23f940d..fa5709e3cb2 100644 --- a/src/app/georeferencer/qgsgeorefdatapoint.cpp +++ b/src/app/georeferencer/qgsgeorefdatapoint.cpp @@ -17,52 +17,8 @@ #include "qgsmapcanvas.h" #include "qgsgcpcanvasitem.h" #include "qgscoordinatereferencesystem.h" - - #include "qgsgeorefdatapoint.h" -// -// QgsGcpPoint -// - -QgsGcpPoint::QgsGcpPoint( const QgsPointXY &sourcePoint, const QgsPointXY &destinationPoint, const QgsCoordinateReferenceSystem &destinationPointCrs, bool enabled ) - : mSourcePoint( sourcePoint ) - , mDestinationPoint( destinationPoint ) - , mDestinationCrs( destinationPointCrs ) - , mEnabled( enabled ) -{ - -} - -QgsCoordinateReferenceSystem QgsGcpPoint::destinationPointCrs() const -{ - return mDestinationCrs; -} - -void QgsGcpPoint::setDestinationPointCrs( const QgsCoordinateReferenceSystem &crs ) -{ - mDestinationCrs = crs; -} - -QgsPointXY QgsGcpPoint::transformedDestinationPoint( const QgsCoordinateReferenceSystem &targetCrs, const QgsCoordinateTransformContext &context ) const -{ - const QgsCoordinateTransform transform( mDestinationCrs, targetCrs, context ); - try - { - return transform.transform( mDestinationPoint ); - } - catch ( QgsCsException & ) - { - QgsDebugMsg( QStringLiteral( "Error transforming destination point" ) ); - return mDestinationPoint; - } -} - - -// -// QgsGeorefDataPoint -// - QgsGeorefDataPoint::QgsGeorefDataPoint( QgsMapCanvas *srcCanvas, QgsMapCanvas *dstCanvas, const QgsPointXY &sourceCoordinates, const QgsPointXY &destinationPoint, const QgsCoordinateReferenceSystem &destinationPointCrs, bool enabled ) diff --git a/src/app/georeferencer/qgsgeorefdatapoint.h b/src/app/georeferencer/qgsgeorefdatapoint.h index b001f857296..2fe183ab590 100644 --- a/src/app/georeferencer/qgsgeorefdatapoint.h +++ b/src/app/georeferencer/qgsgeorefdatapoint.h @@ -19,124 +19,11 @@ #include "qgis_app.h" #include "qgsmapcanvasitem.h" #include "qgscoordinatereferencesystem.h" +#include "qgsgcppoint.h" class QgsGCPCanvasItem; class QgsCoordinateTransformContext; -/** - * Contains properties of a ground control point (GCP). - */ -class APP_EXPORT QgsGcpPoint -{ - public: - - //! Coordinate point types - enum class PointType - { - Source, //!< Source point - Destination, //!< Destination point - }; - - /** - * Constructor for QgsGcpPoint. - * - * \param sourceCoordinates source coordinates. This may either be in pixels (for completely non-referenced images) OR in the source layer CRS. - * \param destinationPoint destination coordinates - * \param destinationPointCrs CRS of destination point - * \param enabled whether the point is currently enabled - */ - QgsGcpPoint( const QgsPointXY &sourcePoint, const QgsPointXY &destinationPoint, - const QgsCoordinateReferenceSystem &destinationPointCrs, bool enabled ); - - /** - * Returns the source coordinates. - * - * This may either be in pixels (for completely non-referenced images) OR in the source layer CRS. - * - * \see setSourcePoint() - */ - QgsPointXY sourcePoint() const { return mSourcePoint; } - - /** - * Sets the source coordinates. - * - * This may either be in pixels (for completely non-referenced images) OR in the source layer CRS. - * - * \see sourcePoint() - */ - void setSourcePoint( QgsPointXY point ) { mSourcePoint = point; } - - /** - * Returns the destination coordinates. - * - * \see setDestinationPoint() - */ - QgsPointXY destinationPoint() const { return mDestinationPoint; } - - /** - * Sets the destination coordinates. - * - * \see destinationPoint() - */ - void setDestinationPoint( QgsPointXY point ) { mDestinationPoint = point; } - - /** - * Returns the CRS of the destination point. - * - * \see setDestinationCrs() - */ - QgsCoordinateReferenceSystem destinationPointCrs() const; - - /** - * Sets the \a crs of the destination point. - * - * \see destinationCrs() - */ - void setDestinationPointCrs( const QgsCoordinateReferenceSystem &crs ); - - /** - * Returns the destionationPoint() transformed to the given target CRS. - */ - QgsPointXY transformedDestinationPoint( const QgsCoordinateReferenceSystem &targetCrs, const QgsCoordinateTransformContext &context ) const; - - /** - * Returns TRUE if the point is currently enabled. - * - * \see setEnabled() - */ - bool isEnabled() const { return mEnabled; } - - /** - * Sets whether the point is currently enabled. - * - * \see enabled() - */ - void setEnabled( bool enabled ) { mEnabled = enabled; } - - // TODO c++20 - replace with = default - bool operator==( const QgsGcpPoint &other ) const - { - return mEnabled == other.mEnabled - && mSourcePoint == other.mSourcePoint - && mDestinationPoint == other.mDestinationPoint - && mDestinationCrs == other.mDestinationCrs; - } - - bool operator!=( const QgsGcpPoint &other ) const - { - return !( *this == other ); - } - - private: - - QgsPointXY mSourcePoint; - QgsPointXY mDestinationPoint; - QgsCoordinateReferenceSystem mDestinationCrs; - bool mEnabled = true; - -}; - - /** * Container for a GCP point and the graphical objects which represent it on the map canvas. */