24
votes
Accepted
Showing the number of currently selected layers in QGIS
You can use this script. It adds a toolbar as seen in the image and shows how many layers are selected.
label = QLabel("Selected Layers Count:")
count = QLabel()
tree_view = iface....
19
votes
Adding layer to group in layers panel using PyQGIS?
Use addMapLayer(layer,False), which will add a layer without showing it
memlay = QgsVectorLayer("Point","myLayer", "memory")
QgsProject.instance().addMapLayer(memlay, False) #False is the key
...
17
votes
Showing the number of currently selected layers in QGIS
To extend the great solution by @Kadir Şahbaz, you could do something like this to get a count per group:
p = QgsProject.instance()
root = p.layerTreeRoot()
view = iface.layerTreeView()
## TOOLBAR
tb ...
12
votes
Accepted
Getting layer within a specific group using PyQGIS
You can define a method for this.
def select_layer(layer_name, group_name):
root = QgsProject.instance().layerTreeRoot()
group = root.findGroup(group_name)
if group is not None:
...
11
votes
Accepted
Removing all layers from group using PyQGIS
dump() method of QgsLayerTreeLayer should be only used for debug purpose. You can do it much nicer this way:
root = QgsProject.instance().layerTreeRoot()
group = root.findGroup(groupName)
if group is ...
11
votes
Accepted
Moving layers in the Layer Order Panel using PyQGIS
You can set layer order in the Layer Order Panel manually using QgsLayerTreeCanvasBridge.setCustomLayerOrder() method, which receives an ordered list of layer IDs.
For instance (assuming you just ...
10
votes
Accepted
Sorting layers by name in one specific group of QGIS layer tree
Nice try, you're almost there!
You just need to use your group instead of the root for the ordering, like this:
from collections import OrderedDict
root = QgsProject.instance().layerTreeRoot()
group =...
10
votes
Accepted
Selecting subgroup in Layers panel using PyQGIS
Setting the Qt.MatchRecursive flag as parameter enables searching the entire hierarchy of the tree view.
And looking at the docs for QAbstractItemModel::match it also seems that you put the Qt....
9
votes
Moving layers in the Layer Order Panel using PyQGIS
For QGIS 3:
I've found maybe a substitute command:
bridge = iface.layerTreeCanvasBridge()
bridge.rootGroup().customLayerOrder()
From https://qgis.org/api/classQgsLayerTree.html#...
9
votes
Accepted
Adding layer to group in layers panel using PyQGIS?
You have to make a clone of the layer and then move it and remove the original layer, try:
groupName="test group"
root = QgsProject.instance().layerTreeRoot()
group = root.addGroup(groupName)
vlayer =...
7
votes
Copy styles from many layers
Here is a small Python script which should do what you want. Don't worry if you're not familiar with the Python console, just open it with ctrl+alt+P or click the button in the plugins toolbar.
Open ...
6
votes
Accepted
Getting name of group that layer is in using PyQGIS?
Instead of using the layers from the QgsMapCanvas you could better iterate the root of the layer tree view (QgsProject.instance().layerTreeRoot().children()) like I show in How to create a text file ...
6
votes
Accepted
Creating event in PyQGIS that notices that group of layers is selected
You can use and modify this script:
from qgis.utils import iface
from qgis.core import QgsLayerTreeNode
view = iface.layerTreeView()
def eventoClickPanelCapas():
selected = view.selectedNodes()
...
6
votes
Accepted
Cloning the map layer using PyQGIS
There are several suggestions regarding your code:
adding the same layer l_out one more time to the project, even with the addToLegend = False does not make much sense to me. In the documentation for ...
5
votes
Accepted
Sorting layers in specific group layer with ArcPy?
Your code is flawed in that it is not referencing layers in the group layer and for some reason your last line is to delete the group layer!
Below is some code that correctly sorts and moves based ...
5
votes
Programmatically select a GROUP node using PyQGIS
The following script selects a node by name.
from qgis.PyQt.QtCore import *
def select(name):
view = iface.layerTreeView()
m = view.model()
listIndexes = m.match(m.index(0, 0), Qt....
5
votes
Grouping layers in Portal for ArcGIS?
Portal does not support grouped layers. You can only have grouped layers if you share as a web service and include the service in your web map.
5
votes
Accepted
.on("load") event for layer groups in Leaflet
A simple way of doing this would be to count load events of individual layers and when count is equal to number of layers, it's done.
Code could then look something like this:
var nLayers = 0;
var ...
5
votes
Layer to KML using ArcGIS Pro doesn't show all points
If you want a tool to operate on every feature in a layer, always unselect selected features before using a tool in ArcGIS. If any feature is selected, the tool uses only selected ones.
5
votes
Accepted
Getting active group with PyQGIS
The layer tree is a QTreeView object where you can access any selected row via its selectionModel.
def activeGroup():
tree_view = iface.layerTreeView()
# retrieve current selected index ...
4
votes
Moving layers in the Layer Order Panel using PyQGIS
Based on this (old) question and some other research, I've successfully added a handler to my QGIS 3.10 project to move all newly added layers to the top of the custom layer order. Here's the relevant ...
4
votes
Dynamically add layer(s) to Layer Group
Here is what I think is the easiest and shortest way to add a Layer to LayerGroup.
First add a "group" to the Map, let's call it markerGroup
markerGroup = new ol.layer.Group({
...
4
votes
Removing all layers from group using PyQGIS
Update for QGIS 3.
Based in @cag answer only need change this line :
QgsMapLayerRegistry.instance().removeMapLayer(id)
to
QgsProject.instance().removeMapLayer(id)
And work like a charm
4
votes
Adding layer to group using PyQGIS
I got tired of forgetting whatever the inputs to the various tree layer methods are so I made a function to handle all that for me. It takes whatever thing (group name, layer id, QgsMapLayer, or ...
4
votes
Grouping layers in Portal for ArcGIS?
I agree with Zara. Unfortunately, Portal doesn't support group layer as of 10.6.
A workaround that I have been using is to group the layers in .mxd and publish them as one service. Then I would add ...
4
votes
Accepted
Creating new layer group in ArcMap?
It should just make a new, empty group layer in your table of contents. You should see 'New Group Layer'.
You can drag other layers into this group layer and collectively toggle them on/off as needed....
4
votes
Accepted
Adding data to subgroup layers with same name in ArcPy?
You can get the group/subgroup path using the longName attribute:
...
targetGroupLayer = arcpy.mapping.ListLayers(mxd, "SubGroupLayer2", df)[0]
print targetGroupLayer.longName
...
So you could ...
4
votes
Accepted
4
votes
Accepted
Enabling the "Render Layers as a Group" option in QGIS through python
You are just missing a few lines.
project = QgsProject.instance()
root = project.layerTreeRoot()
grpSEPASurfaceWater = root.insertGroup(index, 'SEPA Flood Map | Surface Water')
# Set Render Layers as ...
3
votes
Accepted
Apply a definition query to a Layer Group
You cannot list layer groups with listlayers and you do not want to list groups because you cannot apply a definition query to a layer group. You want to list individual layers and then apply the ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
group-layer × 136arcpy × 37
layers × 30
pyqgis × 26
qgis × 24
arcgis-desktop × 18
geoserver × 13
arcgis-pro × 13
table-of-contents × 11
arcmap × 9
wms × 8
qgis-3 × 6
python × 5
legend × 5
arcgis-maps-sdk-javascript × 5
leaflet × 4
openlayers × 4
arcgis-10.1 × 4
arcgis-10.2 × 4
arcgis-10.0 × 3
arcgis-server × 3
modelbuilder × 3
arcgis-10.3 × 3
style × 3
arcgis-10.5 × 3