Questions tagged [pyqgis-3]
Python bindings for QGIS 3.
768
questions
0
votes
0
answers
28
views
QGIS - Electrical Power Grid: getting the value from a previous line
I am working with two layers. One of them is a set of lines supposed to represent the electrical grid of a city. And the other one is a set of points representing the utility poles of the grid.
The ...
0
votes
1
answer
26
views
What was the PyQGIS class QgsCompostition changed to?
I am wondering what the old classes QgsComposition and QgsComposerItem where changed to in the current release?
0
votes
1
answer
45
views
Using PyQGIS to make a custom measure tool that persists
Similar to how Google Earth works where you can draw out a measure line, then click the draw line or draw poly button to draw a feature and the measure line stays on the map. How could I modify the ...
3
votes
2
answers
179
views
Easy examples for multiprocessing in PyQGIS
I've gone through a large number of forum threads and cannot make sense of how possible it is to easily run two tools at the same time in PyQGIS.
Basically what I'm wanting to do is:
def function1():
...
0
votes
0
answers
30
views
Replace Attributes Form and Automate Fields
I used QT Creator to create an .ui for my form.
I want to change the form attribute and automate some fields. Imagine I have an layer with field name, I want that field when the form appears, to ...
2
votes
1
answer
78
views
Changeing attributevalue using PyQGIS
Is there a faster way to make the selection of the "bnt" field and the value change in the "BUERO" field?
import time
start= time.time()
fldname = "BUERO" #Feldname, das ...
0
votes
1
answer
70
views
How to transfer the data from attribute table to Excel sheet in PyQGIS [closed]
I want to automatically write the data from the attribute table of the layer I have created to an Excel sheet. Is there a script for that?
0
votes
0
answers
85
views
PyQGIS: How to save an in-memory file to shapefile
I created memory files by chaining multiple processes (dissolve, multiparttosingleparts, pointsalonglines) and in the last step I add a new field to the memory layer.
My code looks this:
from qgis....
0
votes
1
answer
36
views
Chain two processes with in-memory layer in QGIS
I have two processes which should run after each other, first dissolve, then multipart-singlepart. Until now I have worked with file-based layers but I would like to have the output from the dissolve ...
1
vote
0
answers
57
views
Legend is cropped after exporting Print Layout to .png using PyQGIS
Some legends looks like that, after rendering a few layouts in a row.
I tried all these methods in the code, but in cases when previous Print Layout has smaller Legend's size - it's just doesn't work ...
5
votes
1
answer
57
views
Export reports in QGIS using PyQGIS
I've created a report in QGIS 3.28.
Now I want to export this report to PDF using PyQGIS, but I can't find a method for it.
layout_manager = QgsProject.instance().layoutManager()
report = ...
2
votes
1
answer
67
views
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&...
0
votes
0
answers
21
views
Automatically pin labels with PyQGIS?
How to automatically pin labels on canvas? I see two possible ways.
The first way: I'm trying to do it with the pinning tool . I turn on this tool. But then I need to automatically select all the ...
1
vote
1
answer
62
views
QGIS plugin, display image responses with known bounding box
I am building a QGIS plugin. The users will fill some parameters from UI and the response image will be displayed on QGIS map.
There is a back-end service that serves images (PNG, WebP, JPEG) of given ...
0
votes
0
answers
38
views
Using 2D float arrays in attribute table fields in QGIS
I am currently using QGIS 3.28.0-Firenze for developing custom plugins, using PyQGIS.
I am interested in assigning a table of values to each of the point features of a Vector Point Layer. So then, ...
0
votes
0
answers
41
views
QGIS Crashed while working in background thread
I implemented threading and all the GUI stuff in the main thread, I'm performing snapping and validation stuff in the background thread.
It works well but sometimes suddenly it stops and the progress ...
1
vote
0
answers
81
views
How to display a label from another layer (without creating a new layer)?
Layer A contains terrains knowing that the geometries have been merged when they are contiguous 'and' the owners are identical.
The layer includes a variable indicating the number of slots.
Layer B ...
2
votes
0
answers
30
views
How to capture featureDeleted() info in PyQGIS3
I have a system of scratch layers generated from table data in QGIS. Users may interact with the attribute tables directly (not good practice, but I did not design the system) or through a PyQt5 UI. ...
2
votes
1
answer
152
views
Enabling the "Render Layers as a Group" option in QGIS through python
I have written a simple python function that loads several existing shapefile layers into a new group in QGIS 3.28. I would like to extend this function to also automatically enable the "Render ...
-1
votes
1
answer
80
views
How to get the active layer and use it as input layer for dissolve in PyQis [duplicate]
This is my Script:
from qgis import processing
inlayDir = r'C:\Users\CMCA\OneDrive - Boskalis\Documents\Trial PyQGIS\cdc_1stfill.shp'
processing.runAndLoadResults("native:dissolve",
...
9
votes
2
answers
286
views
PyQGIS to set masked symbol layer and mask source
I have a PyQGIS script to open a GPKG-layer (contour lines) along with a qml-file in QGIS.
In the style file I have enabled label masking and using the contour lines as mask layer:
Making my labels ...
2
votes
2
answers
4k
views
ModuleNotFoundError: No module named 'xlsxwriter'
I created a plugin that export some data from the layer to some excell.
The problem that I'm facing, as the title says, is that Module xlsxwriter is not found.
To save some answers, yes I installed ...
0
votes
1
answer
86
views
Set/Get Value of QGIS-Server Variables in ProjectSettings
I want to automatically read and write settings of my QGIS-project with Pyqgis. Especially i want to do this for the QGIS Server Service Properties (Top of QGIS-Server Tab).
I found this Link but i ...
1
vote
0
answers
84
views
Updating length in an existing field using PyQGIS - changes not persisting
I have a group of layers and I want to edit the field in some of them. More specifically, I want to change the length in those fields named ATTRIBUTE1. I'm using this code
from qgis import core
from ...
2
votes
1
answer
102
views
ImportError when importing QgsCoordinateReferenceSystem
I'm trying to import QgsCoordinateReferenceSystem for a QGIS plugin but it keeps complaining about either trying the Core, Gui, or Widget modules.
The import line reads:
from PyQt5.QtCore import Qt, ...
1
vote
1
answer
83
views
Save features to KML in particular order in PyQGIS
I have a layer with an attribute called 'label' which has numbers as text ('1', '2', etc...) I want a KML saved and have the features saved by order of int('label'). Is it possible?
Looks like from ...
1
vote
1
answer
86
views
Setting QAction with no associated buttons in PyQGIS
I have a function that sets up some QActions and sets some keyboard shortcuts:
def set_num_edit_shortcuts(self):
self.right_next_action = QAction(parent=iface.mainWindow())
self....
0
votes
0
answers
43
views
Unload Qgis core plugins
How can I unload a core plugin from Qgis using python script (for example GDAL georeferencer)?
I tried :
for p in available_plugins:
print(p)
but it lists only python plugins
0
votes
0
answers
107
views
How to refresh label layout items after font change in pyQGIS
I have pyQGIS (3.x) to change the font face of all labels in a QGIS Print Layout. It works however, if the label is bold or italic the label appears as a regular font until the project is closed and ...
3
votes
1
answer
120
views
Create virtual layer without geometry from code
I'm trying to create virtual layer to calculate count of features in layer "polygon_layer". I have no problem to create virtual layer from DB Manager. But if I do it in my python plugin, the ...
0
votes
0
answers
43
views
KeyError : whenever i change the active layer from the combo box of plugin it gives me keyError
I have used the QgsFieldExpressionWidget to build an expression and then evaluate it.
but whenever i try to change the layer from the plugin , it gives me this error.
this is my code:
self.cb_layer = ...
1
vote
1
answer
73
views
Toggle on/off rule based labeling in PyQGIS
I have a vector layer. It's defined with rule based labeling.
I need to control the rules to turn on / off programmatically.
How to do it?
1
vote
1
answer
105
views
QGIS Graphic Designer Add field
I am trying to design a little large model, and writing it i need to add fields and calculate them in output layer A from route finding point to point function before I append my result to the main ...
1
vote
0
answers
58
views
Zooming to layer extent using PyQGIS when project SCR and layer SCR are not the same
I'm creating a plugin to automate maps layout and I obviously need to use the extent of my main layer for this...
If my layer SCR and my project SCR were the same I would simply proceed this way:
...
0
votes
1
answer
134
views
Create Esri token authentication in PyQGIS
I want to create a Esri token-based authentication in PyQGIS using the generated token. I am using below code to achieve it. But while running the code I am only able to get the basic authentication ...
1
vote
1
answer
353
views
Error importing QGIS modules in standalone script: from qgis._gui import * ImportError: The specified module could not be found
I'm trying to run the following script (following Gary Sherman's PyQGIS Programmer's Guide). It is supposed to create a standalone PyQT window that displays a .shp in the QgsMapCanvas without opening ...
0
votes
1
answer
52
views
Unable to save KML file using QgsVectorFileWriter
I am using this code:
default_filename = Path.home() / "Documents/test.kml"
outputlayer, _ = QFileDialog.getSaveFileName(self, "Save KML file", str(default_filename), "KML ...
2
votes
1
answer
591
views
Use QGIS `processing.run(...., alg_params)` from OSGEO4W shell in QGIS Dev 3.26
I've created a simple tool using the code from save model to automate processing. It runs as expected in the QGIS python console but does not work from osgeo4w shell.
I have tried the process in https:...
4
votes
1
answer
172
views
What is the difference between a feature source and vector layer?
I'm trying to use PyQGIS to make a tool script in QGIS 3. I'm using the default script template as a starter. The template uses QgsProcessingParameterFeatureSource() to define the input. A quick ...
1
vote
1
answer
67
views
QgsVectorLayer Line layer in memory, layer source could not be found PyQGIS 3
I'm at a loss for what I could be missing here
self.curve_layer = QgsVectorLayer("line?crs=epsg:4326", "curves", "memory")
feats = []
xform = ...
2
votes
1
answer
241
views
Correct image for each layer via print Layout
In the code, first I am merging the Cooling_Tower(vector layer) with each raster layer and I want the output as an image, so created a layout, add a map, gave extents and page properties, and exported ...
1
vote
1
answer
191
views
PyQGIS error - 'QgsProcessingParameterMultipleLayers' is not defined
I'm making my first tool script in QGIS LTR (3.22.8). I'm following the answer given here about multiple layer parameters. I'm using the following code:
self.addParameter(
...
4
votes
1
answer
267
views
PYQGIS MapLayerComboBox filter on both layer type and field within layer
I have created a plugin, initially for myself (so I didn't have to worry about error handling), but now I need to hand it over to my colleagues and I need to make it fool-proof.
I have already ...
1
vote
0
answers
95
views
Expressing output in processing algorithms
In the following code, a KML file is created on the output path:
'''
# Save vector features to file
alg_params = {
'DATASOURCE_OPTIONS': '',
'INPUT': parameters['inputlayer'],
'LAYER_NAME': '',
'...
1
vote
1
answer
195
views
AutoFields Plugin for QGIS 3? Or best way to set up Default Values via PyQGIS?
I am working on transitioning my workflow from QGIS 2 to QGIS 3. I was using the AutoFields plugin in QGIS 2 to setup automatic adjustments to the attributes for lines and points (namely their length, ...
0
votes
1
answer
238
views
PyQGIS 3 Select features by mouse click not working
I'm using the solution provided in this question. but when I click on the canvas nothing happens. here is my code
from qgis.gui import QgsMapToolIdentifyFeature, QgsMapToolIdentify
from qgis.core ...
3
votes
1
answer
159
views
Rotating point objects toward lines using QGIS
I have a set of points that I'd like to have rotated toward nearest line by adding an attribute column angle.
Original points with no rotation
Points rotated toward line object
I have found and ...
1
vote
0
answers
142
views
Exploiting "iterate over this layer" option to process polygons within the same layer separately and obtaining a merged final output
I'd like to merge the outputs of the below script, when run with "iterate over this layer" option. The reason to enable iteration option is not to obtain separate files, but to process each ...
1
vote
0
answers
162
views
How to remove all resources loaded from QGIS plugin?
I used the QGIS Plugin Builder to create a plugin where the main.py file imports dockwidgets and class from its own file and from other files. A button on the toolbar executes the run(self) function ...
2
votes
1
answer
165
views
Using PyQGIS to buffer the width different than the height of a rectangle
So I have a polygon in QGIS (3.18) and it will always be a rectangle (I create it using minimum bounding geometry, oriented rectangle) I want to buffer the width out using some math to get the total ...