Skip to content

Commit 51abef4

Browse files
committed
Add geometry column name to sublayers result
1 parent 026083f commit 51abef4

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/providers/ogr/qgsogrprovider.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ email : sherman at mrcc.com
3939
#ifdef HAVE_GUI
4040
#include "qgssourceselectprovider.h"
4141
#include "qgsogrsourceselect.h"
42+
#include "qgsgeopackagesourceselect.h"
4243
#endif
4344

4445
#include "qgis.h"
@@ -697,7 +698,6 @@ static OGRwkbGeometryType ogrWkbGeometryTypeFromName( const QString &typeName )
697698

698699
QStringList QgsOgrProvider::subLayers() const
699700
{
700-
QgsDebugMsg( "Entered." );
701701
if ( !mValid )
702702
{
703703
return QStringList();
@@ -710,6 +710,10 @@ QStringList QgsOgrProvider::subLayers() const
710710
{
711711
OGRLayerH layer = OGR_DS_GetLayer( ogrDataSource, i );
712712
OGRFeatureDefnH fdef = OGR_L_GetLayerDefn( layer );
713+
// Get first column name,
714+
// TODO: add support for multiple
715+
OGRGeomFieldDefnH geomH = OGR_FD_GetGeomFieldDefn( fdef, 0 );
716+
QString geometryColumnName = QString::fromUtf8( OGR_GFld_GetNameRef( geomH ) );
713717
QString layerName = QString::fromUtf8( OGR_FD_GetName( fdef ) );
714718
OGRwkbGeometryType layerGeomType = OGR_FD_GetGeomType( fdef );
715719

@@ -738,7 +742,7 @@ QStringList QgsOgrProvider::subLayers() const
738742

739743
QString geom = ogrWkbGeometryTypeName( layerGeomType );
740744

741-
mSubLayerList << QStringLiteral( "%1:%2:%3:%4" ).arg( i ).arg( layerName, layerFeatureCount == -1 ? tr( "Unknown" ) : QString::number( layerFeatureCount ), geom );
745+
mSubLayerList << QStringLiteral( "%1:%2:%3:%4:%5" ).arg( i ).arg( layerName, layerFeatureCount == -1 ? tr( "Unknown" ) : QString::number( layerFeatureCount ), geom, geometryColumnName );
742746
}
743747
else
744748
{
@@ -792,13 +796,12 @@ QStringList QgsOgrProvider::subLayers() const
792796
{
793797
QString geom = ogrWkbGeometryTypeName( ( bIs25D ) ? wkbSetZ( countIt.key() ) : countIt.key() );
794798

795-
QString sl = QStringLiteral( "%1:%2:%3:%4" ).arg( i ).arg( layerName ).arg( fCount.value( countIt.key() ) ).arg( geom );
799+
QString sl = QStringLiteral( "%1:%2:%3:%4:%5" ).arg( i ).arg( layerName ).arg( fCount.value( countIt.key() ) ).arg( geom, geometryColumnName );
796800
QgsDebugMsg( "sub layer: " + sl );
797801
mSubLayerList << sl;
798802
}
799803
}
800804
}
801-
802805
return mSubLayerList;
803806
}
804807

0 commit comments

Comments
 (0)