[Browser] Fix invalid detection of OGR VRT by GDAL provider, and fix broken detection of OGR VRT (fixes #16806)

This commit is contained in:
Even Rouault 2017-10-21 00:09:27 +02:00
parent cc96f51e62
commit 49071808ac
3 changed files with 11 additions and 18 deletions

View File

@ -273,13 +273,13 @@ QGISEXTERN QgsDataItem *dataItem( QString path, QgsDataItem *parentItem )
// do not print errors, but write to debug
CPLPushErrorHandler( CPLQuietErrorHandler );
CPLErrorReset();
if ( ! GDALIdentifyDriver( path.toUtf8().constData(), nullptr ) )
GDALDriverH hDriver = GDALIdentifyDriver( path.toUtf8().constData(), nullptr );
CPLPopErrorHandler();
if ( !hDriver || GDALGetDriverShortName( hDriver ) == QLatin1String( "OGR_VRT" ) )
{
QgsDebugMsgLevel( "Skipping VRT file because root is not a GDAL VRT", 2 );
CPLPopErrorHandler();
return nullptr;
}
CPLPopErrorHandler();
}
// add the item
QStringList sublayers;

View File

@ -592,21 +592,14 @@ QGISEXTERN QgsDataItem *dataItem( QString path, QgsDataItem *parentItem )
// if this is a VRT file make sure it is vector VRT to avoid duplicates
if ( suffix == QLatin1String( "vrt" ) )
{
GDALDriverH hDriver = GDALGetDriverByName( "OGR_VRT" );
if ( hDriver )
CPLPushErrorHandler( CPLQuietErrorHandler );
CPLErrorReset();
GDALDriverH hDriver = GDALIdentifyDriver( path.toUtf8().constData(), nullptr );
CPLPopErrorHandler();
if ( !hDriver || GDALGetDriverShortName( hDriver ) == QLatin1String( "VRT" ) )
{
// do not print errors, but write to debug
CPLPushErrorHandler( CPLQuietErrorHandler );
CPLErrorReset();
GDALDatasetH hDataSource = GDALOpenEx(
path.toLocal8Bit().constData(), GDAL_OF_VECTOR, nullptr, nullptr, nullptr );
CPLPopErrorHandler();
if ( ! hDataSource )
{
QgsDebugMsgLevel( "Skipping VRT file because root is not a OGR VRT", 2 );
return nullptr;
}
GDALClose( hDataSource );
QgsDebugMsgLevel( "Skipping VRT file because root is not a OGR VRT", 2 );
return nullptr;
}
}
// Handle collections

View File

@ -2403,7 +2403,7 @@ QString createFilters( const QString &type )
{
sDirectoryDrivers += QObject::tr( "U.S. Census TIGER/Line" ) + ",TIGER;";
}
else if ( driverName.startsWith( QLatin1String( "VRT" ) ) )
else if ( driverName.startsWith( QLatin1String( "OGR_VRT" ) ) )
{
sFileFilters += createFileFilter_( QObject::tr( "VRT - Virtual Datasource" ),
QStringLiteral( "*.vrt *.ovf" ) );