Questions tagged [pyqgis-3]

Python bindings for QGIS 3.

A Python interface to QGIS version 3.x.

See also .

773 questions
10
votes
0 answers

PyQGIS script crashes QGIS 3 when removing a custom pluginLayer which has custom legend

I upgrade a 2.18 plugin to 3.4. PluginLayer has been refactored and I could not create a custom legend as simple as previous major version of QGIS 2 : QgsDefaultPluginLayerLegend was removed. Use QgsMapLayer::setLegend() to provide legend nodes for…
Hugo Roussaffa
  • 2,191
  • 15
  • 40
5
votes
2 answers

Using the advanced filter of an attribute table from python

I have created a script which opens the attribute table in QGIS and I would like to use the advanced filter (expression). I want to create the expression from python and then show the result in the attribute table. Code: request =…
p374
  • 223
  • 1
  • 7
3
votes
1 answer

How to use 'memory:name' output as VectorLayer in PyQGIS?

After running processins in a loop, I try to export results on a single shapefile. I've created a vector layer called "regroupee", I merge results with it, and I overwrite "regroupee" with the result. As Kadir Şahbaz said in this post on the…
Zacharie Moulin
  • 339
  • 1
  • 11
3
votes
1 answer

QGIS 3: Changing the datasource of a layer?

Everything seems to go right, but nothing happens: layers = QgsProject.instance().mapLayers().values() for layer in layers: if isinstance(layer, QgsVectorLayer): dp = layer.dataProvider() uri =…
The Rabbit
  • 556
  • 2
  • 15
2
votes
1 answer

PyQGIS: How to set the width of the highlighted feature?

the following code enables to select and highlight the feature with the id 5, further, the highlight is shown in red: from qgis.core import * iface.mapCanvas().setSelectionColor( QColor("red") ) l=iface.activeLayer() l.selectByIds([5]) If all…
i.i.k.
  • 1,427
  • 5
  • 11
2
votes
0 answers

Why segmentation fault when QgsVectorlayer not deleted?

Config: Ubuntu 20.04, QGIS 3.10, Python 3.8.5 My pyqgis scripts are doing the job, but some of them end with a segmentation fault when executing the closing instruction .exitQgis(). The segfault appear each time that I instantiate a QgsVectorLayer…
2
votes
1 answer

Update for Deprecated setLayerInsertionPoint() in QGIS3

The setLayerInsertionPoint() with the QgsProject.instance().layerTreeRoot() object is deprecated. The documentation says: since QGIS 3.10 use setLayerInsertionPoint( const InsertionPoint &insertionPoint ) instead but I can find no example of how…
CNIDog
  • 479
  • 3
  • 13
2
votes
1 answer

PyQGIS & Qt - Revisiting the 'dialog window on top' issue

I want to keep a modeless dialog window on top of the main QGIS window. This issue has been discussed before and two solutions have been offered: self.dlg.setWindowFlags(Qt.WindowStaysOnTopHint). This is unsatisfactory because the dialog window…
TonyMJ
  • 51
  • 3
2
votes
1 answer

In PyQGIS can I get the total length of a road where it's broken up into segments?

In PyQGIS can I get the total length of a road where it's broken up into segments? In SQL I would run SELECT format_number(ROAD_ID,0) as Road_ID, ROAD_NAME as Road, format_number(Sum(st_length(geometry)),2) as Total, Count(*) as…
GeorgeC
  • 8,228
  • 7
  • 52
  • 136
2
votes
1 answer

Feature is snapped?

I try to detect, if a newly created feature is snapped according the snap options: def isSnapped(self,feat): try: snapper = QgsSnappingUtils(self.iface.mapCanvas()) snapper.setMapSettings(self.iface.mapCanvas().mapSettings()) …
The Rabbit
  • 556
  • 2
  • 15
2
votes
1 answer

What is the equivalent of QgsMapToolIdentifyFeature in PyQGIS 3?

I was trying to use the QgsMapToolIdentifyFeature() tool as shown in an answer of StackOverflow, but when executed it gave the error: 'QgisInterface' object has no attribute 'QgsMapToolIdentifyFeature' I am assuming it was deprecated, in that case…
Thriskel
  • 355
  • 1
  • 14
2
votes
1 answer

Problem with the QgsFieldExpressionWidget

I try to customize the QgsFieldExpressionWidget. But if I open the Expression Dialog, the "Fields and Values" are empty. What I am missing? lay= iface.activeLayer() wid = QgsFieldExpressionWidget() wid.setLayer=lay scope=…
The Rabbit
  • 556
  • 2
  • 15
2
votes
0 answers

Upgrading multiprint plugin to QGIS 3

I'm trying to upgrade multiPrint plug in to QGIS3, but I'm newbie on python My upgrade return an error like: AttributeError: 'QgisInterface' object has no attribute 'activeComposers' activeComposer no more exist in QGIS3 The code: def…
felix
  • 21
  • 1
2
votes
0 answers

Is there a way in PyQgis to perform a transaction upon several features at once for undo and redo operations?

I'm developing a standalone application in pyqgis (python 3.6, qgis 3.2) for editing roads and ran into a problem connected to performing transactions. When the user of the app insert, update or delete one feature s/he often wants to perform undo or…
Vadym
  • 811
  • 5
  • 8
2
votes
2 answers

How extract the polyline length in PyQgis 3.0?

I wrote the following code in order to automatically extract the objects' length of a line layer, but I think the « measureLine » expression is not working. This expression works very well PyQgis 2.0. Is there a new expression in PyQgis 3.0 ? def…
ennine
  • 863
  • 2
  • 10
  • 20
1
2