Skip to content

Commit

Permalink
fix QgsOgrProvider::subLayers() to return only one sublayer when a sp…
Browse files Browse the repository at this point in the history
…ecific layer id or name was requested in uri
  • Loading branch information
etiennesky committed May 9, 2014
1 parent 5f72747 commit 2f74037
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/providers/ogr/qgsogrprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ QgsOgrProvider::QgsOgrProvider( QString const & uri )
, extent_( 0 )
, ogrLayer( 0 )
, ogrOrigLayer( 0 )
, mLayerIndex( 0 )
, mIsSubLayer( false )
, mOgrGeometryTypeFilter( wkbUnknown )
, ogrDriver( 0 )
, valid( false )
Expand All @@ -276,7 +278,7 @@ QgsOgrProvider::QgsOgrProvider( QString const & uri )

// make connection to the data source

QgsDebugMsg( "Data source uri is " + uri );
QgsDebugMsg( "Data source uri is [" + uri + "]" );

// try to open for update, but disable error messages to avoid a
// message if the file is read only, because we cope with that
Expand Down Expand Up @@ -315,10 +317,15 @@ QgsOgrProvider::QgsOgrProvider( QString const & uri )
{
mLayerIndex = -1;
}
else
{
mIsSubLayer = true;
}
}
else if ( field == "layername" )
{
mLayerName = value;
mIsSubLayer = true;
}

if ( field == "subset" )
Expand Down Expand Up @@ -397,7 +404,14 @@ QgsOgrProvider::QgsOgrProvider( QString const & uri )
setEncoding( encoding() );

valid = setSubsetString( mSubsetString );
QgsDebugMsg( "Data source is valid" );
if ( valid )
{
QgsDebugMsg( "Data source is valid" );
}
else
{
QgsMessageLog::logMessage( tr( "Data source is invalid (%1)" ).arg( QString::fromUtf8( CPLGetLastErrorMsg() ) ), tr( "OGR" ) );
}
}
else
{
Expand Down Expand Up @@ -594,7 +608,16 @@ QStringList QgsOgrProvider::subLayers() const
QString theLayerName = FROM8( OGR_FD_GetName( fdef ) );
OGRwkbGeometryType layerGeomType = OGR_FD_GetGeomType( fdef );

QgsDebugMsg( QString( "layerGeomType = %1" ).arg( layerGeomType ) );
// ignore this layer if a sublayer was requested and it is not this one
if ( mIsSubLayer &&
(( !mLayerName.isNull() && theLayerName != mLayerName ) ||
( mLayerName.isNull() && mLayerIndex >= 0 && i != ( unsigned int )mLayerIndex ) ) )
{
QgsDebugMsg( QString( "subLayers() ignoring layer #%1 (%2)" ).arg( i ).arg( theLayerName ) );
continue;
}

QgsDebugMsg( QString( "id = %1 name = %2 layerGeomType = %3" ).arg( i ).arg( theLayerName ).arg( layerGeomType ) );

if ( layerGeomType != wkbUnknown )
{
Expand Down
3 changes: 3 additions & 0 deletions src/providers/ogr/qgsogrprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ class QgsOgrProvider : public QgsVectorDataProvider
//! layer index
int mLayerIndex;

//! was a sub layer requested?
bool mIsSubLayer;

/** Optional geometry type for layers with multiple geometries,
* otherwise wkbUnknown. This type is always flatten (2D) and single, it means
* that 2D, 25D, single and multi types are mixed in one sublayer */
Expand Down

0 comments on commit 2f74037

Please sign in to comment.