Questions tagged [pyqgis-3]

Python bindings for QGIS 3.

Filter by
Sorted by
Tagged with
1
vote
0answers
178 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 (...
2
votes
1answer
413 views

Definition of OUTPUT parameter in PyQGIS 3 processing algorithms

In PyQGIS 2.X I could handle the output of processings algorithm as follows: import processing # None is the OUTPUT parameter here buffer = processing.runalg('qgis:fixeddistancebuffer', ...
1
vote
1answer
255 views

Error in executing Voronoi polygon algorithm

I am trying to create Voronoi polygon on point layer of my project. I need to save this new layer as .shp file. The following is the code I have written in Python console, using QGIS 3.0 import ...
2
votes
0answers
126 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 ...
0
votes
1answer
306 views

Toggle Editing Add Feature

i have loaded the layers in qgis from database. so after picking "toggle editing" plugin,the other corresponding plugin are in disabled state only,they are not enabled.how to set "add feature" plugin ...
0
votes
1answer
99 views

Adding vector layer and newly created layer always in Top- Down Order Panel using Pyqgis 3 [closed]

I have two layers in my project Point Layer Building Layer I recently created Voronoi Polygon on Point Layer say (vor-points layer) But as soon this Happen, the newly created vor-points layer ...
3
votes
2answers
373 views

How do I declare a QGIS custom expression function and use it in a single python script?

I would like to create and populate a virtual field in a QGIS vector layer attribute table using a python script. I think the easiest way to do this is to create a custom expression function, and, ...
1
vote
1answer
202 views

qgis:JoinAttributeTable is giving a Syntax Error in QGIS 3.0

I am new to QGIS 3.0 and using "qgis:Joinattributetable" for joining .csv and .shp file. Below is my code, but I am getting Syntax Error. AttributeError: module Processing has no attribute '...
3
votes
1answer
450 views

Join CSV and shapefile in PyQGIS

I am new to QGIS and using version 3.0. I have written below code to join population data with Building Layer. I am using Python Console within QGIS. I didn't get any error but the target files doesn'...
2
votes
0answers
813 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 ...
3
votes
1answer
70 views

Hiding a field column while editing in pyqgis3

I would like to hide a field column while editing. The following code works perfectly in pyqgis2. def fieldVisibility (layer,fname): f = layer.editFormConfig() for i, column in enumerate(layer....
1
vote
1answer
178 views

pyqgis 3 QgsVectorLayer.startEditing() doesn't trigger vertex display

In pyqgis 2 standalone application, the following code will trigger the display of vertex as red cross mark, but in pyqgis 3.0.3 standalone application, it doesn't: layer.startEditing() mapCanvas....
1
vote
1answer
108 views

QGIS2 Plugin Replacement for Join Attributes by Location

I am using QGIS (ver2.18.22) to join 2 layers (polygons) at intersections to derive some summary statistics into the join layer ("Grid" layer). The "Grid" layer is assembled by using Create Grid, and ...
3
votes
1answer
223 views

Algorithm “qgis:difference” doesn't work in pyQGIS 3

I try to use native algorithm difference of QGIS. But it seams it doesn't work like the others : parameters = {'INPUT': polygons['OUTPUT'], #from temporary layer created before 'OVERLAY'...
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 = ...
3
votes
0answers
265 views

Model in QGIS 3 (.model3) to Python 3? [duplicate]

I try to export a QGIS 3 model (.model3) to Python but the functionality that was available in QGIS 2 doesn't exist anymore. Is there a way to export it ?
3
votes
0answers
254 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 ...
2
votes
1answer
119 views

QGIS 3 crashes when QgsExtentGroupBox.setOriginalExtent() is called

Below is the relevant code. I am using QgsProjectionSelectionWidget to get the CRS. canvas_extent = self.canvas.extent() transformer = QgsCoordinateTransform( self.canvas.mapSettings(...
0
votes
1answer
108 views

QGIS 3.0 migration - unable to install PyPDF2

I am migrating my Plugin to QGIS 3.0. Currently a bit stuck trying to install PyPDF2. I have been trying different things for the last couple of hours or more, without success. I have got another ...
2
votes
1answer
271 views

How to remove part of a string value in the attribute table of a shapefile in PyQGIS

I have a number of shapefiles with a field in the attribute table containing many different string values similar to this one: 'Waypoints_17-JUL-18Timothy waypoints.shp Waypoints_17-JUL-18Timothy ...
5
votes
2answers
514 views

Creating and manipulating an HTML frame in QGIS 3.2.0 Print Composer using PyQGIS

I'm trying to create, reposition and resize an HTML frame in a QGIS 3.2.0 Print Composer layout using PyQGIS: proj = QgsProject.instance() comp = QgsPrintLayout(proj) blockStats = QgsLayoutItemHtml....
0
votes
1answer
348 views

Problem running PyQt code in Qgis3

I am in my first steps in PyQt and I face difficulties in how to run the following code within QGIS console. I want to create a simple window, but nothing happens. I change main by console and then ...
1
vote
1answer
350 views

Error: Algorithm not found with correct processing use

I try to run a simple dissolve algorithm in a standalone Python 3 script. My code is following : from qgis.core import QgsVectorLayer import processing from processing.core.Processing import ...
1
vote
0answers
63 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 ...
3
votes
1answer
456 views

QGIS 3: Changing the datasource of a layer?

Everything seems to go right, but nothing happens: layers = QgsProject.instance().mapLayers().values() for layer in layers: if isinstance(layer, QgsVectorLayer): dp = layer.dataProvider() ...
4
votes
1answer
729 views

Using Python to set text for a label in a QGIS3 print layout label

I am able to assign a QGIS 3.2 print layout label item to a Python variable using: MyMapLabel = MyPrintLayoutObject.itemById('MyLabelName') Which is all well and good but I need to be able to change ...
0
votes
2answers
206 views

Saving image to variable using PyQGIS

I'm generating an image from QgsComposer composition through QgsLayoutExporter.exportToImage() method that allows saving the image to disk. I wonder if there is any way to get image binary data into ...
0
votes
1answer
388 views

How to open saved QGIS layout in layout designer with Python?

Is it possible to open saved layout in layout designer(print composer) with Python? QGIS Python API: openLayoutDesigner(self, layout: QgsMasterLayoutInterface) → QgsLayoutDesignerInterface ...
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
52 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/...
2
votes
2answers
306 views

How extract the polyline length in PyQgis 3.0?

I wrote the following code in order to automatically extract the objects' length of a line layer, but I think the « measureLine » expression is not working. This expression works very well PyQgis 2.0. ...
3
votes
0answers
265 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
1answer
362 views

QGIS 3 - Python : QgsVectorLayerJoinInfo issue

I'm trying to use Python to join a table to a vector layer within QGIS (v. 3.2.0) Here is the script I use : >>>root = QgsProject.instance().layerTreeRoot() >>>ids = root....
2
votes
1answer
339 views

How to fill fields with layer name in PyQGIS

I have hundreds of shapefiles that I have added to a QGIS project. I am using QGIS 3.0.0. I have created a new text field for each of them named 'Enumertr' in PyQGIS and I need to populate this field ...
1
vote
0answers
108 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 ...
0
votes
1answer
646 views

Find QGIS 3 plugin folder location with PyQGIS

Background of my question: I would like to figure out the version of a plugin ('my_plugin'), in PyQGIS 2 like: from qgis.utils import findPlugins import os plugins = list(findPlugins('C:\Users\me\....
1
vote
1answer
454 views

Passing “self” when calling functions in modules from other modules using PyQGIS?

I'm building a QGIS 3.0 plugin and trying to organise my code into several files. I have three files - a main python script and two other scripts stored in a subfolder. Excerpts provided below: \...
1
vote
1answer
343 views

How to set label font color using data defined property for PyQGIS 3?

Set label font color using data defined property in PyQGIS 2 is well established, e.g. in another thread However, PyQGIS 3 completely changed the way this works with no well documented examples. So, ...
2
votes
1answer
111 views

Getting “value”, “color”, “label” from existing palette raster layer in PyQGIS?

renderer = activaterlayer.renderer() symboloyitems = renderer.legendSymbologyItems() label = symboloyitems[i][0] color = symboloyitems[i][1].getRgb() value = ? How can I get the ...
1
vote
1answer
98 views

pyqgis 3.0 : how to project raster layer, avoid pop-up prompts interface

rasterlayer = QgsRasterLayer(self.infile, layername) raster_crs = rasterlayer.dataProvider().crs() if raster_crs is None: self.rasterlayer.setCrs(QgsCoordinateReferenceSystem(4326, ...
2
votes
1answer
135 views

pyqgis: how to get the existing Paletted Raster Layers' color

rasterlayer = QgsRasterLayer(infilename, layername) renderer = rasterlayer.renderer() rasterlayer is the active layer with renderer type is Palette, I want to get current Palette Color, how could I ...
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=...
2
votes
1answer
214 views

Http Request in Qgis3 Plugin

I need to do some HTTP request based on feature in PyQGIS. Based on http://zetcode.com/pyqt/qnetworkaccessmanager/ I created this class: from typing import Callable from PyQt5.QtNetwork import ...
2
votes
1answer
570 views

How to set background color of label using PyQGIS 3?

suppose I have a shapefile that have an attribute, and I want that attribute to be shown with white background behind the text in the viewport. This is what I want to accomplish: I've searched the ...
3
votes
1answer
739 views

How can I get the path for an input layer in a QGIS 3 script?

Writing scripts in previous versions of QGIS, I would get the layer path to pass to algorithms using processing.getObject(layer). In QGIS 3, the scripting system has been rewritten, and I now define a ...
2
votes
1answer
686 views

Where to find documentation on algorithm parameters when writing scripts in QGIS 3?

For older versions of QGIS, the algorithm parameters were documented in the 'Console usage' section in the QGIS documentation (e.g. the reproject layer documentation). In the QGIS 3 documentation (e.g....
1
vote
2answers
573 views

exec(open('/tmp/tmpu7edmqsu.py'.encode('utf-8')).read()) on PyQGIS 3

I tried to load csv layer using this script: file = "/home/ayato/Desktop/26mei.csv?delimiter=%s&xField=%s&yField=%s" uri = file % (",", "x", "y") vlayer = QgsVectorLayer(uri, "asd", "...
1
vote
1answer
422 views

Can get PyQGIS 3 map to display in PyQt5 standalone app or menus, but not both

I can run a standalone app but no map shows up, but different from a similar question last year. The code posted last year works for me after editing QGISHOME to Win 10 system (r'c:\OSGeo4W64\apps\...
0
votes
1answer
95 views

Save wkt as “polygon_name”.text from postgis table [closed]

I have a PostGIS-Table (PostGIS-layer) with more than 400 Polygons (ID, name, geom). I need the WKT of each feature in the layer saved in a "polygon_name".txt file with the name of the Polygon. How to ...

1 4 5 6 7 8