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?
3 Answers
If you open the "DB Manager", you can navigate to 'virtual layers'. Select your layer and look in the tab 'info'.
Here you get a list of all your fields, the geometry-field included.
-
1Thanks, 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 ?– EliasseCommented 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– PieterBCommented Feb 1, 2021 at 18:34
-
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.
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:
$geometry
?