Skip to content
Permalink
Browse files
Support retrieving sublayer path for OGR layers on GDAL 3.4+
  • Loading branch information
nyalldawson committed Aug 25, 2021
1 parent ec80d5a commit abdfcb7b4cce05d88d1d18cebdd356be37fef4da
Showing with 68 additions and 0 deletions.
  1. +49 −0 src/core/providers/ogr/qgsogrprovidermetadata.cpp
  2. +18 −0 tests/src/python/test_provider_ogr.py
  3. BIN tests/testdata/featuredataset.gdb/a00000001.TablesByName.atx
  4. BIN tests/testdata/featuredataset.gdb/a00000001.gdbindexes
  5. BIN tests/testdata/featuredataset.gdb/a00000001.gdbtable
  6. BIN tests/testdata/featuredataset.gdb/a00000001.gdbtablx
  7. BIN tests/testdata/featuredataset.gdb/a00000002.gdbtable
  8. BIN tests/testdata/featuredataset.gdb/a00000002.gdbtablx
  9. BIN tests/testdata/featuredataset.gdb/a00000003.gdbindexes
  10. BIN tests/testdata/featuredataset.gdb/a00000003.gdbtable
  11. BIN tests/testdata/featuredataset.gdb/a00000003.gdbtablx
  12. BIN tests/testdata/featuredataset.gdb/a00000004.CatItemsByPhysicalName.atx
  13. BIN tests/testdata/featuredataset.gdb/a00000004.CatItemsByType.atx
  14. BIN tests/testdata/featuredataset.gdb/a00000004.FDO_UUID.atx
  15. BIN tests/testdata/featuredataset.gdb/a00000004.freelist
  16. BIN tests/testdata/featuredataset.gdb/a00000004.gdbindexes
  17. BIN tests/testdata/featuredataset.gdb/a00000004.gdbtable
  18. BIN tests/testdata/featuredataset.gdb/a00000004.gdbtablx
  19. BIN tests/testdata/featuredataset.gdb/a00000004.spx
  20. BIN tests/testdata/featuredataset.gdb/a00000005.CatItemTypesByName.atx
  21. BIN tests/testdata/featuredataset.gdb/a00000005.CatItemTypesByParentTypeID.atx
  22. BIN tests/testdata/featuredataset.gdb/a00000005.CatItemTypesByUUID.atx
  23. BIN tests/testdata/featuredataset.gdb/a00000005.gdbindexes
  24. BIN tests/testdata/featuredataset.gdb/a00000005.gdbtable
  25. BIN tests/testdata/featuredataset.gdb/a00000005.gdbtablx
  26. BIN tests/testdata/featuredataset.gdb/a00000006.CatRelsByDestinationID.atx
  27. BIN tests/testdata/featuredataset.gdb/a00000006.CatRelsByOriginID.atx
  28. BIN tests/testdata/featuredataset.gdb/a00000006.CatRelsByType.atx
  29. BIN tests/testdata/featuredataset.gdb/a00000006.FDO_UUID.atx
  30. BIN tests/testdata/featuredataset.gdb/a00000006.gdbindexes
  31. BIN tests/testdata/featuredataset.gdb/a00000006.gdbtable
  32. BIN tests/testdata/featuredataset.gdb/a00000006.gdbtablx
  33. BIN tests/testdata/featuredataset.gdb/a00000007.CatRelTypesByBackwardLabel.atx
  34. BIN tests/testdata/featuredataset.gdb/a00000007.CatRelTypesByDestItemTypeID.atx
  35. BIN tests/testdata/featuredataset.gdb/a00000007.CatRelTypesByForwardLabel.atx
  36. BIN tests/testdata/featuredataset.gdb/a00000007.CatRelTypesByName.atx
  37. BIN tests/testdata/featuredataset.gdb/a00000007.CatRelTypesByOriginItemTypeID.atx
  38. BIN tests/testdata/featuredataset.gdb/a00000007.CatRelTypesByUUID.atx
  39. BIN tests/testdata/featuredataset.gdb/a00000007.gdbindexes
  40. BIN tests/testdata/featuredataset.gdb/a00000007.gdbtable
  41. BIN tests/testdata/featuredataset.gdb/a00000007.gdbtablx
  42. BIN tests/testdata/featuredataset.gdb/a00000009.gdbindexes
  43. BIN tests/testdata/featuredataset.gdb/a00000009.gdbtable
  44. BIN tests/testdata/featuredataset.gdb/a00000009.gdbtablx
  45. BIN tests/testdata/featuredataset.gdb/a00000009.spx
  46. BIN tests/testdata/featuredataset.gdb/a0000000a.gdbindexes
  47. BIN tests/testdata/featuredataset.gdb/a0000000a.gdbtable
  48. BIN tests/testdata/featuredataset.gdb/a0000000a.gdbtablx
  49. BIN tests/testdata/featuredataset.gdb/a0000000a.spx
  50. BIN tests/testdata/featuredataset.gdb/a0000000b.gdbindexes
  51. BIN tests/testdata/featuredataset.gdb/a0000000b.gdbtable
  52. BIN tests/testdata/featuredataset.gdb/a0000000b.gdbtablx
  53. BIN tests/testdata/featuredataset.gdb/a0000000b.spx
  54. BIN tests/testdata/featuredataset.gdb/a0000000c.gdbindexes
  55. BIN tests/testdata/featuredataset.gdb/a0000000c.gdbtable
  56. BIN tests/testdata/featuredataset.gdb/a0000000c.gdbtablx
  57. BIN tests/testdata/featuredataset.gdb/a0000000c.spx
  58. BIN tests/testdata/featuredataset.gdb/gdb
  59. +1 −0 tests/testdata/featuredataset.gdb/timestamps
@@ -31,6 +31,7 @@ email : nyall dot dawson at gmail dot com
#include "qgsproviderutils.h"
#include "qgsgdalutils.h"

#include <gdal.h>
#include <QFileInfo>
#include <QFile>
#include <QDir>
@@ -1305,6 +1306,54 @@ QList<QgsProviderSublayerDetails> QgsOgrProviderMetadata::querySublayers( const
} ), res.end() );
}

#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,4,0)

#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
QMutex *mutex = nullptr;
#else
QRecursiveMutex *mutex = nullptr;
#endif
GDALDatasetH hDS = firstLayer->getDatasetHandleAndMutex( mutex );
QMutexLocker locker( mutex );
if ( GDALGroupH rootGroup = GDALDatasetGetRootGroup( hDS ) )
{
std::function< void( GDALGroupH, const QStringList & ) > recurseGroup;
recurseGroup = [&recurseGroup, &res]( GDALGroupH group, const QStringList & currentPath )
{
if ( char **vectorLayerNames = GDALGroupGetVectorLayerNames( group, nullptr ) )
{
const QStringList layers = QgsOgrUtils::cStringListToQStringList( vectorLayerNames );
// attach path to matching layers
for ( const QString &layer : layers )
{
for ( int i = 0; i < res.size(); ++i )
{
if ( res.at( i ).name() == layer )
{
res[i].setPath( currentPath );
}
}
}
}

if ( char **subgroupNames = GDALGroupGetGroupNames( group, nullptr ) )
{
for ( int i = 0; subgroupNames[i]; ++i )
{
if ( GDALGroupH subgroup = GDALGroupOpenGroup( group, subgroupNames[i], nullptr ) )
{
recurseGroup( subgroup, QStringList( currentPath ) << QString::fromUtf8( subgroupNames[i] ) );
GDALGroupRelease( subgroup );
}
}
}
};

recurseGroup( rootGroup, {} );
GDALGroupRelease( rootGroup );
}
#endif

return res;
}

@@ -2045,6 +2045,24 @@ def test_provider_sublayer_details(self):
'driverName': 'SQLite',
'geomColName': ''}])

@unittest.skipIf(int(gdal.VersionInfo('VERSION_NUM')) < GDAL_COMPUTE_VERSION(3, 4, 0), "GDAL 3.4 required")
def test_provider_sublayer_details_hierarchy(self):
"""
Test retrieving sublayer details from a datasource with a hierarchy of layers
"""
metadata = QgsProviderRegistry.instance().providerMetadata('ogr')

res = metadata.querySublayers(os.path.join(TEST_DATA_DIR, 'featuredataset.gdb'))
self.assertEqual(len(res), 4)
self.assertEqual(res[0].name(), 'fd1_lyr1')
self.assertEqual(res[0].path(), ['fd1'])
self.assertEqual(res[1].name(), 'fd1_lyr2')
self.assertEqual(res[1].path(), ['fd1'])
self.assertEqual(res[2].name(), 'standalone')
self.assertEqual(res[2].path(), [])
self.assertEqual(res[3].name(), 'fd2_lyr')
self.assertEqual(res[3].path(), ['fd2'])

def test_provider_sublayer_details_fast_scan(self):
"""
Test retrieving sublayer details from data provider metadata, using fast scan
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

0 comments on commit abdfcb7

Please sign in to comment.