Questions tagged [pyqgis-3]

Python bindings for QGIS 3.

118 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
6
votes
0answers
226 views

QGIS projects in PostgreSQL (pyQGIS - saving proj to DB)

I'm currently working on some code to automate the creation of a QGIS project from tables in a PostgreSQL DB. For info I'm working in QGIS 3.4. I'm almost there, but I'm stuck on one thing How do I ...
4
votes
0answers
97 views

Rotating image by specific angle in QGIS plugin

I am using the Freehand Raster Georeferencing code in a widget to help size and locate site plans on aerial GE backdrops. I need to find a way for a user to input a specific angle of rotation and the ...
4
votes
1answer
480 views

Updating Algorithm list in pyqgis3?

I am attempting to run a union operation in a standalone pyqgis script and I'm receiving this error: Algorithm qgis:union not found The union operation fails with this code: params = { 'INPUT' ...
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 ...
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", {'...
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 ...
3
votes
0answers
147 views

PyQGIS script crashes QGIS 3 when remove a custom pluginLayer which has custom legend

I upgrade a 2.18 plugin to 3.4. PluginLayer has been refactored and I could not create a custom legend as simple as previous major version of QGIS 2 : QgsDefaultPluginLayerLegend was removed. Use ...
3
votes
0answers
47 views

Pyqgis: Added raster layers do not show up

I have a list ("datList") with names of raster layers which I want to add. When I add raster layers in the python console everything works fine: for da in datListe: layerDir = "C:/[path]/" + da ...
3
votes
1answer
93 views

PyQGIS output to specific layer

I have a Python script that I have exported from a QGIS model and I want to specify the layer it creates as output. If defaultValue=None it outputs 'Reportpmbc': '...
3
votes
0answers
289 views

Deleting vector layer from Geopackage using PyQGIS?

Programmatically I have added the vector layers to an existing Geo Package in QGIS 3.2 using python. Similarly, I would like to delete a layer from the existing Geo package using python code. But ...
3
votes
0answers
47 views

Hiding Layer Source using PyQGIS

I am developing a plugin for QGIS that loads the layers of a WFS. For security reasons I would like the user could not know the layer source. How can I remove the path of the layer in Vector ...
3
votes
1answer
101 views

PYQGIS 3 Using the ouptut from GRASS v.distance algorithm

I have a script which is trying to run v.distance on two existing shape files, buildings.shp which containing some polygons and singleasn.shp which contains a single point. This will be run from the ...
3
votes
1answer
79 views

Programmatically styling layer after output is returned from QGIS 3 processing script?

Hi this may be more of a python question rather than qgis processing script question. I've managed to successfully get the output that I want from my processing script, but I wish to take one step ...
3
votes
0answers
290 views

QGIS 3.4 Processing Python Scripts folder default configuration is lost

I have lost the default configuration of the 'Processing Python Scripts folder' on QGIS 3.4 and in consecuence some Python processing scripts and plugins cannot work properly because they cannot find ...
3
votes
0answers
581 views

PyQGIS Layout export

I have some problems with PyQGIS while generating a layout. Here is a minimal (non-)working example in which I first load some layers with their styles. Then I would like to export them using a ...
3
votes
0answers
242 views

pyinstaller package of pyqgis 3 standalone program failed import qgis.core

I have a working standalone pyqgis program with mapping ability, it was in python 2.7 and qgis 2.x library. I used pyinstaller to package it up. Now I have migrated this application to python 3.6 and ...
3
votes
0answers
258 views

“gdal:cliprasterbymasklayer” not clipping to polygons in QGIS3

I'm working on a plugin for QGIS3, and trying to clip a raster layer using a vector mask layer containing many polygons. I've been able to successfully do this using "Clip raster by mask layer" ...
2
votes
0answers
57 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/...
2
votes
1answer
346 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 ...
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 ...
2
votes
0answers
90 views

Integrating WinPython Spyder with QGIS?

I'm using Winpython 3.6.7 and I want to create a standalone application using QGIS 3.4.11. When I append the QGIS path using the sys module, nothing happens. import sys sys.path.append("C:\OSGeo4W64\...
2
votes
0answers
41 views

Getting layers path in Layer properties window in QGIS 3.4 by PyQGIS?

I'm going to know how I can get layers full path in table of contents in QGIS3.4 when my QGIS is closed and it's running such as daemon? Rememebr: my shapefiles are in some different folders. This ...
2
votes
1answer
97 views

Setting value to defaults Layer properties using PyQGIS 3

I have a vector layer, how to set defaults value in fields from the Python console. Layer Properties / Attributes Form / Defaults | In option: Default value |______________|
2
votes
0answers
33 views

getFeatures() delivers some fields more multiple times

I am extracting data from selected fields using .getFeatures() in PyQGIS (see code below). The result is correct, but for some reason python delivers some features multiple times (see below; Lamu ...
2
votes
0answers
31 views

QgsFileDownloader: download fails every time when run in a plugin

I'm developing a QGIS plugin that has the functionality to download raster files from a server. As the final step, the user has to name the file and select a file path on their system. After that, a ...
2
votes
0answers
34 views

QGIS map tile not printing some given extent in one time why?

I made a plugin in QGIS using pyqgis and qt designer to plot OSM tile in which I have one button which connects me to function in which I wrote a program to plot raster layer using param and I am ...
2
votes
0answers
57 views

How to use the Raster Calculator in PyQGIS (Console) in QGIS 3?

I want to use a script to do some raster calculations. I found this and this posts which seem to answer this question, however, it seems that they work for QGIS 2 and not for QGIS 3. I think the ...
2
votes
0answers
39 views

How to automate locally QGIS plugin building steps using exe or script?

I have made a plugin name Area Calc on my local computer. The plugin work very well. I have followed this. I don't want to release plugin. Is there any way to automate the whole above task through a ...
2
votes
0answers
30 views

How to get display of individual polygons from vector shapefile?

I am creating a shapefile with adding 20 polgons to it. poly = ogr.Geometry(ogr.wkbPolygon) for p in range(20):#20 should be replaced by pix_no ridx = rind1[p] ...
2
votes
0answers
80 views

Using Pyqgis 3 to select features from attribute table by expressions

I have a shp with the following attribute table: The column Line_ID represents each line (line 0, line 1, line 2 ... ). The column ID are the points id (point 1, point 2 … ). The column Declividad ...
2
votes
0answers
40 views

Slow retrieval of features

I have a vector layer with lots of features and I'd like to create a new layer in Python, containing only a subset of those features. To be more specific, I downloaded OpenStreetMaps data of Austria (...
2
votes
0answers
28 views

Calling a Python function for each page in an atlas

I have made a script to do some calculations for each page of a QGIS atlas (QGIS Atlas with insert map) The script is adjusting the bounding box of a map on the layout page. To make it run for each ...
2
votes
0answers
40 views

Plugin widget, include file extension by default

I've got a Plugin widget box I'm trying to configure. In one step the user defines the path to where they will export the final layout as a .pdf file. I'm using the following code to configure the box:...
2
votes
0answers
57 views

Testing for vector joins in PyQGIS 3

I'm writing a plugin in PyQGIS 3, and I've to test for vector joins before run a code, so I've found here about vectorJoin() and write this: def joinTables(self): d, f = self.lyrPair() # d = {...
2
votes
0answers
185 views

QGIS Processing Script to Create and Add CSV Layer

I have a QGIS 3 processing script that I'm working on which has the following workflow: Get xy coordinates from a grid layer and construct a list. Make calls to the Google Distance Matrix API using ...
2
votes
0answers
133 views

Call the QGIS 3D view using PyQGIS

I am working on creating a change detection script for QGIS3, that detects the differences between two DEMs and highlights the changes. Everything is working well but I have been unable to get the 3D ...
2
votes
0answers
208 views

QGIS 3.4 Layer Properties Update Extents to minimum bounding box of features

When I use QGIS 3.4.4 on Windows 10 and right click on a layer then select Zoom to Layer I zoom to half of the earth even though the 3 items on the layer are within 50 meters of each other. I tried ...
2
votes
0answers
134 views

QGIS 3.x closestSegmentWithContext returns sqrt distance 0.0 and point doesn't snap to polyline

I have a point and line shapefile. I am new to QGIS and Python, but have been able to get a working method to snap some of the points to the line. The method I am using is "closestSegmentWithContext",...
2
votes
0answers
62 views

Is there a way in PyQgis to perform a transaction upon several features at once for undo and redo operations?

I'm developing a standalone application in pyqgis (python 3.6, qgis 3.2) for editing roads and ran into a problem connected to performing transactions. When the user of the app insert, update or ...
2
votes
0answers
107 views

Convert QgsVectorLayer.extent() to EPGS:4326

Many APIs such as overpass turbo require bounding box notation like (x_max, y_max, y_min, x_min) in EPSG:4326. However the method QgsVectorLayer.extent() returns values in the source's CRS. A possible ...
2
votes
0answers
186 views

Refactor Fields using PyQGIS3

I am trying to use Processing tool to automate refactoring for several tables: here is the code I am trying to use import processing input = 'C:\\Users\\Ehsan\\Desktop\\CIS WORK\\Sample files\\...
2
votes
0answers
41 views

How to impose constraints on drop lists of two fields of the same layer?

Is it possible to impose with pyqgis3.0 some constraints on a drop list of a field attribute in order to govern the drop list attributes of another linked field? To better clarify this issue, I attach ...
2
votes
0answers
79 views

Changing the Location of Python Expressions QGIS3

I've recently started using QGIS and I've written a few custom functions to use with expressions in the Function Editor (see image below) From what I can find these appear to be saved in: C:\Users\...
2
votes
0answers
119 views

Saving outputs of “proccesing” to temp file in PyQGIS

I'm trying to save the output of a "proccesing" algorithm executed in PyQGIS as a temporal file, and then re-using it with another algorithm. The desired result is to write the output only at the end ...
2
votes
0answers
791 views

Python processing script with clip in QGIS 3.2

I have been following the QGIS scripting templates, but have been unable to get vector processing to work with input and output layers. Working with QGIS 3.2.2. The following script is my attempt at ...
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....
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
0answers
25 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
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 ...
1
vote
0answers
16 views

PyQgis 3 Script for PDF Exporting not showing map?

Im writing this script for exporting PDFs, I managed to get an output PDF as I wanted but its not showing the Map window. If i get into the Composer, the map is blank but magically refreshes and shows ...