mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
Add method to determine whether transform context has a valid transform
for a specific src/dest CRS pair
This commit is contained in:
parent
f55da4affb
commit
d2353e7c01
@ -110,6 +110,14 @@ class QgsCoordinateTransformContext
|
||||
.. seealso:: addSourceDestinationDatumTransform()
|
||||
%End
|
||||
|
||||
bool hasTransform( const QgsCoordinateReferenceSystem &source,
|
||||
const QgsCoordinateReferenceSystem &destination ) const;
|
||||
%Docstring
|
||||
Returns true if the context has a valid datum transform to use
|
||||
when transforming from the specified ``source`` CRS to ``destination`` CRS.
|
||||
:rtype: bool
|
||||
%End
|
||||
|
||||
QPair< int, int > calculateDatumTransforms( const QgsCoordinateReferenceSystem &source,
|
||||
const QgsCoordinateReferenceSystem &destination ) const;
|
||||
%Docstring
|
||||
|
@ -12535,10 +12535,8 @@ bool QgisApp::askForDatumTransform( QgsCoordinateReferenceSystem sourceCrs, QgsC
|
||||
bool ok = false;
|
||||
|
||||
QgsCoordinateTransformContext context = QgsProject::instance()->transformContext();
|
||||
QPair<int, int> dt = context.calculateDatumTransforms( sourceCrs, destinationCrs );
|
||||
if ( dt != qMakePair( -1, -1 ) )
|
||||
if ( context.hasTransform( sourceCrs, destinationCrs ) )
|
||||
{
|
||||
// already defined by user
|
||||
ok = true;
|
||||
}
|
||||
else
|
||||
|
@ -124,6 +124,12 @@ void QgsCoordinateTransformContext::removeSourceDestinationDatumTransform( const
|
||||
d->mSourceDestDatumTransforms.remove( qMakePair( sourceCrs.authid(), destinationCrs.authid() ) );
|
||||
}
|
||||
|
||||
bool QgsCoordinateTransformContext::hasTransform( const QgsCoordinateReferenceSystem &source, const QgsCoordinateReferenceSystem &destination ) const
|
||||
{
|
||||
QPair<int, int> t = calculateDatumTransforms( source, destination );
|
||||
return t.first != -1 || t.second != -1;
|
||||
}
|
||||
|
||||
QPair<int, int> QgsCoordinateTransformContext::calculateDatumTransforms( const QgsCoordinateReferenceSystem &source, const QgsCoordinateReferenceSystem &destination ) const
|
||||
{
|
||||
QString srcKey = source.authid();
|
||||
|
@ -209,6 +209,13 @@ class CORE_EXPORT QgsCoordinateTransformContext
|
||||
void removeSourceDestinationDatumTransform( const QgsCoordinateReferenceSystem &sourceCrs,
|
||||
const QgsCoordinateReferenceSystem &destinationCrs );
|
||||
|
||||
/**
|
||||
* Returns true if the context has a valid datum transform to use
|
||||
* when transforming from the specified \a source CRS to \a destination CRS.
|
||||
*/
|
||||
bool hasTransform( const QgsCoordinateReferenceSystem &source,
|
||||
const QgsCoordinateReferenceSystem &destination ) const;
|
||||
|
||||
/**
|
||||
* Returns the pair of source and destination datum transforms to use
|
||||
* for a transform from the specified \a source CRS to \a destination CRS.
|
||||
|
@ -94,8 +94,15 @@ class TestQgsCoordinateTransformContext(unittest.TestCase):
|
||||
def testSourceDestinationDatumTransforms(self):
|
||||
context = QgsCoordinateTransformContext()
|
||||
self.assertEqual(context.sourceDestinationDatumTransforms(), {})
|
||||
self.assertFalse(context.hasTransform(QgsCoordinateReferenceSystem('EPSG:3111'), QgsCoordinateReferenceSystem('EPSG:4283')))
|
||||
self.assertTrue(context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem('EPSG:3111'),
|
||||
QgsCoordinateReferenceSystem('EPSG:4283'), 1, 2))
|
||||
self.assertTrue(
|
||||
context.hasTransform(QgsCoordinateReferenceSystem('EPSG:3111'), QgsCoordinateReferenceSystem('EPSG:4283')))
|
||||
self.assertFalse(
|
||||
context.hasTransform(QgsCoordinateReferenceSystem('EPSG:3111'), QgsCoordinateReferenceSystem('EPSG:4326')))
|
||||
self.assertFalse(
|
||||
context.hasTransform(QgsCoordinateReferenceSystem('EPSG:3113'), QgsCoordinateReferenceSystem('EPSG:4283')))
|
||||
self.assertEqual(context.sourceDestinationDatumTransforms(), {('EPSG:3111', 'EPSG:4283'): (1, 2)})
|
||||
self.assertTrue(context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem('EPSG:28356'),
|
||||
QgsCoordinateReferenceSystem(4283), 3, 4))
|
||||
|
Loading…
x
Reference in New Issue
Block a user