Skip to content

Commit

Permalink
[OGR provider] Expose FileGeodatabase layer alias name as dataComment…
Browse files Browse the repository at this point in the history
…() (fixes qgis#55900)
  • Loading branch information
rouault committed Jan 21, 2024
1 parent 121aaa3 commit 661342f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/core/providers/ogr/qgsogrprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3239,6 +3239,12 @@ QgsCoordinateReferenceSystem QgsOgrProvider::crs() const
return srs;
}

QString QgsOgrProvider::dataComment() const
{
// Potentially set on File Geodatabase
return mOgrLayer->GetMetadataItem( QStringLiteral( "ALIAS_NAME" ) );
}

QSet<QVariant> QgsOgrProvider::uniqueValues( int index, int limit ) const
{
QSet<QVariant> uniqueValues;
Expand Down
2 changes: 2 additions & 0 deletions src/core/providers/ogr/qgsogrprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ class QgsOgrProvider final: public QgsVectorDataProvider

QgsCoordinateReferenceSystem crs() const override;

QString dataComment() const override;

/**
* Gets the number of sublayer in the OGR datasource.
* layer_styles is not counted.
Expand Down
21 changes: 21 additions & 0 deletions tests/src/python/test_provider_ogr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3497,6 +3497,27 @@ def testGeoJsonMapType(self):
f = vl.getFeature(1)
self.assertEqual(f.attributes()[0], {'style': {'color': 'yellow'}})

@unittest.skipIf(int(gdal.VersionInfo('VERSION_NUM')) < GDAL_COMPUTE_VERSION(3, 8, 0), "GDAL 3.8 required")
def testDataCommentFileGeodatabase(self):

with tempfile.TemporaryDirectory() as temp_dir:
dest_file_name = os.path.join(temp_dir, 'testDataCommentFileGeodatabase.gdb')
ds = ogr.GetDriverByName("OpenFileGDB").CreateDataSource(dest_file_name)
ds.CreateLayer("test", geom_type=ogr.wkbPoint)
ds = None

vl = QgsVectorLayer(dest_file_name, 'vl')
self.assertEqual(vl.dataComment(), "")

with tempfile.TemporaryDirectory() as temp_dir:
dest_file_name = os.path.join(temp_dir, 'testDataCommentFileGeodatabase.gdb')
ds = ogr.GetDriverByName("OpenFileGDB").CreateDataSource(dest_file_name)
ds.CreateLayer("test", geom_type=ogr.wkbPoint, options=["LAYER_ALIAS=my_alias"])
ds = None

vl = QgsVectorLayer(dest_file_name, 'vl')
self.assertEqual(vl.dataComment(), "my_alias")


if __name__ == '__main__':
unittest.main()

0 comments on commit 661342f

Please sign in to comment.