Skip to content

Commit

Permalink
[OGR provider] Make querySublayers() work with GTFS .zip datasets
Browse files Browse the repository at this point in the history
Fixes #59222

Added tests/testdata/ogr/gtfs_extract.zip comes from GDAL autotest
suite.
  • Loading branch information
rouault committed Oct 25, 2024
1 parent 3094ca5 commit bb65f61
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/core/qgsgdalutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,13 @@ QString QgsGdalUtils::vsiPrefixForPath( const QString &path )
return QStringLiteral( "/vsizip/" );
}
else if ( path.endsWith( QLatin1String( ".zip" ), Qt::CaseInsensitive ) )
{
// GTFS driver directly handles .zip files
const char *const apszAllowedDrivers[] = { "GTFS", nullptr };
if ( GDALIdentifyDriverEx( path.toUtf8().constData(), GDAL_OF_VECTOR, apszAllowedDrivers, nullptr ) )
return QString();
return QStringLiteral( "/vsizip/" );
}
else if ( path.endsWith( QLatin1String( ".tar" ), Qt::CaseInsensitive ) ||
path.endsWith( QLatin1String( ".tar.gz" ), Qt::CaseInsensitive ) ||
path.endsWith( QLatin1String( ".tgz" ), Qt::CaseInsensitive ) )
Expand Down
9 changes: 9 additions & 0 deletions tests/src/python/test_provider_ogr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1626,6 +1626,15 @@ def testDecodeEncodeUriVsizip(self):
encodedUri = QgsProviderRegistry.instance().encodeUri('ogr', parts)
self.assertEqual(encodedUri, uri)

@unittest.skipIf(gdal.GetDriverByName("GTFS") is None, "GTFS driver required")
def testDecodeGTFS(self):
"""Test querySublayers() for GTFS .zip dataset"""

uri = os.path.join(TEST_DATA_DIR, "ogr", "gtfs_extract.zip")
metadata = QgsProviderRegistry.instance().providerMetadata('ogr')
res = metadata.querySublayers(uri)
self.assertEqual(len(res), 9)

def testDecodeEncodeUriCredentialOptions(self):
"""Test decodeUri/encodeUri credential options support"""

Expand Down
Binary file added tests/testdata/ogr/gtfs_extract.zip
Binary file not shown.

0 comments on commit bb65f61

Please sign in to comment.