6

Depending on the table I'm working on, the geometry column does not always have the same name, for example in my data it is called sometimes "the_geom", "geometry", "geom", or even "geometrie". How can I get the name of this attribute in QGIS?

1
  • What does your geometry column contain what you can't access via $geometry?
    – Erik
    Commented Feb 1, 2021 at 11:00

3 Answers 3

8

If you open the "DB Manager", you can navigate to 'virtual layers'. Select your layer and look in the tab 'info'.

enter image description here

Here you get a list of all your fields, the geometry-field included.

3
  • 1
    Thanks, however there is a problem, I tried with a random table. The field name is different in QGIS DB Manager ("geometry") and in PostgreSQL (" geometrie ", the real name). It looks like whatever the name of the geometry column, it is renamed by default "geometry" in DB Manager. Am I right or wrong ?
    – Eliasse
    Commented Feb 1, 2021 at 13:06
  • 1
    @Eliasse You can access your postgres-table via DBmanager. Select the table and look in the info-tab. There the name of your geometrycolumn will be shown as registered in PostGIS
    – PieterB
    Commented Feb 1, 2021 at 18:34
  • Thanks it's working !
    – Eliasse
    Commented Feb 8, 2021 at 9:04
2

A bit late but I Had the same problem when defining a dynamic query for a virtual layer and stumbled over this discussion.

My solution was the understanding, that in QGIS queries/expressions the "geometry"/"$geometry"-pseudo-SQL-keyword allows access to any vector-geometry-source without knowing the name of that column, even if there is no physical column, think about shape-file-Layers.

1

Here is a programmatic solution: With PyQGIS you can get the name of the geometry column via the QgsDataSourceUri of the QgsVectorDataProvider class, e.g. for the active Layer:

iface.activeLayer().dataProvider().uri().geometryColumn()

will give you:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.