Questions tagged [pyqgis-3]

Python bindings for QGIS 3.

Filter by
Sorted by
Tagged with
0
votes
1answer
35 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
0answers
27 views

Please help me sorting out this problem.File “<string>”, line 15, in <module> AttributeError: 'NoneType' object has no attribute 'GetRasterBand' [closed]

import gdal import numpy as np bf_overburden = "D:\Minnesota data\Data files\clipped\water level\overburdenthickness.tif" bf_fractpresslevel = "D:\Minnesota data\Data files\clipped\water level\...
-2
votes
0answers
17 views

I see the following error “NameError: name 'pressurehead2' is not defined” Please suggest the place where I should change the code [closed]

dem_ras_input = "D:\Minnesota data\Data files\clipped\Buffalo_DEM.tif" dem_ras = QgsRasterLayer(dem_ras_input, "dem_raster") QgsProject.instance().addMapLayer(dem_ras) waterlevel_ras_input = "D:\...
2
votes
0answers
56 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
91 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
55 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
29 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
43 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
101 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
73 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
49 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
35 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
50 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
21 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
19 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
168 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
50 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
45 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
49 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
18 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
24 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
79 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
31 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
46 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
31 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
35 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
30 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
50 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
31 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
42 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
345 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
119 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
39 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
24 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
63 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
61 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
50 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
50 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
vote
0answers
28 views

PyQGIS wrong editing tool warning

I am trying to add a point by using the pyqgis code below: layer = iface.activeLayer() # point layer layer.startEditing() iface.actionAddFeature().trigger() Then the marker becomes add feature ...
1
vote
1answer
26 views

Built-in ZOOM function

Does anybody know where i can find implementation of feature called "Zoom to Feature". To use this function from GUI you have to right click on layer then choose "Open Attribute Table" then right ...
1
vote
1answer
46 views

Change attribute values of multiple fields via PyQGIS

I am starting with PyQGIS and I would like to change the values of two fields within selected features: from qgis.PyQt.QtCore import QVariant parent = iface.mainWindow() mc = iface.mapCanvas() myLyr =...
3
votes
1answer
56 views

Easy way to close open clipped contours with the edges of the clipping mask?

I am trying to programmatically (with pyqgis) clip contour lines that I've generated in QGIS, but make it so that the clipping mask forms the new edges of the contours, rather than leaving the ...
1
vote
2answers
177 views

QGIS Python ImportError: No module named builtins

When I am executing a python script for doing a geoprocessing task using QGIS Desktop 3.8.3 (executed using a windows .bat file), I am getting an import error. from builtins import zip ImportError: ...
3
votes
2answers
53 views

Routing a consecutive set of points on a network

I need to generate routes based on a consecutive set of points exactly as given in this routing script by Anita Graser. As given in this image, I have a layer of consecutive points as well as a ...
3
votes
1answer
41 views

QGIS 3.8 Python merge files

For a merge operation I need a list of all my layers in the TOC with path and filename. How can I achieve that? layers = QgsProject.instance().mapLayers() # dictionary myLyrList[] for layer in layers....
3
votes
1answer
159 views

Basic script for Raster Files - PyQGIS 3

I am trying to make a script, to run at the toolbox, that receives a raster file and has an identical output to it, following the idea from here. I couldn't find a complete script that works ...
3
votes
0answers
33 views

Changing Map Tip popup direction dynamically

Is there a way to dynamically (or semi-automatic) change direction of a popup? Default direction is 'right-down', which in some cases, where hovered feature is at the bottom of a canvas, Map Tip is ...