Skip to main content

Questions tagged [pyqgis-3]

Python bindings for QGIS 3.

Filter by
Sorted by
Tagged with
3 votes
1 answer
37 views

Symbology display issues in raster layers

The code below aims to apply symbology based on NDVI values ​​to the selected raster layer. However, after running the script it does not display correct information (image 1). I need to access layer ...
geofausto's user avatar
  • 775
0 votes
1 answer
39 views

PyQGIS to use Taudem

I'm using QGIS 3.34 (integrated with Python 3.9) for Windows 10. I'm trying to use MPI to execute Taudem's PitRemove in python. For some reason, it runs perfectly fine in a separate python shell or in ...
favendano's user avatar
1 vote
0 answers
55 views

Calling ST_IsValid on a QgsGeometry in PyQGIS, referencing PyQGIS object in SQL statement

I'd like to be able to verify the validity of a geometry of type QgsGeometry within PyQGIS. From what I can understand, the steps are Convert QgsGeometry to something that ST_IsValid will recognize. ...
nr_aus's user avatar
  • 3,576
1 vote
1 answer
34 views

QgsVectorLayer not loading correctly

I'm working with PyQGIS and have encountered an issue. While my code successfully creates a new layer (as evident in the screenshot attached), this layer does not load correctly into the project. I'm ...
Diogo Barros's user avatar
1 vote
1 answer
64 views

Correction of a script about assigning default styles with PyQGIS

I have a project with different shapefiles, and I would like to assign different default styles to each of these layers. Thus, when I execute the following code, it only works for the first layer, ...
Raíssa Daher's user avatar
0 votes
0 answers
48 views

PyQGIS calculate the actual map dimensions on a dynamic layout

I'm writing a plugin to more easily create atlas coverage rectangles, which are to scale and can dynamically rotate from portrait to landscape orientation. I've also written in some code which can ...
Elfry's user avatar
  • 1
1 vote
0 answers
25 views

Synchronizing qgsofflineediting database data back to remote layers using PyQGIS

I have a situation where I need to find the path(database) of GeoPackage, if the path has already exist then I need to use the existing GeoPackage data to load the offline data using qgsofflineediting ...
Nihar Sahoo's user avatar
3 votes
1 answer
158 views

Using PyQGIS 3 in Visual Studio Code

I did all the steps in the video below: https://www.youtube.com/watch?v=qobogVuXtJU&list=PLbGkCPlkC_XTAUG5HC1WPhxMuZQnBQ7jU&index=1&t=308s When I run the full Python file, it throws this: ...
Zoltán Dévény's user avatar
1 vote
0 answers
127 views

Converting coordinates into GeoJSON string with PyQGIS

I'm trying to write some code that gets the coordinates of a point, line or polygon, then I have to convert these coordinates into a GeoJSON string. I'm currently just trying to print it to make sure ...
SLC's user avatar
  • 13
0 votes
0 answers
53 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 ...
Lucas Carvalho's user avatar
0 votes
1 answer
33 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?
MoritzMoreira's user avatar
0 votes
1 answer
137 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 ...
tbob's user avatar
  • 586
3 votes
2 answers
598 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(): ...
Buff Fox's user avatar
  • 109
2 votes
1 answer
90 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 ...
Klaus's user avatar
  • 329
0 votes
1 answer
117 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?
charliey's user avatar
  • 163
0 votes
0 answers
202 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....
i.i.k.'s user avatar
  • 1,753
0 votes
1 answer
49 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 ...
i.i.k.'s user avatar
  • 1,753
1 vote
0 answers
69 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 ...
VegesaukrRex's user avatar
5 votes
1 answer
119 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 = ...
André's user avatar
  • 357
2 votes
1 answer
127 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&...
i.i.k.'s user avatar
  • 1,753
1 vote
1 answer
95 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 ...
GolD.'s user avatar
  • 39
0 votes
0 answers
83 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, ...
Zylon360's user avatar
1 vote
0 answers
92 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 ...
fcka's user avatar
  • 985
2 votes
0 answers
34 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. ...
CNIDog's user avatar
  • 479
2 votes
1 answer
269 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 ...
davehughes87's user avatar
-1 votes
1 answer
106 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", ...
PyCher's user avatar
  • 171
9 votes
2 answers
386 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 ...
9ls1's user avatar
  • 1,427
3 votes
2 answers
10k 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 ...
Diogo Barros's user avatar
0 votes
1 answer
124 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 ...
fsg's user avatar
  • 682
1 vote
0 answers
151 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 ...
bluesmonk's user avatar
  • 179
2 votes
1 answer
132 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, ...
afernandezody's user avatar
1 vote
1 answer
120 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 ...
tbob's user avatar
  • 586
1 vote
1 answer
121 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....
tbob's user avatar
  • 586
3 votes
1 answer
140 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 ...
RainForest's user avatar
  • 1,150
0 votes
0 answers
59 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 = ...
user avatar
1 vote
1 answer
106 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?
Velugoti Venkateswarlu's user avatar
1 vote
1 answer
147 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 ...
Ahmed Ismail's user avatar
1 vote
0 answers
73 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: ...
wanderzen's user avatar
  • 2,140
1 vote
1 answer
191 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 ...
Nihar Sahoo's user avatar
1 vote
1 answer
510 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 ...
Jinglelocks's user avatar
0 votes
1 answer
59 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 ...
tbob's user avatar
  • 586
2 votes
1 answer
806 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:...
GeorgeC's user avatar
  • 8,248
4 votes
1 answer
275 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 ...
camarones95's user avatar
1 vote
1 answer
98 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 = ...
tbob's user avatar
  • 586
2 votes
1 answer
265 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 ...
kanishka dubey's user avatar
1 vote
1 answer
274 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( ...
camarones95's user avatar
4 votes
1 answer
473 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 ...
WillH's user avatar
  • 455
1 vote
0 answers
109 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': '', '...
MLourdes's user avatar
  • 198
1 vote
1 answer
275 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, ...
efrank's user avatar
  • 419
0 votes
1 answer
387 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 ...
tbob's user avatar
  • 586

1
2 3 4 5
16