Skip to content

Commit

Permalink
Merge pull request #5409 from rouault/fix_gpkg_many_layers
Browse files Browse the repository at this point in the history
[OGR provider] Allow opening (GeoPackage) datasets with many layers
  • Loading branch information
rouault authored Oct 20, 2017
2 parents e59f1d5 + c9b0a2b commit a733ace
Show file tree
Hide file tree
Showing 6 changed files with 1,763 additions and 607 deletions.
2 changes: 1 addition & 1 deletion src/providers/ogr/qgsogrconnpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ inline void qgsConnectionPool_ConnectionCreate( const QString &connInfo, QgsOgrC
{
c = new QgsOgrConn;
QString filePath = connInfo.left( connInfo.indexOf( QLatin1String( "|" ) ) );
c->ds = GDALOpenEx( filePath.toUtf8().constData(), GDAL_OF_VECTOR, nullptr, nullptr, nullptr );
c->ds = QgsOgrProviderUtils::GDALOpenWrapper( filePath.toUtf8().constData(), false, nullptr, nullptr );
c->path = connInfo;
c->valid = true;
}
Expand Down
6 changes: 3 additions & 3 deletions src/providers/ogr/qgsogrdataitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ QgsOgrLayerItem::QgsOgrLayerItem( QgsDataItem *parent,

OGRRegisterAll();
GDALDriverH hDriver;
GDALDatasetH hDataSource = QgsOgrProviderUtils::GDALOpenWrapper( mPath.toUtf8().constData(), true, false, &hDriver );
GDALDatasetH hDataSource = QgsOgrProviderUtils::GDALOpenWrapper( mPath.toUtf8().constData(), true, nullptr, &hDriver );

if ( hDataSource )
{
Expand Down Expand Up @@ -408,7 +408,7 @@ QVector<QgsDataItem *> QgsOgrDataCollectionItem::createChildren()
QVector<QgsDataItem *> children;

GDALDriverH hDriver;
GDALDatasetH hDataSource = QgsOgrProviderUtils::GDALOpenWrapper( mPath.toUtf8().constData(), false, false, &hDriver );
GDALDatasetH hDataSource = QgsOgrProviderUtils::GDALOpenWrapper( mPath.toUtf8().constData(), false, nullptr, &hDriver );
if ( !hDataSource )
return children;
int numLayers = GDALDatasetGetLayerCount( hDataSource );
Expand Down Expand Up @@ -639,7 +639,7 @@ QGISEXTERN QgsDataItem *dataItem( QString path, QgsDataItem *parentItem )
// do not print errors, but write to debug
CPLPushErrorHandler( CPLQuietErrorHandler );
CPLErrorReset();
OGRDataSourceH hDataSource = QgsOgrProviderUtils::GDALOpenWrapper( path.toUtf8().constData(), false, false, &hDriver );
OGRDataSourceH hDataSource = QgsOgrProviderUtils::GDALOpenWrapper( path.toUtf8().constData(), false, nullptr, &hDriver );
CPLPopErrorHandler();

if ( ! hDataSource )
Expand Down
10 changes: 7 additions & 3 deletions src/providers/ogr/qgsogrfeatureiterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ QgsOgrFeatureIterator::QgsOgrFeatureIterator( QgsOgrFeatureSource *source, bool
, mFilterFids( mRequest.filterFids() )
, mFilterFidsIt( mFilterFids.constBegin() )
{
mConn = QgsOgrConnPool::instance()->acquireConnection( mSource->mDataSource );
//QgsDebugMsg( "Feature iterator of " + mSource->mLayerName + ": acquiring connection");
mConn = QgsOgrConnPool::instance()->acquireConnection( QgsOgrProviderUtils::connectionPoolId( mSource->mDataSource ) );
if ( !mConn->ds )
{
return;
Expand Down Expand Up @@ -316,7 +317,10 @@ bool QgsOgrFeatureIterator::close()
}

if ( mConn )
{
//QgsDebugMsg( "Feature iterator of " + mSource->mLayerName + ": releasing connection");
QgsOgrConnPool::instance()->releaseConnection( mConn );
}

mConn = nullptr;
ogrLayer = nullptr;
Expand Down Expand Up @@ -437,12 +441,12 @@ QgsOgrFeatureSource::QgsOgrFeatureSource( const QgsOgrProvider *p )
{
for ( int i = ( p->mFirstFieldIsFid ) ? 1 : 0; i < mFields.size(); i++ )
mFieldsWithoutFid.append( mFields.at( i ) );
QgsOgrConnPool::instance()->ref( mDataSource );
QgsOgrConnPool::instance()->ref( QgsOgrProviderUtils::connectionPoolId( mDataSource ) );
}

QgsOgrFeatureSource::~QgsOgrFeatureSource()
{
QgsOgrConnPool::instance()->unref( mDataSource );
QgsOgrConnPool::instance()->unref( QgsOgrProviderUtils::connectionPoolId( mDataSource ) );
}

QgsFeatureIterator QgsOgrFeatureSource::getFeatures( const QgsFeatureRequest &request )
Expand Down
Loading

0 comments on commit a733ace

Please sign in to comment.