Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [pyqgis-3]

Python bindings for QGIS 3.

1
vote
0answers
20 views

QGIS 3.4/3.6 standalone script

So, I have this little script (which I would like to build more upon). I was able to make it work in QGIS3.2 (just change all paths and environments to 3.2) but now, after deleting QGIS 3.2 and ...
1
vote
0answers
14 views

Remove a raster layer and reload it from 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: ...
0
votes
0answers
5 views

Taking snapshot from for loop in PyQGIS 3?

I am pretty new in PyQGIS and programming in general, and I am trying to get images from four different layers. If I do just for one time with Qtimer option, works... but the problem appears when I ...
2
votes
0answers
27 views

How to get raster layer metadata in python for QGIS 3.6? [on hold]

I am loading imagery as raster layer through a URL. I need to store its metadata as JSON string in db for future reference. I tried getting the metadata via layer.metadata() and then tried to get ...
1
vote
1answer
30 views

QGIS 3.4 / QgsVectorLayer()

I tried to use QgsProject.instance().addMapLayer(layer) on QGIS 3.4 but I didn't succeed. Example: layer = QgsVectorLayer(r'C:\CURSO_PYQGIS\CAPAS\urbano.shp','urbano','ogr ') QgsProject.instance()....
1
vote
2answers
43 views

Adding tile layer via PyQGIS

Any idea how to add a tile layer (XYZ-Layer) using PyQGIS 101 to a map? Something like osmLayer = QgsXYZLayer(uri.uri(), "OpenStreetMap", "XYZ") "XYZ" is a raw guess. Running QGIS 3.6.0
1
vote
0answers
13 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
8 views

How to set a new raster band to a QgsPalettedRasterRenderer object?

Is there a way to set the current raster band to an existing QgsPalettedRasterRenderer object? Other renderer have specific methods for that (e.g. setRedBand, setGreenBand, setBlueBand, setGrayBand, ...
2
votes
1answer
50 views

Error loading layer in QGIS using Iface

While I was trying to load a vector layer (Shapefile) from the desktop directory into the QGIS using the iface variable data is not loading and user name in location of the status message is showing ...
0
votes
1answer
37 views

How to test for previously joined layers before run a code

I've a function that join two added layers. The code works fine, but now I need to test for previously joined layers before run this function. The function code is right below: def jointables(dict): #...
0
votes
0answers
8 views

QgsVectorLayer, configuring ogr uri for a shapefile (to set field datatypes)

I'd like to load a .shp and set the data type of one of the fields. I thought something like this would work: uri = 'C:/myfile.shp?field=myfield:integer' vlay = QgsVectorLayer(uri ,'some_name','ogr')...
0
votes
0answers
19 views

Developing and desirably debugging pygis-3 processing scripts?

The writing of processing scripts in QGIS3 changed substantially. On the basis of many tutorials/blog posts and answers on this site I got a running processing script in QGIS3. But it was, for a lousy ...
1
vote
1answer
31 views

How to fill values in a field of a layer if the id columns of two layers match using pyqgis 3?

I have two layers, pipes and intersect layers. Both layers have an id, score column but intersect layer does not have all the ids present in pipes. So I am trying to check if the id present in pipes ...
1
vote
0answers
23 views

Using non-spatial csv with PyQGIS?

I have some csv lookup tables which are too heterogeneous for ordinary join so I want to process them in PyQgis. However the csv files have no geometry column whatsoever. If used as QgsVectorLayer the ...
4
votes
1answer
67 views

How to add an existing QGSVectorLayer to QGIS project?

I know I can pull a vector file into my current project using: vlayer = iface.addVectorLayer(r"S:/Data/Natural_Earth_quick_start/110m_cultural/ne_110m_admin_0_countries.shp", "admin", "ogr") But if ...
2
votes
0answers
44 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 ...
1
vote
1answer
36 views

Clipping in PyQGIS2 working but error in PyQGIS3 (argument 1 has unexpected type 'str')

I am trying to clip streets by a layer with municipalities in them. I was trying to run this script in QGIS3 but obtain the error hereunder. Traceback (most recent call last): File "C:\OSGEO4~1\...
1
vote
0answers
18 views

Open Identify Results Window from QGIS Plugin [duplicate]

I am trying to open Identify Results docked window using qgis plugin. How can i open the identify results window using feature id? I am iterating through active layer, get a specific feature and then ...
2
votes
0answers
21 views

How can I programmatically style 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 ...
1
vote
1answer
53 views

Adding processed features and layer to QGIS 3 project

Hi I'm writing a new processing script for QGIS 3.4.5 and am stuck at the last step where I have to add the features to the newly created layer, then add the layer to the map. For more context, this ...
1
vote
1answer
30 views

How to set QgsPropertyCollection via an dict

I've to set some layer properties from all loaded layers using QgsPropertyCollection, and I handle it with this code below(doesn't have the loop for all layers yet it's for the activelayer only): pc =...
0
votes
2answers
105 views

QGIS 3 - Creating a new layer through DB Manager

When I load a polygon shp file into QGIS 3.6 and run a query finding the centroids of the polygons, I cannot load it back to the layers panel. The same operation works fine in QGIS 2.18.2. The query ...
2
votes
1answer
72 views

QGIS Processing Script Stops Working After First Run

I have a script that creates a multi-distance buffer rings and have managed to migrate it successfully to QGIS 3.4.5. This script requires me to select a layer, and a feature in the layer before I run ...
2
votes
1answer
35 views

How do I set QgsVectorFileWriter.SaveVectorOptions for QGIS 3?

I wrote a processing scrip for QGIS 2.18 to create a multi-distance buffer rings using the haversine formula. Unfortunately, it no longer works after I updated to QGIS 3.4.5. I've tried updating the ...
2
votes
0answers
61 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
38 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 ...
3
votes
1answer
128 views

processAlgorithm problem with QgsLayoutItemLegend.model()

I've got a script which adds a legend to a print layout. It works perfectly as a script but when I try to implement this in the processAlgorithm of a QGIS plugin, it doesn't work. If it is helpful, ...
1
vote
1answer
44 views

How to read the error when writing vector files in QGIS 3.0

Upgraded to QGIS 3.0 and now I cant read writer errors. The following (post 2to3) code doesnt print the error to the console: CRS=QgsCoordinateReferenceSystem().fromEpsgId(4326) error = ...
1
vote
0answers
20 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
44 views

Identifying selected feature using PyQGIS?

If I select a feature and run self.iface.actionIdentify().trigger() it will open the identify window but won't open the selected feature's data, how can I make it open the data of the selected feature?...
1
vote
0answers
34 views

Getting rid of qt.qpa.plugin Error? [closed]

I am trying to execute standalone python script outside QGIS. But when I try to initialize Qgs Application , it give me below error . I don't have any idea how to get rid of it . from qgis.core ...
1
vote
0answers
80 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 ...
0
votes
1answer
81 views

Plugin processAlgorithm. Same code, different results in script vs plugin code

I'm adding functionality to a QGIS Plugin to create a print layout and add stuff to it like a map, legend, etc. To test this code, I wrote a script. The script works and creates the print layout the ...
1
vote
1answer
45 views

PyQGIS - Plugin returns error from processAlgorithm. Invalid Result

I've written a script which automatically creates a print layout and exports it. Now I'm trying to integrate the code into my plugin's code. The plugin has some existing functionality and I'm adding ...
1
vote
0answers
25 views

QgsFeatureRequest() with a string search within QGIS3 Processing Script [closed]

I'm trying to select features using a string comparison within my script using a QgsFeatureRequest() and getFeatures() roadsRequest = QgsFeatureRequest() roadsExpression = str(roadsIDField[0]) + ' ...
1
vote
2answers
47 views

Opening multiple attribute tables using .showAttributeTables()

I've got a question about .showAttributeTables() - i'm trying to open two attrbute tables at the end of a query (selection of lines within a polygon layer) - I thought I could simply do somthing like ...
0
votes
0answers
22 views

pyinstaller3.4 package of pyqgis 3.7 standalone program failed import qgis.core due to missing PyQt5.QtPrintSupport

I have a qgis standalone program that is develop with python3.7/pyqt5.11 that come with the OSGEO4W's QGIS 3.4.4 (the latest LTR), it has the following imports: import os, sys import sip from PyQt5 ...
2
votes
1answer
51 views

How to get data source attributes from PostgreSQL and PostGIS layers

I want to get attributes like schema name and table name from PostgreSQL and PostGIS loaded layers in QGIS 3. I've searched in API docs but just found about set data sources, anyone knows how to get ...
1
vote
1answer
85 views

Filter layerlist in snapping dock of QGIS3 to show only layers selected in the layer-dock (TOC)

I would like to filter the layerlist in the "Snapping and Digitizing Options"-Dock so that only layers are shown which are selected in the TOC of the QGIS-Layer-Dock. At the moment I use a workaround ...
1
vote
1answer
87 views

Stuck on how to list loaded layers in QGIS 3 via Python

I've stuck on a issue about getting a list of loaded layers. I've two layers loaded, one spatial (point, line or area) and another one non spatial (postgresql table). I've tried this code but it lists ...
2
votes
1answer
50 views

Importing QGIS3 processing tools in standalone script

Inspired by this question, but for QGIS 3 (and therefore Python 3), I would like to use the QGIS processing algorithms in a standalone Python script without a GUI, with a standard installation of ...
2
votes
0answers
78 views

QGIS 3 - Wrong legend for datadefined size points layer

I am trying to generate a proportional symbol symbology using data defined symbol size in a QGIS 3 python plugin. Here is the working code : # Symbol creation symbolLayer = ...
4
votes
1answer
114 views

PyQGIS - QgsColorRamp Shader, Overwrite discrete values?

I'm shading a raster layer using a QgsColorRampShader, using discrete values. Basically, I want to make the value '255' a black color because it is a null value. Here is the step-by-step through my ...
7
votes
1answer
192 views

Looking for common PyQGIS functions for QGIS 3

I would like to rewrite some of my QGIS plugins to use more common functions used by all of my plugins. There exist some older functions (GIS2) like https://github.com/NathanW2/parfait https://...
1
vote
0answers
43 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 ...
2
votes
2answers
60 views

PyQGIS - Managing print layouts

I'm struggling to understand how to manage print layouts using python for QGIS. For example, I am starting with Zero exisiting print layouts in my layout manager. I create a new print layout and add a ...
2
votes
0answers
27 views

Upgrading multiprint plugin to QGIS 3 [closed]

I'm trying to upgrade multiPrint plug in to QGIS3, but I'm newbie on python My upgrade return an error like: AttributeError: 'QgisInterface' object has no attribute 'activeComposers' activeComposer ...
0
votes
0answers
54 views

Python script randomly crashes QGIS

I'm trying to run a processing script in QGIS 3.4. It doesn't complete because it seems that step 3 is not generated. A few seconds later (after I got the error), QGIS completely crashes (I get the ...
1
vote
1answer
42 views

Deprecation warning when importing Processing in pyQGIS 3

I use QGIS 3.4 with Python 3.7 and I have a warning message when importing Processing like this : import processing from processing.core.Processing import Processing Here is the message : Using or ...
2
votes
2answers
48 views

PyQGIS Raster Band Stats - Access pixel values of raster layer

I am trying to access individual pixel values in a raster layer I'm working with. I can use QgsRasterBandStats to get some information about the raster layer with the following code: layer = iface....