Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 100254
0 votes
Accepted

Iterate over a layers' features and render the PNG for each feature

Try moving the setExtent() call on the QgsMapSettings object inside your loop and pass the bounding box of the current feature's geometry on each iteration: def finished(): img = render.renderedIm …
Ben W's user avatar
  • 23.1k
5 votes
Accepted

Setting active MapTool to an internal QGIS tool from python

To set the native selection tools found in the Selection Toolbar, you can just programmatically trigger their actions. So, in a plugin (where the iface object is an instance attribute referenced as se …
Ben W's user avatar
  • 23.1k
4 votes
3 answers
2k views

Selecting features using expression with 'maximum' aggregates function in QGIS python console

How do I use the ‘maximum’ aggregates function as an expression with PyQGIS code? …
Ben W's user avatar
  • 23.1k
3 votes
Accepted

Refresh one layer style

Probably the call you are missing is layer.triggerRepaint() Try: style_path = r'Path\to\style_file.qml' lyr = iface.activeLayer() lyr.loadNamedStyle(style_path) lyr.triggerRepaint() # update legen …
Ben W's user avatar
  • 23.1k
3 votes

Export as GeoPackage in PyQGIS

project') else: layer = layers[0]# assign the first item in the list to the layer variable # define the output path fn = 'C:\\Users\\CMCA\\OneDrive - Boskalis\\Documents\\Trial PyQGIS
Ben W's user avatar
  • 23.1k
2 votes
Accepted

QGIS: moving layers inside Layertree into a group crashes QGIS using python

The problem here is that you are modifying the layer tree in the processAlgorithm() method of a processing script, which is not thread safe. This is why QGIS is crashing. This section of the docs give …
Ben W's user avatar
  • 23.1k
8 votes
Accepted

Threading with timer in PyQGIS?

You can use the excellent features QgsTask and QgsTaskManager for this. There are a few options for running tasks in background threads in this way. These are detailed here in the documentation. Bel …
Ben W's user avatar
  • 23.1k
4 votes

Setting QgsExpression for QgsPalLayerSettings in QGIS

Here's a working snippet for creating some label settings and labelling with an expression for PyQGIS 3: # Define layer object layer = QgsProject().instance().mapLayersByName('Name_of_your_layer')[0 …
Ben W's user avatar
  • 23.1k
12 votes
Accepted

Accessing processing.run() output layer in PyQGIS

Regarding the question: "do I need to use is_child_algorithm=True?", you need to use it if the algorithm you are running is being run as a child or sub-algorithm, if you like, inside the processAlgori …
Ben W's user avatar
  • 23.1k
1 vote
Accepted

Getting value of "Editable" checkbox in layer fields widget settings with Python?

Those methods of QgsVectorLayerUtils also take into account the edit state of the layer, as well as the provider capabilities etc. You can see the logic used in the source code for the QgsVectorLayerU …
Ben W's user avatar
  • 23.1k
4 votes

Is there a way to hide range categories using Python code on a vector layer?

Here is a minimal example of how to access layer tree objects such as QgsLayerTreeLayer or QgsLayerTreeGroup. These inherit the method setExpanded() from the QgsLayerTreeNode base class. So you can do …
Ben W's user avatar
  • 23.1k
1 vote

Ignoring feature with featureIdentified with Pyqgis

Make sure you are catching the feature object which is passed by the featureIdentified signal, and using it when you define your self.identify slot function like this: def identify(self, feat): g …
Ben W's user avatar
  • 23.1k
1 vote

Populating attribute field with Python function using PyQGIS

The main problem I see is that the result of your function is two print statements which will just be printed to the console. In order to use those values you need to return them from your function. …
Ben W's user avatar
  • 23.1k
7 votes
Accepted

QGIS Script - Feature Update - Only first feature is updated. The others remain NULL

Without testing your entire script, the problem you describe is because feat = next(polygon.getFeatures()) is only storing the first feature, therefore subsequent references to feat are acting on the …
Ben W's user avatar
  • 23.1k
6 votes
Accepted

Rule based renderer in PyQGIS

This is the second time I've come across this code example in the last week. At least you included a link to the origin source; now I know where it's come from. I think the main problem you have is th …
Ben W's user avatar
  • 23.1k

1
2 3 4 5
22
15 30 50 per page