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…
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 =…
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…
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 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…
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…
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…
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…
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…
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())
…
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…
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=…
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…
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…
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…