Skip to content
Permalink
Browse files

[ogr] Automatically set QGIS field alias if OGR is able to read one

from the underlying datasource

Supported on GDAL >= 3.2, for the file geodatabase driver only
  • Loading branch information
nyalldawson committed Jul 22, 2020
1 parent dac3f00 commit 05be43da55e35b2fbd6bfad42f640d056e389c6f
Showing with 22 additions and 0 deletions.
  1. +8 −0 src/core/providers/ogr/qgsogrprovider.cpp
  2. +14 −0 tests/src/python/test_provider_ogr.py
  3. BIN tests/testdata/field_alias.gdb/a00000001.TablesByName.atx
  4. BIN tests/testdata/field_alias.gdb/a00000001.gdbindexes
  5. BIN tests/testdata/field_alias.gdb/a00000001.gdbtable
  6. BIN tests/testdata/field_alias.gdb/a00000001.gdbtablx
  7. BIN tests/testdata/field_alias.gdb/a00000002.gdbtable
  8. BIN tests/testdata/field_alias.gdb/a00000002.gdbtablx
  9. BIN tests/testdata/field_alias.gdb/a00000003.gdbindexes
  10. BIN tests/testdata/field_alias.gdb/a00000003.gdbtable
  11. BIN tests/testdata/field_alias.gdb/a00000003.gdbtablx
  12. BIN tests/testdata/field_alias.gdb/a00000004.CatItemsByPhysicalName.atx
  13. BIN tests/testdata/field_alias.gdb/a00000004.CatItemsByType.atx
  14. BIN tests/testdata/field_alias.gdb/a00000004.FDO_UUID.atx
  15. BIN tests/testdata/field_alias.gdb/a00000004.gdbindexes
  16. BIN tests/testdata/field_alias.gdb/a00000004.gdbtable
  17. BIN tests/testdata/field_alias.gdb/a00000004.gdbtablx
  18. BIN tests/testdata/field_alias.gdb/a00000004.spx
  19. BIN tests/testdata/field_alias.gdb/a00000005.CatItemTypesByName.atx
  20. BIN tests/testdata/field_alias.gdb/a00000005.CatItemTypesByParentTypeID.atx
  21. BIN tests/testdata/field_alias.gdb/a00000005.CatItemTypesByUUID.atx
  22. BIN tests/testdata/field_alias.gdb/a00000005.gdbindexes
  23. BIN tests/testdata/field_alias.gdb/a00000005.gdbtable
  24. BIN tests/testdata/field_alias.gdb/a00000005.gdbtablx
  25. BIN tests/testdata/field_alias.gdb/a00000006.CatRelsByDestinationID.atx
  26. BIN tests/testdata/field_alias.gdb/a00000006.CatRelsByOriginID.atx
  27. BIN tests/testdata/field_alias.gdb/a00000006.CatRelsByType.atx
  28. BIN tests/testdata/field_alias.gdb/a00000006.FDO_UUID.atx
  29. BIN tests/testdata/field_alias.gdb/a00000006.gdbindexes
  30. BIN tests/testdata/field_alias.gdb/a00000006.gdbtable
  31. BIN tests/testdata/field_alias.gdb/a00000006.gdbtablx
  32. BIN tests/testdata/field_alias.gdb/a00000007.CatRelTypesByBackwardLabel.atx
  33. BIN tests/testdata/field_alias.gdb/a00000007.CatRelTypesByDestItemTypeID.atx
  34. BIN tests/testdata/field_alias.gdb/a00000007.CatRelTypesByForwardLabel.atx
  35. BIN tests/testdata/field_alias.gdb/a00000007.CatRelTypesByName.atx
  36. BIN tests/testdata/field_alias.gdb/a00000007.CatRelTypesByOriginItemTypeID.atx
  37. BIN tests/testdata/field_alias.gdb/a00000007.CatRelTypesByUUID.atx
  38. BIN tests/testdata/field_alias.gdb/a00000007.gdbindexes
  39. BIN tests/testdata/field_alias.gdb/a00000007.gdbtable
  40. BIN tests/testdata/field_alias.gdb/a00000007.gdbtablx
  41. BIN tests/testdata/field_alias.gdb/a00000009.gdbindexes
  42. BIN tests/testdata/field_alias.gdb/a00000009.gdbtable
  43. BIN tests/testdata/field_alias.gdb/a00000009.gdbtablx
  44. BIN tests/testdata/field_alias.gdb/a00000009.spx
  45. BIN tests/testdata/field_alias.gdb/a0000000a.gdbindexes
  46. BIN tests/testdata/field_alias.gdb/a0000000a.gdbtable
  47. BIN tests/testdata/field_alias.gdb/a0000000a.gdbtablx
  48. BIN tests/testdata/field_alias.gdb/a0000000b.gdbindexes
  49. BIN tests/testdata/field_alias.gdb/a0000000b.gdbtable
  50. BIN tests/testdata/field_alias.gdb/a0000000b.gdbtablx
  51. BIN tests/testdata/field_alias.gdb/a0000000c.band_index.atx
  52. BIN tests/testdata/field_alias.gdb/a0000000c.blk_key_index.atx
  53. BIN tests/testdata/field_alias.gdb/a0000000c.col_index.atx
  54. BIN tests/testdata/field_alias.gdb/a0000000c.gdbindexes
  55. BIN tests/testdata/field_alias.gdb/a0000000c.gdbtable
  56. BIN tests/testdata/field_alias.gdb/a0000000c.gdbtablx
  57. BIN tests/testdata/field_alias.gdb/a0000000c.row_index.atx
  58. BIN tests/testdata/field_alias.gdb/a0000000d.gdbindexes
  59. BIN tests/testdata/field_alias.gdb/a0000000d.gdbtable
  60. BIN tests/testdata/field_alias.gdb/a0000000d.gdbtablx
  61. BIN tests/testdata/field_alias.gdb/gdb
  62. BIN tests/testdata/field_alias.gdb/timestamps
@@ -1246,6 +1246,14 @@ void QgsOgrProvider::loadFields()
width, prec, QString(), varSubType
);

#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,2,0)
const QString alias = textEncoding()->toUnicode( OGR_Fld_GetAlternativeNameRef( fldDef ) );
if ( !alias.isEmpty() )
{
newField.setAlias( alias );
}
#endif

// check if field is nullable
bool nullable = OGR_Fld_IsNullable( fldDef );
if ( !nullable )
@@ -730,6 +730,20 @@ def testMixOfFilterExpressionAndSubsetStringWhenFilterExpressionCompilationFails

self.assertCountEqual([f.attributes() for f in vl.getFeatures(request)], [['rectangle', '1']])

@unittest.skip(int(gdal.VersionInfo('VERSION_NUM')) < GDAL_COMPUTE_VERSION(3, 2, 0))
def testFieldAliases(self):
"""
Test that field aliases are taken from OGR where available (requires GDAL 3.2 or later)
"""
datasource = os.path.join(unitTestDataPath(), 'field_alias.gdb')
vl = QgsVectorLayer(datasource, 'test', 'ogr')
self.assertTrue(vl.isValid())

fields = vl.fields()
self.assertEqual([f.name() for f in fields], ['OBJECTID', 'text', 'short_int', 'long_int', 'float', 'double', 'date', 'blob', 'guid', 'raster', 'SHAPE_Length', 'SHAPE_Area'])
self.assertEqual([f.alias() for f in fields],
['', 'My Text Field', 'My Short Int Field', 'My Long Int Field', 'My Float Field', 'My Double Field', 'My Date Field', 'My Blob Field', 'My GUID field', 'My Raster Field', '', ''])


if __name__ == '__main__':
unittest.main()
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 05be43d

Please sign in to comment.
You can’t perform that action at this time.