Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OGR provider] Make querySublayers() work with GTFS .zip datasets #59226

Merged
merged 1 commit into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Loading