Add method to retrieve the details of the coordinate operation which is

actually being used by a QgsCoordinateTransform object
This commit is contained in:
Nyall Dawson 2019-12-13 11:29:14 +10:00
parent 82a84ffd0d
commit ef19797997
4 changed files with 60 additions and 0 deletions

View File

@ -293,14 +293,42 @@ Returns ``True`` if the transform short circuits because the source and destinat
Returns a Proj string representing the coordinate operation which will be used to transform
coordinates.
.. note::
The string returned by this method gives the desired coordinate operation string, based on
the state of the QgsCoordinateTransformContext object given in the QgsCoordinateTransform's constructor.
It may be an empty string if no explicit coordinate operation is required. In order to determine the
ACTUAL coordinate operation which is being used by the transform, use the instantiatedCoordinateOperationDetails() call instead.
.. note::
Requires Proj 6.0 or later. Builds based on earlier Proj versions will always return
an empty string, and the deprecated sourceDatumTransformId() or destinationDatumTransformId() methods should be used instead.
.. seealso:: :py:func:`instantiatedCoordinateOperationDetails`
.. seealso:: :py:func:`setCoordinateOperation`
.. versionadded:: 3.8
%End
QgsDatumTransform::TransformDetails instantiatedCoordinateOperationDetails() const;
%Docstring
Returns the transform details representing the coordinate operation which is being used to transform
coordinates.
This may differ from the result returned by coordinateOperation() if the desired coordinate
operation was not successfully instantiated.
.. note::
Requires Proj 6.0 or later. Builds based on earlier Proj versions will always return
an empty result, and the deprecated sourceDatumTransformId() or destinationDatumTransformId() methods should be used instead.
.. seealso:: :py:func:`coordinateOperation`
.. versionadded:: 3.10.2
%End
void setCoordinateOperation( const QString &operation ) const;

View File

@ -799,6 +799,16 @@ QString QgsCoordinateTransform::coordinateOperation() const
return d->mProjCoordinateOperation;
}
QgsDatumTransform::TransformDetails QgsCoordinateTransform::instantiatedCoordinateOperationDetails() const
{
#if PROJ_VERSION_MAJOR>=6
ProjData projData = d->threadLocalProjData();
return QgsDatumTransform::transformDetailsFromPj( projData );
#else
return QgsDatumTransform::TransformDetails();
#endif
}
void QgsCoordinateTransform::setCoordinateOperation( const QString &operation ) const
{
d.detach();

View File

@ -336,14 +336,35 @@ class CORE_EXPORT QgsCoordinateTransform
* Returns a Proj string representing the coordinate operation which will be used to transform
* coordinates.
*
* \note The string returned by this method gives the desired coordinate operation string, based on
* the state of the QgsCoordinateTransformContext object given in the QgsCoordinateTransform's constructor.
* It may be an empty string if no explicit coordinate operation is required. In order to determine the
* ACTUAL coordinate operation which is being used by the transform, use the instantiatedCoordinateOperationDetails() call instead.
*
* \note Requires Proj 6.0 or later. Builds based on earlier Proj versions will always return
* an empty string, and the deprecated sourceDatumTransformId() or destinationDatumTransformId() methods should be used instead.
*
* \see instantiatedCoordinateOperationDetails()
* \see setCoordinateOperation()
* \since QGIS 3.8
*/
QString coordinateOperation() const;
/**
* Returns the transform details representing the coordinate operation which is being used to transform
* coordinates.
*
* This may differ from the result returned by coordinateOperation() if the desired coordinate
* operation was not successfully instantiated.
*
* \note Requires Proj 6.0 or later. Builds based on earlier Proj versions will always return
* an empty result, and the deprecated sourceDatumTransformId() or destinationDatumTransformId() methods should be used instead.
*
* \see coordinateOperation()
* \since QGIS 3.10.2
*/
QgsDatumTransform::TransformDetails instantiatedCoordinateOperationDetails() const;
/**
* Sets a Proj string representing the coordinate \a operation which will be used to transform
* coordinates.

View File

@ -22,6 +22,7 @@
#include <QObject>
#include "qgstest.h"
#include "qgsexception.h"
#include "qgslogger.h"
class TestQgsCoordinateTransform: public QObject
{