Questions tagged [pyqgis-3]

Python bindings for QGIS 3.

117 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
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 ...
1
vote
0answers
45 views

Adding layers to project from a processing tool in QGIS3

I'm trying to add some layers created during a process to a project. There seems nothing to be added (TOC empty) but when I close QGIS It says: This project includes one or more layers as ...
1
vote
0answers
58 views

PyQGIS console error in QGIS 3.8.2

I have problem with python console in QGIS. Traceback (most recent call last): File "C:\PROGRA~1\QGIS3~1.8\apps\Python37\lib\code.py", line 90, in runcode exec(code, self.locals) File "",...
1
vote
0answers
45 views

RuntimeError occurs randomly on pyqgis loop

I wrotee a loop in pyqgis 3 to apply processing to each polygon of a layer. Apparently randomly, a RuntimeError occurs and crashes my script. Here is the loop part of my script, with the first ...
1
vote
0answers
79 views

Unable to load layers created with Processing Toolbox PyQGIS 3

I figured out that besides from the python editor within QGIS, the layers that I'm creating with a Processing Toolbox are not saved and displayed in my .qgs projects. --> see image: 1) what I get ...
1
vote
0answers
22 views

Using QGIS plugin that's designed for use in interface within PyQGIS?

I need to use a plugin that's designed for use within the QGIS interface in PyQGIS. For example https://github.com/dgoedkoop/joinmultiplelines works great but I want to run it within a script, so ...
1
vote
0answers
34 views

PyQGIS replace text label in Layout view by new text label from csv tabel

Currently, I'm stuck working on my first python plugin and hope to get some adivce here. The plugin should take a csv file (or .xlsx would be even better) which has two string columns. Column 1 has ...
1
vote
1answer
99 views

How to rename the result of a QGIS Processing Algorithm

When calling a QgsAlgorithm from within another, the result will be named after this algorithm output regardless of what is setup as the output of the main one. For instance, taking the code from ...
1
vote
1answer
35 views

pyqgis 3 vector layer labeling settings dialog

I am working on a pyqgis standalone application with the latest QGIS 3 libraries and in python 3.7. I would like to allow users to modify any vector layer's labeling style, I know in QGIS program, one ...
1
vote
0answers
25 views

Configure QGIS in a project on PyCharm on Ubuntu

I'm creating a PySide2 project and i'd like to know if it's possible to add QGIS in it. When i puted "from qgis" it does not work. from PySide2 import QtCore, QtGui, QtWidgets from qgis._core import ...
1
vote
0answers
78 views

Calling a temporary layer in PyQGIS

I have the following PyQGIS script (see below) which works fine except from one issue: The input vector layer I would like to use is a temporary file. How can I call a temporary layer (which does not ...
1
vote
0answers
75 views

Syntax error using layer.getFeatures PyQGIS

I am simply trying to run a command in QGIS to extract the coordinates of a point layer, but I get a syntax error when trying to do so (see code below). I can not see where the issue is - any ...
1
vote
0answers
52 views

Use pyQGIS to extract QGIS style as geometry in a DXF

I have a qgis point layer with a complex data driven style: This is the style without other layers: When exporting the layer as Dxf I would like to also export the style so the symbols are visible ...
1
vote
0answers
142 views

How to build loop using memory layer with PyQGIS 3?

I have a "for" loop included on a "while" loop, and it work when I save the for loop result in a shapefile and I reuse it on the loop like that : #last step of the "for" loop alg_params = { ...
1
vote
0answers
174 views

PyQGIS (3.6.3 Noosa) Why is self.iface.mapCanvas().setExtent() being overridden in plugin?

I am writing a plugin that first adds the Google Imagery XYZ tile layer and then adds various other layers - some from a GeoPackage and others by creating their geometry in PyQGIS. The last function ...
1
vote
0answers
99 views

Where is “Nearest neighbour analysis” tool in pyqgis documentation?

I have a group of point features for which I want to run the Nearest neighbour analysis using python. The problem is that I cannot find that function in the documentation. The closest I got was: ...
1
vote
0answers
42 views

Open attribute table script in QGIS 3.6 graphical modeler

I am looking for a script which will allow me to open an attribute table of the final output of a graphical model in QGIS. I know that you can use the following lines of code in the console but ...
1
vote
1answer
161 views

QGIS 3 PyQGIS Script - Merge Layers and Export to csv with KML geom field

I previously had a script in 2.18 that exported csv files with kml geometry's file by file. I'm now wanting to move to QGIS 3 and do the same process except Merge the point layers then add the ...
1
vote
0answers
42 views

How to add or delete one category in Categorized Symbol Renderer PyQGIS QGis 3.x

I need code for add o delete Categorized Symbol in QGIS 3 category = ? More information: https://qgis.org/pyqgis/3.4/core/QgsCategorizedSymbolRenderer.html
1
vote
1answer
148 views

Load layer styles from PostGIS DB with QGIS 3 with PyQt5

I'm trying to load styles that are stored in a PostGIS database. We have them organised in sets, for each layer that is in the DB. I added comments in the code. This code was previously 2 lines. ...
1
vote
0answers
118 views

Merging multiple QgsRasterLayer objects to create virtual raster (.vrt file) using gdal

I am creating multiple QgsRasterLayer objects in pyqgis and I need to merge them into a virtual raster .vrt file which will eventually be loaded as a layer in QGIS. The QgsRasterLayer objects are ...
1
vote
0answers
62 views

PyQGIS - QgsProcessingParameterFeatureSink, Why is user input required?

I'm working with a QGIS plugin widget and I have a box which creates a temporary table as an output. I've created the box using the QgsProcessingParameterFeatureSink class. Here is how I created my ...
1
vote
0answers
244 views

Rename fields of shapefile using PyQGIS 3

I am using the following script through QGIS 3.4 "Python Console" to rename field names of shapefiles. The input will be a CSV file with 1st row - shapefile name, 2nd row - old field name, 3rd row - ...
1
vote
0answers
73 views

Updating identify tool every time feature is selected with PyQGIS3

I want to use the "Identify Feature Tool" in code (PyQGIS3). What I've found in the internet doesn't use the tool, people usually print in console point features and ids. I also found a tool that ...
1
vote
0answers
118 views

Remove and reload raster layer from previously created QgsRasterLayer object

I have created a QgsRasterLayer object using: lyr=QgsRasterLayer(url,'lyr_name') and the layer is displayed by: QgsProject.instance().addMapLayer(lyr) Now when this layer is removed through: ...
1
vote
0answers
81 views

pyqgis 3:how to identify partial intersections between a buffer (polygon) layer and pipe (line) layer?

I have a drains layer (polygon) around which I have created buffers of varying distances. I want to find the intersection between the different buffer layers and pipes (line) layer and accordingly ...
1
vote
0answers
26 views

Unable to use PyQGIS since python is unable to import qgis libraries

I am using Ubuntu 18.04. I have installed QGIS 3.4.4 Madeira on my laptop. I am learning PyQGIS. I have found these lines of code that I have executed in my terminal but I get a traceback saying that ...
1
vote
1answer
351 views

Using GRASS in Python script QGIS 3

I am creating a Python script in QGIS 3 and I want to use the processing module. I want to transform my raster file to a vector file with the GRASS algorithm r.to.vect. My problem here is that the ...
1
vote
0answers
119 views

Launch a QGIS plugin from a batchfile

After having built a QGIS 3 plugin, I'd like to know how could I call my plugin without clicking on the plugin bar of QGIS to launch it. I've tried implement a first batch file for it : REM changer ...
1
vote
1answer
101 views

Setting selection border color in red and save the map of the resulting selection

I'm attempting to create a plugin in QGIS 3 in order to zoom on a selected feature and get the map picture exported in .jpg format. I've been able to perform the zoom and selection of my selection, ...
1
vote
0answers
56 views

How to set project CRS with plugin (sqlite layer)?

I'm loading a sqlite db into the current project of qgis with a plugin. The standard CRS is EPSG:4326, however i want the canvas to be set at EPSG:3857. When running one of the 2 codes in the console,...
1
vote
0answers
86 views

pyqgis - Code stops working when called using threading.Thread()

I am trying to troubleshoot a threading problem. QGIS version is 3.4. I want to move a processing-intensive task (importing xyz data, applying hillshading, and saving as TIFF) to a separate thread. I ...
1
vote
0answers
161 views

Python QGIS : Adding features to a temp vector layer with their attributes

I try to create a temporary vector layer with data from another vector layer that are inside a polygon. My code works perfectly except that in the temp vector layer, the fields of the attribute table ...
1
vote
0answers
99 views

Opening template project with PyQGIS in QGIS 3?

What do I need to do to open a project-file as a template with PyQGIS in QGIS 3? I am able to open a project like this: project = QgsProject.instance() project.read('C:/path/to/my/project.qgs') But ...
1
vote
1answer
82 views

Create Widgets for specific fields of a feature

I need to create a widget were some fields of a feature are listed and are editable. I used QgsAttributeForm for this, but this widget is too big and has to many fields. I need to provide a ...
1
vote
0answers
40 views

Match a custom CRS to existing (proj4 database) ones in QGIS 3

I am reading SPS files (see format definition here) from which I gather CRS information. Unfortunately, there is no ESPG reference available nor is there any standard naming scheme for Ellipsoids so ...
1
vote
0answers
130 views

How to remove last created QgsRubberBand by clicking in Map Canvas area where doesn't exist any feature?

By combining information from these posts: Get the identified feature How to create and remove multiple QgsRubberBands in PyQGIS? I produced following code for getting feature attributes and ...
1
vote
0answers
18 views

Get the mouse event value from another module

I have two simple classes, one calls another. One of the classes is QGIS map tool and only returns the position of the clicked event to the method which activates maptool. I don't know how to do this. ...
1
vote
0answers
68 views

How to call correctly QgsMapRendererJob in pyqgis3

I'm trying to modify ma pyQgis2 code to run in pyqgis3. That is custom application, that shows canvas with appropriate layers and settings and I can't refresh canvas with pyqgis3. pyqgis2 code that ...
1
vote
0answers
188 views

Polygon Centroids working for only some Polygons in PyQGIS?

I have a building Layer(Full of Polygons).I want to get centroids of polygons and save them as point layer.I am using python console within Qgis 3.0. I have tried below code.I got my Centroid Layer(...
1
vote
0answers
167 views

Nearest Neighbour Analysis Or NN join

I have two Layer in my Project 1) Voronoi Layer which is constructed on point Layer 2) Building Layers which is represented as Polygon. The goal is to find the nearest node for every polygon (...
1
vote
0answers
40 views

How to merge polygons to get coordinates of final shape?

I have list of plots numbers that should be merged into multipolygon. As a result I have to get coordinates of final shape (as multipolygon). That is may code: # work only on layer "plots" name = ...
1
vote
0answers
61 views

Changing name of outputlayer dynamically in QGIS Processing script?

I have a processing script to load txt-data from a magnetometer and convert them into a vectorlayer (to make a raster in a second step). I want the name of output layer to be changed into something ...
1
vote
0answers
55 views

pyqgis: release all image locks

I have a QGIS 3.2 workflow that helps me to mass produce image classiication labels for some deep learning work. The workflow creates multiple files with various prefixes in tif format. At the end ...
1
vote
0answers
51 views

Improve performance of QgsVectorLayerDirector.makeGraph() in PyQGIS 3

Porting a plugin that makes excessive use of PyQGIS networking capabilities I had to realize, that building the graph (makeGraph() method of class QgsVectorLayerDirector) in PyQGIS 3 (https://qgis.org/...
1
vote
0answers
106 views

Make QgsVectorLayer().getFeatures() ignore an existing filter

When retrieving features from a layer with PyQGIS by sth. like feat = [f for f in my_lyr.getFeatures('"road_name" = \'myroad\'')] the resulting feat list is empty in cases where a filter is applied ...
1
vote
0answers
84 views

Why python function not work in custom function in QGIS 3.2?

in QGIS atlas I use a custom function to find the first file containing texts : import os, fnmatch from PyQt5.QtCore import QFileInfo from qgis.core import * from qgis.gui import * @qgsfunction(args=...
1
vote
1answer
56 views

QgsSingleBandPseudoColorRenderer not automatically applied after added

Summary I am trying to apply a Single Band Pseudo Color Renderer (SBPCR) to a raster layer, importing the shader from an XML. I've hit a dead end trying to get my SBPCR to apply. QGIS Version - 3.4....
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....
0
votes
0answers
52 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 ...