Skip to content

Commit

Permalink
Add mechanism to disable user-visible warnings on use of fallback tra…
Browse files Browse the repository at this point in the history
…nsforms

for a particular QgsCoordinateTransform object

This can be set for transforms where we definitively know that a "ballpark"
result is acceptable, e.g. when transforming global layer extents to
a localized area-of-use CRS

Refs qgis#33929
  • Loading branch information
nyalldawson committed Feb 17, 2020
1 parent fd534f6 commit 8bb1c47
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
30 changes: 30 additions & 0 deletions python/core/auto_generated/qgscoordinatetransform.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,36 @@ coordinates.
.. seealso:: :py:func:`coordinateOperation`

.. versionadded:: 3.8
%End

void setBallparkTransformsAreAppropriate( bool appropriate );
%Docstring
Sets whether approximate "ballpark" results are appropriate for this coordinate transform.

When a coordinate transform is only being used to generate ballpark results then the
``appropriate`` argument should be set to ``True``. This indicates that its perfectable
acceptable (and even expected!) for the transform to use fallback coordinate operations
in the case that the preferred or user-specified operation fails (such as when coordinates
from outside of a grid shift file's extent are transformed).

When ``appropriate`` is ``True``, then no warnings will be generated when the transform
falls back to a default operation, which may introduce inaccuracies when compared to
the default/specified coordinate operation.

This should be set when a transform expects that coordinates outside of the direct
area of use while be transformed, e.g. when transforming from a global extent to a
CRS with a localized area of use.

If ``appropriate`` is ``False`` (the default behavior), then transforms MAY STILL fallback to default operations
when the preferred or user-specified operation fails, however whenever this occurs
a user-visible warning will be generated.

.. warning::

This setting applies to a single instance of a coordinate transform only,
and is not copied when a coordinate transform object is copied or assigned.

.. versionadded:: 3.12
%End

int sourceDatumTransformId() const /Deprecated/;
Expand Down
11 changes: 10 additions & 1 deletion src/core/qgscoordinatetransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#endif

#include <sqlite3.h>
#include <qlogging.h>
#include <vector>
#include <algorithm>

Expand Down Expand Up @@ -774,11 +775,14 @@ void QgsCoordinateTransform::transformCoords( int numPoints, double *x, double *
memcpy( z, zprev.data(), sizeof( double ) * numPoints );
}

if ( sFallbackOperationOccurredHandler )
if ( !mBallparkTransformsAreAppropriate && sFallbackOperationOccurredHandler )
{
QgsDatumTransform::TransformDetails desired = instantiatedCoordinateOperationDetails();
QgsDatumTransform::TransformDetails used = QgsDatumTransform::transformDetailsFromPj( transform );
sFallbackOperationOccurredHandler( d->mSourceCRS, d->mDestCRS, desired, used );
const QString warning = QStringLiteral( "A fallback coordinate operation was used between %1 and %2" ).arg( d->mSourceCRS.authid(),
d->mDestCRS.authid() );
qWarning( "%s", warning.toLatin1().constData() );
}
}
}
Expand Down Expand Up @@ -897,6 +901,11 @@ void QgsCoordinateTransform::setCoordinateOperation( const QString &operation )
d->mShouldReverseCoordinateOperation = false;
}

void QgsCoordinateTransform::setBallparkTransformsAreAppropriate( bool appropriate )
{
mBallparkTransformsAreAppropriate = appropriate;
}

const char *finder( const char *name )
{
QString proj;
Expand Down
29 changes: 29 additions & 0 deletions src/core/qgscoordinatetransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,34 @@ class CORE_EXPORT QgsCoordinateTransform
*/
void setCoordinateOperation( const QString &operation ) const;

/**
* Sets whether approximate "ballpark" results are appropriate for this coordinate transform.
*
* When a coordinate transform is only being used to generate ballpark results then the
* \a appropriate argument should be set to TRUE. This indicates that its perfectable
* acceptable (and even expected!) for the transform to use fallback coordinate operations
* in the case that the preferred or user-specified operation fails (such as when coordinates
* from outside of a grid shift file's extent are transformed).
*
* When \a appropriate is TRUE, then no warnings will be generated when the transform
* falls back to a default operation, which may introduce inaccuracies when compared to
* the default/specified coordinate operation.
*
* This should be set when a transform expects that coordinates outside of the direct
* area of use while be transformed, e.g. when transforming from a global extent to a
* CRS with a localized area of use.
*
* If \a appropriate is FALSE (the default behavior), then transforms MAY STILL fallback to default operations
* when the preferred or user-specified operation fails, however whenever this occurs
* a user-visible warning will be generated.
*
* \warning This setting applies to a single instance of a coordinate transform only,
* and is not copied when a coordinate transform object is copied or assigned.
*
* \since QGIS 3.12
*/
void setBallparkTransformsAreAppropriate( bool appropriate );

/**
* Returns the ID of the datum transform to use when projecting from the source
* CRS.
Expand Down Expand Up @@ -591,6 +619,7 @@ class CORE_EXPORT QgsCoordinateTransform
#endif

mutable QString mLastError;
bool mBallparkTransformsAreAppropriate = false;

#if PROJ_VERSION_MAJOR>=6
bool setFromCache( const QgsCoordinateReferenceSystem &src,
Expand Down

0 comments on commit 8bb1c47

Please sign in to comment.