Questions tagged [pyqgis]
Python bindings for QGIS.
7,893 questions
2
votes
1
answer
46
views
Automate the turn off QGIS band number in the legend
I’m trying to remove the “Bande 1” label that appears in the raster legend in QGIS 3.40 (Bratislava).
This issue was already mentioned here:
How to turn off QGIS legend band number by default?
The ...
0
votes
0
answers
32
views
Using project based custom functions in QGIS
Now project based custom functions are a thing (QGIS 3.44) I could streamline some of my management of QGIS expressions that get used in various places, so rather than finding all the instances of a ...
1
vote
0
answers
79
views
Override default keyboard shortcut while QGIS plugin window is active
I'm writing a QGIS plugin that uses a QMainWindow and includes several QActions. I'd like to trigger those actions via keyboard shortcuts, but only when the QMainWindow is active.
The shortcuts I'm ...
0
votes
0
answers
35
views
Add custom CRS in QGIS resources DB
I have a custom CRS that I want to use regardless of the profile I am currently working in.
I can add the CRS to resources/srs.db and to resources/qgis.db (and to profile/qgis.db).
A CRS added to ...
1
vote
0
answers
38
views
Correct syntax for VAR_MODEL in sagang:kriging via PyQGIS
I am writing a PyQGIS script to automate interpolation using the sagang:ordinarykriging algorithm (QGIS 3.28.13, SAGA 9.2.0).
While the algorithm runs successfully with the default linear variogram ...
3
votes
1
answer
351
views
Using Python Code as tool in QGIS
I have this little Python code. I want a button or at least a tool in the toolbox which I can click so the console does not have to be open all the time.
I unterstand that saving this code as .py and ...
1
vote
0
answers
54
views
Shapefile DataSourceUri different depending on how the layer is loaded using PyQGIS
I'm using Python in conjunction with a custom form to autofill some fields. I add a vector layer to my project (via 'Add Layer' button) and then use:
print(self.dlg.SelectedLayer.currentLayer()....
4
votes
1
answer
195
views
Removing rows in Layout legend with PyQGIS
I have a script that exports multiple layouts using different layers. Part of it is changing the legend depending on which layer is being printed in the layout. I'm having trouble finding a way to ...
1
vote
1
answer
75
views
Update existing WMS connection in PyQGIS
I update a list of WMS connections automatically with QgsSettings(). When the connection doesn't exist, it is well created with all good attributes. But when the connection already exists, and one ...
3
votes
1
answer
78
views
How do I debug/Run issues with code while attempting to execute TIN interpolation in QGIS 3.36.0
I am completing a project for my master's degree on sedimentary layers across South Wales deposited by a marine transgression event at the end Triassic. For the project, we're attempting to generate ...
0
votes
0
answers
100
views
How do I handle iface properly?
Let's use the following Python code (QGIS 3.36.2):
from qgis.utils import iface
class MyClass:
def __init__(self,iface):
self.iface = iface
#self.test = "This is a test."...
0
votes
2
answers
101
views
Customize QField form for a survey
I'm trying to build a customized QField form for a survey, but I'm having trouble with the customization. I need a button that, when clicked, opens a new empty UI where users can enter information for ...
0
votes
0
answers
59
views
Conditional Inputs within QGIS processing algorithm
I am programming a processing algorithm in PyQGIS that allows users to select certain natural protected areas from state-wide datasets that are stored in an internal data structure. The selection of ...
1
vote
1
answer
107
views
Geometry of feature of temporary scratch layer will dissapear when changing it with PyQGIS
I have a permanent vector layer type linestring with only one feature. In the geometry a
circle with a certain radius is saved. I will change the radius of the circle to a new
value. This is my code (...
1
vote
0
answers
54
views
When exporting GeoTIFF some layers are missing with PyQGIS
I am trying to export a GeoTIFF using a script in the QGIS Python Console, but the exported GeoTIFF is missing most layers. The image being exported is part of a larger canvas, too big to export as a ...
1
vote
1
answer
49
views
Custom tool with default attribute editor form , ok button always disabled
I am making a QGIS tool that will allow a two click point, first click is the geometry, second click gets the angle. I also need to open the default add feature attribute editor form. This is what I ...
0
votes
1
answer
105
views
PYQGIS Processing Script - Add custom action to output layer
I wrote a processing script that creates a layer and adds it to the current project:
class TestAlgorithm(QgsProcessingAlgorithm):
def initAlgorithm(self, config=None):
self.addParameter(...
1
vote
1
answer
83
views
Creating field and updating its value for feature using PyQGIS
First,
I'm trying to create a field for a vector layer. This is the one of the most basic actions.
with edit(noViewLayer):
noViewLayer.addAttribute(QgsField('DN',QMetaType.Type.Int))
QgsProject....
2
votes
1
answer
149
views
Adding layer definition (.qlr file) in QGIS with Python code
I try to run a script that would add a layer definition file (.qlr) to a project in QGIS. The version of QGIS I'm using is very new (3.40.4-Bratislava).
The Python code runs without error messages, ...
-2
votes
2
answers
123
views
Command to restart kernel of QGIS Python Console
In Spyder, I often use the GUI to restart the kernel to ensure that I have a clean slate.
I am using QGIS to access Python (not for GIS) on a system where I have no other way to get Python. I googled ...
1
vote
1
answer
72
views
QGIS hotkeys to maximize the pane that has the focus
I have requested QGIS on a system for the sole purpose of using Python. There is no other means of getting Python on that system. While waiting for the installation, I installed and test drove ...
1
vote
1
answer
86
views
Using QgsMapToolIdentify Within a QGIS Plugin
Within the QGIS python console, I've written a script that allows users to click a location and receive back information. This works well, so I'm now trying to convert it into a plugin. The basics ...
1
vote
0
answers
66
views
Making one sided buffer for not closed polygon rings [closed]
I have a polygon layer representing the outer areas of cities. The polygons do not create a closed "ring" most of the time and consist of multiple fragments. See my example drawing:
How ...
3
votes
0
answers
60
views
Define QGIS expression function with named arguments in Python [duplicate]
I’d like to write a QGIS Expression function in Python that takes a list of strings and joins them with a separator that can be given as an optional named argument sep which also has a default value. ...
1
vote
1
answer
99
views
Creating multiple maps each with different layers in one script with PyQGIS
I want to generate multiple maps with one script. I define a dictionary map_configurations with names for each map and the wanted layers.
I try to loop through the function create_map but my selected ...