Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Hide coordinate operations which utilise a LAS/LOS grid shift file,
which are unsupported by proj 6

E.g. some candidate operations between EPSG:3035 and EPSG:5514

Since these can NEVER (as of now) be instantiated by proj, even if
the grid shift files are present, it's misleading to present them
as options to users.

Refs #30569
  • Loading branch information
nyalldawson committed Nov 25, 2019
1 parent 97fd59a commit 42d6c39
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/core/qgscoordinatetransform_p.cpp
Expand Up @@ -465,15 +465,21 @@ ProjData QgsCoordinateTransformPrivate::threadLocalProjData()
// multiple operations available. Can we use the best one?
QgsDatumTransform::TransformDetails preferred;
bool missingPreferred = false;
bool stillLookingForPreferred = true;
for ( int i = 0; i < count; ++ i )
{
transform.reset( proj_list_get( context, ops, i ) );
const bool isInstantiable = transform && proj_coordoperation_is_instantiable( context, transform.get() );
if ( i == 0 && transform && !isInstantiable )
if ( stillLookingForPreferred && transform && !isInstantiable )
{
// uh oh :( something is missing blocking us from the preferred operation!
missingPreferred = true;
preferred = QgsDatumTransform::transformDetailsFromPj( transform.get() );
QgsDatumTransform::TransformDetails candidate = QgsDatumTransform::transformDetailsFromPj( transform.get() );
if ( !candidate.proj.isEmpty() )
{
preferred = candidate;
missingPreferred = true;
stillLookingForPreferred = false;
}
}
if ( transform && isInstantiable )
{
Expand Down
9 changes: 8 additions & 1 deletion src/core/qgsdatumtransform.cpp
Expand Up @@ -61,7 +61,10 @@ QList<QgsDatumTransform::TransformDetails> QgsDatumTransform::operations( const
if ( !op )
continue;

res.push_back( transformDetailsFromPj( op.get() ) );
QgsDatumTransform::TransformDetails details = transformDetailsFromPj( op.get() );
if ( !details.proj.isEmpty() )
res.push_back( details );

}
proj_list_destroy( ops );
}
Expand Down Expand Up @@ -326,6 +329,10 @@ QgsDatumTransform::TransformDetails QgsDatumTransform::transformDetailsFromPj( P

if ( details.proj.isEmpty() )
details.proj = QString( proj_as_proj_string( pjContext, op, PJ_PROJ_5, nullptr ) );

if ( details.proj.isEmpty() )
return details;

details.name = QString( proj_get_name( op ) );
details.accuracy = proj_coordoperation_get_accuracy( pjContext, op );
details.isAvailable = proj_coordoperation_is_instantiable( pjContext, op );
Expand Down
15 changes: 15 additions & 0 deletions tests/src/python/test_qgsdatumtransforms.py
Expand Up @@ -152,6 +152,21 @@ def testOperations(self):
self.assertTrue(ops[op3_index].grids[0].directDownload)
self.assertTrue(ops[op3_index].grids[0].openLicense)

@unittest.skipIf(QgsProjUtils.projVersionMajor() < 6, 'Not a proj6 build')
def testNoLasLos(self):
"""
Test that operations which rely on an las/los grid shift file (which are unsupported by Proj6) are not returned
"""
ops = QgsDatumTransform.operations(QgsCoordinateReferenceSystem('EPSG:3035'),
QgsCoordinateReferenceSystem('EPSG:5514'))
self.assertEqual(len(ops), 3)
self.assertTrue(ops[0].name)
self.assertTrue(ops[0].proj)
self.assertTrue(ops[1].name)
self.assertTrue(ops[1].proj)
self.assertTrue(ops[2].name)
self.assertTrue(ops[2].proj)


if __name__ == '__main__':
unittest.main()

0 comments on commit 42d6c39

Please sign in to comment.