Questions tagged [pyqgis-3]

Python bindings for QGIS 3.

Filter by
Sorted by
Tagged with
1
vote
0answers
10 views

Problem with QgsRasterCalculator.processCalculation() in PyQGIS

I have a really weird problem with a PyQGIS script which use a "for" loop. My script is doing those tasks : Go in a given directory and list all the files with os.listdir Enters a for loop to run ...
1
vote
0answers
29 views

Connecting multiple polygons with lines using shortest distance as parameter

Is there any plugin in QGIS (or code) that is used to connect multiple polygons with lines using distance as parameter. Let say that I put 10 meters, than all polygons within that distance will be ...
0
votes
1answer
29 views

Installing Python modules for QGIS3 on Mac?

I want to install some third-party Python modules for QGIS3 on Mac, however, I have no clue how to do it, since I am not so much familiar with different Python environments. Is there any similar ...
3
votes
1answer
66 views

Passing variable to function when button has been clicked

I want the user to make a selection of a layer from a QgsMapLayerComboBox and setting up their settings they wish to use. After a click on a button, a function should be called which performs the work....
1
vote
1answer
42 views

Copying attribute values to new layer in QGIS with python

I am making a buffer for a point layer and want the attribute values to be copied over to the new layer. I am able to duplicate the attribute fields, but not populate them with the values. I get the ...
4
votes
2answers
154 views

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 ...
2
votes
2answers
86 views

Using layers attribute within QgsPropertyOverrideButton

In addition to my previous question, I am struggling to implement the possibility to choose an attribute from a layer within QgsPropertyOverrideButton. I have a combobox where one can choose a layer ...
1
vote
1answer
32 views

Use Python to change a print composer layout item's extent in QGIS 3

I have a QGIS project and in that project there is a print composer layout titled mainmap. This print composer layout has my desired layout items like a title, scalebar, and legend. mainmap also has ...
2
votes
0answers
22 views

PyQGIS 3: Create a layer with a primary key

I have written a plugin for QGIS that is importing some data. In this plugin, I can create a memory layer for the data like I have described here https://gis.stackexchange.com/a/349354/10123, but how ...
2
votes
2answers
30 views

Reprojecting QgsPointXY

I am writing a plugin to import some files into qgis. The files initially have coordinates in lat lon, but I want to reproject them to a local projection during the import. So, I can set the CRS on ...
1
vote
0answers
22 views

How to visualize Earth Engine image with a minimum scale parameter?

I am trying to visualize outputs of Earth Engine with QGIS plugin. The problem arises when I want to analyze an output of a KMeans model. When I zoom in, the result changes and becomes vague to ...
0
votes
1answer
43 views

Remove a QgsRectangle from a RectangleMapTool in PyQGIS

In a QGIS plugin, I implemented a RectangleMapTool that I apply to my canvas. Thus, the user has the possibility to select a bounding box to define the spatial processing footprint. Once he has ...
2
votes
1answer
98 views

Error name '__file__' is not defined

I have a complement (image_1) that works perfect. But I get an error by wanting to make a change. I add the code of my two .py files. I want to change this address: "C:/Users/SENARA/AppData/Roaming/...
1
vote
0answers
19 views

GRASS is crashing every time I am running this pyqgis script. Any suggestions?

I have the following script that it keeps on crashing. How can I find a solution to this issue? import pandas as pd import processing from PyQt5.QtCore import * from PyQt5.QtGui import * resol=0....
2
votes
2answers
97 views

Use QGIS general tools/actions in my plugin

I am creating a QGIS plugin that will use some general tools available in QGIS like "identify features" and a plugin like a "digitizing tool". Is it possible for example to link a button of my plugin ...
1
vote
2answers
61 views

Make flashFeatureIds's duration to depend on an action

I'm working on a Plugin PyQGIS. I've wrote a method that calculate a buffer, with this buffer I get the id of a line, with this id I flash the line for a few seconds. I used flashFeatureIds: self....
1
vote
1answer
35 views

PyQGIS: How to store the result of cliprasterbymasklayer

This Question is a follow up Question to this one I recently asked. In my plugin I have a function that clips rasters by mask and I would like that the function returns the raster layer object. And ...
1
vote
2answers
59 views

Select by location using separate features iteratively (pyqgis)

I am looking for a way to run select by location, specific to the features of the 'INTERSECT' layer. I have got bus locations and bus stops and want to figure out when the bus has entered and left ...
4
votes
1answer
105 views

Get the reference of Attribute Table while opening in QGIS

I have a problem related to this question and the script. I can add some functionalities to Attribute Table (AT) by the script in the post. But according to the post, I have to open the AT using ...
4
votes
1answer
89 views

Zoom to feature by clicking cell in the Attribute Table

I have a layer which has FID field representing the unique ID of features. In QGIS, there is a Zoom to selected rows button on top of the Attribute Table. It has a shortcut (Ctrl + J) and it doesn't ...
0
votes
2answers
56 views

PyQGIS in PysScripter

I am trying to add the PyQGIS in PyScripter, I have followed the tutorial provided in QGIS tutorial: IDE settings for writing and debugging plugins. I have created the bat file as follows: SET ...
4
votes
1answer
41 views

How can i prevent a form from closing unless data is accepted by validation

I try to use a custom-form in QGIS 3 to validate input-data before saving the data in a database. It would be nice to have the form open unless every input is correct. But the dialog/form closes even ...
0
votes
1answer
90 views

Getting bounding box of polygon

I'm having difficulties to get the bounding box of a polygon. My code is the following: def getBoundingBox(self): boundingBox = [] polygon = self.getVectorLayer() vertices = polygon....
0
votes
0answers
23 views

Set the Output of a script as Input of another one

What is the correct way to call the output file of a script? Since QGIS can't name it automatically. I have this script that works perfectly, just drop a file identical to the original. from qgis....
1
vote
1answer
22 views

How close an editing session in pyqgis3

I have a custom tool to add feature points. The attribute values are provided filling a custom dialog. The code was writted following this topic. At the end of the procedure, outside the tool, if I ...
3
votes
2answers
214 views

Apply a color ramp to vector layer using PyQGIS3?

I'm trying to apply a color ramp to a QgsGraduatedSymbolRenderer in PyQGIS 3 (QGIS 3.8) using the following code: Getting the QgsGradientColorRamp: myStyle = QgsStyle().defaultStyle() ...
1
vote
0answers
73 views

PyQGIS grass7:v.distance parameter error “The number of columns and the number of upload parameters should be equal!”

I am currently working on a Python script for QGIS in which I would like to obtain the (minimum) distance from each point (polygon centroid) in the points layer centroid_layer to the line layer ...
1
vote
2answers
48 views

Refresh Oracle and Spatialite Layer with PyQgis

I'm working on a Dockwidget with PyQgis. I made an insert into an Oracle DB and a Spatialite DB and I would like to see the new insert (it's a point). The Layer where the new point is add is ...
1
vote
1answer
62 views

Qgis 3 : QgsEditorWidgetSetup for date

I need to make a date format in QGIS 3 but, in the program I need to use, QgsEditorWidgetSetup('Date',{'yyyymmdd'}), I want to get this: But I don't know how to use QgsEditorWidgetSetup to make the ...
1
vote
0answers
20 views

Which type of slash to use in path - QGIS 3.8 with Python [closed]

I'm a beginner using Python. I had a problem loading a shapefile in QGIS 3.8 using Python, while loading a rasterfile worked perfectly. I found the solution here: Can't load a shapefile with ...
1
vote
0answers
26 views

Rotating raster cells with QGIS GDAL

I've written a PyQGIS script based on this answer to the following question: Writing numpy array to raster file My data shows up at the correct, expected location but the raster cells, which are ...
1
vote
1answer
91 views

Tab widgets in QGIS plugin - run different scripts

Is it possible to run separate python processes through tab widgets of the same QGIS plugin. I have created a QGIS plugin using the plugin builder. From QT designer I added two tab widgets to the ...
2
votes
1answer
36 views

pyqgis create layer from a list of points

I am working with pyqgis in QGIS3 and i want to create a point layer from an intersection beetween a point and a polygon layer. I can identify wich points intersects my polygon layer but i can't use ...
3
votes
1answer
53 views

Create rotated point grid inside polygon

I want to create a rotated grid inside a polygon using a starting point and a rotation angle. I have started with the python script found here. I have altered the original script to accommodate ...
3
votes
0answers
35 views

PyQGIS Layout - Change Image Source QGIS 3

Looking for a solution to loop through existing layouts in a QGIS 3.6 document and change a source of an image. The image is the same in each of the layouts. What I have is: from qgis.core import ...
1
vote
0answers
47 views

PyQGIS: Using variable instead of number in selectByExpression query [closed]

I am trying to select features of a layer based on an expression that uses the variable jenks_var_sep_minclass. When running it I don't get an error message, but there are also no features selected ...
2
votes
1answer
31 views

Outputting colour associated with category in text format

I've written a plugin which randomly generates fill colours for differing categories. I'm wondering if there's a way to iterate through the category renderer and output the RGB colour as text. I have ...
3
votes
1answer
65 views

Creating a Line feature in PyQGIS QGIS 3.x

In QGIS GUI, a line feature is created from this icon 1.jpg How to Create a line with a fixed distance from a vector layer in python console. This my example: from qgis.core import * from qgis....
1
vote
1answer
52 views

Pyqgis: How to use GDAL-Tool 'Rasterinfo'

I have a couple of raster layers and for my next Plugin, I want to get the corner coordinates for each layer. My idea was to use the GDAL-Tool 'Rasterinformation' which gives as an output a lot of ...
1
vote
1answer
34 views

Understanding nested list of asPolygon in PyQGIS

In Getting list of QgsPoint from polygon Layer in PyQGIS, a user explains how to get the coordinates of a polygon and gives the following code: layer = iface.activeLayer() feature = layer....
2
votes
2answers
45 views

Hiding advanced parameters in QGIS Processing Algorithm Script

There is an option, in the graphical modeler of QGIS 3.10, to mark input fields as "advanced" to hide them from user by default (advanced model parameters). I wonder how to achieve it from a Python ...
2
votes
1answer
515 views

Deep Learning in QGIS: installing Tensorflow

I am trying to install tensorflow (with or without GPU support) with the keras API in the QGIS 3.4 LTR python 3 environment but without success. I do have a working install of tensorflow-gpu that I ...
6
votes
1answer
120 views

Get index of QgsAttributeEditorField from QgsVectorLayer

I have a QgsVectorLayer and right now I'm retrieving it's fields like that: for index in layer.attributeList(): print(layer.fields()[index].name(), layer.attributeDisplayName(index)) Now I ...
3
votes
1answer
42 views

Getting list of layers when opening a QGIS project on a standalone app?

I am trying to make a standalone QGIS app to read a .qgs file for rendering an image based on the vectors using LayoutManager. The problem is that when I try to print project.mapLayers() I get an ...
1
vote
0answers
25 views

Add help tab in plugins from the toolbox

Is it possible to add in QGIS 3 (Python Script) a help tab on the plugins created for the toolbox as it was in QGIS 2? Looking in the API I found the parameters helpString that will be deprecated in ...
2
votes
1answer
87 views

PermissionError : [WinError 32] --> how to close raster file handler after use?

I created a function where I access to a Raster folder and get all files CRS for Rsubdir, Rdirs, Rfiles in os.walk(Rrootdir): for Rfile in Rfiles: ...
1
vote
1answer
69 views

PyQGIS error message: algorithm “gdalogr:cliprasterbymasklayer” not found

I wrote a QGIS plugin and at the moment I'm going through the error messages. I'm stuck on the following: Now I show you the top of my code where I import everything and the function containing the ...
2
votes
0answers
27 views

Selecting features of one layer based on another layer

I have a polygon layer A, then a new layer is created by applying minimum bounded boxes algorithm and then I selected those features in which height and width of bounded boxes is less than 150 and ...
3
votes
0answers
59 views

QGIS 3.8.3 Python Ubuntu 18.04 Error : Could not load source layer for INPUT

I am running a .py file from terminal in Ubuntu 18.04. python3 script.py I am running the given below algorithm of QGIS Desktop 3.8.3 in script.py. processing.run("gdal:cliprasterbymasklayer", {'...
0
votes
0answers
62 views

Get catchment delineation with multiple outlets in QGIS 3.4 or 3.8

I'm starting with a DEM, then I generate a drainage direction layer (ldd). Then I'm trying to get all the watershed basins for multiple outlet points in a QGIS plugin I'm developing. I can get them ...

1 2 3 4 5 9