[Qgis-user] Display number of features present in layer's Attribute Table
Ann Tulliani
anntulliani at aol.com
Wed Feb 3 22:38:24 PST 2021
Actually, I was able to make it work. I was including the startup.py file in the wrong directory. The code as mentioned in my last email does work and makes "show feature count" become enabled by default - but with a catch: only for layers added individually. If one adds multiple layers at once, or generates multiple layers at once, then only the first added/generated gets "show feature count" automatically enabled.
Does anyone have any suggestions on how to update that code to make it work for multiple addition of layers?
Ann
-----Original Message-----
From: Ann Tulliani <anntulliani at aol.com>
To: bernd.vogelgesang at gmx.de <bernd.vogelgesang at gmx.de>; qgis-user at lists.osgeo.org <qgis-user at lists.osgeo.org>
Sent: Wed, Feb 3, 2021 11:19 pm
Subject: Re: [Qgis-user] Display number of features present in layer's Attribute Table
Hi Bernd,
Thanks for your reply and sorry for not being clear enough. Of course, I know that I can see the number of features when I open an attribute table or by choosing "show feature count" individually for each layer. What I want to accomplish is something slightly different, but never mind, let's focus on what matters most: the most important is that I want feature count to be automatically enabled for all layers instead of me having to manually do that for dozens and dozens of layers every day.
It seems that there was a feature request put up for this around 8 years ago: https://github.com/qgis/QGIS/issues/16671 and it entered this closed milestone list (but was, afaik, never implemented) almost 3 years ago: https://github.com/qgis/QGIS/milestone/52.
The one proposed workaround I found online is https://gis.stackexchange.com/questions/318190/setting-qgis-to-show-feature-count-always-when-layer-is-loaded. Following it, inside my /home/tulliani/.qgis2/python/startup.py I have:
from qgis.core import QgsMapLayer, QgsProject
def showFeatureCount(layers): layer = layers[0] if layer.type() == QgsMapLayer.VectorLayer: root = QgsProject.instance().layerTreeRoot() myLayerNode = root.findLayer(layer.id()) myLayerNode.setCustomProperty("showFeatureCount", True)
QgsProject.instance().legendLayersAdded.connect(showFeatureCount)
However, that does not see to work: it does not turn "show feature count" automatically on for all added layers.
Would you or anyone else know of an alternative to the above code that would give me the desired behaviour?
Thanks!
Ann Turlliani
-----Original Message-----
From: Bernd Vogelgesang <bernd.vogelgesang at gmx.de>
To: Ann Tulliani <anntulliani at aol.com>; qgis-user at lists.osgeo.org <qgis-user at lists.osgeo.org>
Sent: Wed, Feb 3, 2021 9:45 pm
Subject: Re: [Qgis-user] Display number of features present in layer's Attribute Table
Hi Ann, actually I do not fully understand what you are looking for: When you open an attribute table, the number of features in this table is normally displayed in the the header of this table, and in case features are selected, the number of selected features.
Furthermore, when you right-click on a layer in the layer pannel and choose "show feature count", you can also have the number of features directly shown in the layers panel. In case you have a categorized style, it even shows the counts for those categories.
So I really wonder where and for what did you look, cause for me it seems that the things you ask for, are right in front of your eyes. Cheers, Bernd
Am 04.02.21 um 02:29 schrieb Ann Tulliani:
Dear list,
Is there a way to display - either at the status bar or directly within the Layers panel - the number of features present in the Attributes Table of each layer - or, at least, of the selected layer?
I have been looking for a setting or a plugin that would allow something like that for a while but could not find. Since that functionality would be a huge productivity boost for me and no solution exists already, I would also appreciate any hints that would put me in the right direction of implementing it with Python Scripts.
Best regards,
Ann Tulliani
_______________________________________________
Qgis-user mailing list
Qgis-user at lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20210204/5eca2b9b/attachment.html>
More information about the Qgis-user
mailing list