We’re rewarding the question askers & reputations are being recalculated! Read more.

Questions tagged [pyqgis-3]

Python bindings for QGIS 3.

Filter by
Sorted by
Tagged with
13
votes
6answers
938 views

PyCharm 2019 is not working with QGIS anymore

Since the update to PyCharm 2019 I am unable to load the QGIS Python modules. I can not use auto completion either. I already deleted the cache (by invalidating the cache in PyCharm and also by ...
7
votes
1answer
266 views

'native' vs. 'qgis' geoprocessing algorithm provider in (Py)QGIS 3

In QGIS 3 processing toolbox among all the algorithms with the QGIS 3 icon there are some with Algorithm-ID starting with qgis: and some starting with native:. What is the difference between ...
7
votes
1answer
242 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://...
6
votes
3answers
210 views

How to change form content dynamically in QGIS 3.6

By using "Identify Features" QGIS shows a form for viewing and editing attributes in the canvas. Now I want to change the visible form elements dynamically by attribute value. An example in ...
5
votes
2answers
306 views

Moving a geometry using PyQGIS3

I have a layer which has one feature. I try to move the feature(multipolygon) using the script below: layer = iface.activeLayer() for feat in layer.getFeatures(): prev_pos = feat.geometry()....
5
votes
1answer
129 views

Add Help Menu entry in QGIS 3 from `startup.py`

I would like to add a menu entry in the Help menu pointing to some web ressource, say https://gis.stackexchange.com. The following code executed from the python console works perfect: from qgis.utils ...
5
votes
2answers
431 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....
5
votes
0answers
181 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
1answer
177 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 ...
4
votes
3answers
272 views

Sort layers in table of contents in QGIS 3?

When I load a bunch of layers into QGIS, they seem to load in reverse alphabetical order. I'd like to sort them alphabetically. In this thread a solution is proposed, but that does not work in QGIS 2....
4
votes
1answer
97 views

Setting layer identifiable, seachable and removable with Python in QGIS 3?

With PyQGIS, I want to set project layer properties (Project Menu > Properties > DataSource) such as Identifiable, Searchable and Required (for Read Only, the method is QgsVectorLayer....
4
votes
1answer
203 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 ...
4
votes
1answer
199 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, ...
4
votes
2answers
548 views

PyQGIS QgsVectorLayer() Loading Invalid Layer in Standalone Python Script?

In my standalone python 3 script, QgsVectorLayer() is loading an invalid layer. When I use the exact same function and inputs in the QGIS GUI python console, the layer loads fine. I am not sure what ...
4
votes
1answer
253 views

pyqgis - post-processing of layer output of QgsProcessingAlgorithm

While extending a plugin with a Processing Provider and a set of algorithms I mostly followed the defaults of Plugin Builder 3. So, the basic code is smth along the lines of class ORSisochronesAlgo(...
4
votes
1answer
67 views
+50

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 ...
4
votes
1answer
74 views

Why get the first and the last point code from a multilinestring layer in PyQGIS 3 doesn't works?

I need to get the first and the last vertex from a multilinestring layer from PostGIS and create a memory point layer with them. The code below works for some line layers and doesn't for others in ...
4
votes
1answer
518 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 ...
4
votes
1answer
576 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 ...
4
votes
1answer
84 views

How to fix the error '_core.QgsProcessingException: There were errors executing the algorithm.'

I am trying to get the overlapping features between two layers in a loop. This works fine in most cases but raises an exception in some cases. The exception traceback does not even give any hint what ...
4
votes
0answers
75 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
419 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
2answers
214 views

Search and Replace text in All Fields in QGIS 3

I want to replace a string in ALL FIELDS / Columns of table without having to do it using field calculator in every field manually using replace( "RoadName1" ,'Wharf','WharfXXX'). I have layer = ...
3
votes
2answers
238 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....
3
votes
1answer
654 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 ...
3
votes
2answers
106 views

Script I made for pyQgis runs slow but can't find another way around it

registry = QgsProject.instance() first_layer = registry.mapLayersByName('buffered')[0] second_layer = registry.mapLayersByName('buffered')[0] areas = [] instrument_number = "tin_ttl_in" proprietor =...
3
votes
1answer
76 views

Making Upload button for shapefile in QGIS plugin?

I am new to Plugin Builder and creating my first plugin called NearestNeighbour. The below is GUI of my plugin made using Qt Creator I read in this link that it is important to rename Dialog Box, ...
3
votes
1answer
432 views

Print Layout Items. setExtent() and attemptResize()

I'm trying to arrange some map items onto a print layout. Let's start with the map item itself. Here is my code to add a map item to the print layout. Specifically I have questions about the ...
3
votes
1answer
398 views

Install QGIS plugin manually - Package not available in Plugin Manager

If it is helpful, I am using QGIS 3.4.3 (Madeira) and MacOS High Sierra v10.13.6 I am trying to install a QGIS plugin manually, I've been using the instructions from the PyQGIS Programmer's Guide by ...
3
votes
1answer
846 views

Output layer from PyQGIS 3 processing script is empty

I've created a processing script in QGIS 3, and although my output layer has shows a feature count greater than zero when using the feedback command, the resulting feature layer that appears in QGIS ...
3
votes
1answer
1k views

QGIS 3.0.2 Check if a field exists in a layer in Python

There are a few posts similar to this one, but none that I have found that hit it right on the head. My question is simply, how can you find if a field exists in a layer in QGIS 3.0.2 using Python? ...
3
votes
1answer
36 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
78 views

Setting a Background Color with RVBT field with python

I'm trying to set the color of a background of a layer. To do this i created an attribute "Color" with the RVBT numbers associate to each feature. As in the picture, i want to set the color with those ...
3
votes
1answer
45 views

selectionChanged connection is being called twice

I have this function with: self.iface.mapCanvas().selectionChanged.connect(self.openThePano) which waits for a feature selection change to connect to the function openThePano the issue is that once a ...
3
votes
1answer
100 views

Using libraries other than PyQGIS to develop plugin for QGIS?

I develop a plugin for QGIS. Before to integreted it in the QGIS I developped it with GIS library (Fiona, shapely, geopandas, ...) and it work well. Now I try to build it with plugin_builder of QGIS. ...
3
votes
1answer
67 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....
3
votes
1answer
377 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() ...
3
votes
1answer
35 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
2answers
43 views

Working with memory ouputs in PyQGIS3

I have the following code snippet I run in QGIS 3.4 which goes through a list of shapefiles (my_wild) and runs a polygon to lines process. It performs the process and adds them to the map as expected, ...
3
votes
1answer
64 views

Get Layer's Raster Band Data in pyQGIS

In QGIS I am trying to read raster band data from a specific layer in my Python plug in. I can easily get access to the layer from the console with something like this. iface.mapCanvas().layers()[0] ...
3
votes
1answer
75 views

Show feature count with PyQGIS 3

After adding a layer to my QGIS project with a Python script, I want to show the number of objects beside the layer in the layer window. I have tried this code, which is from Show feature count of ...
3
votes
1answer
63 views

Making a custom expression “portable”…?

In a QGIS project im using a custom expression. As far as i know they are stored locally in a .py file located in the user profile. What would be the solution to make this custom expression "...
3
votes
1answer
107 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 ...
3
votes
1answer
112 views

Does any body knows if there are a ArcSDM version or port for QGIS?

ArcSDM is a series of python analysis tools for ArcGIS developed by Don Sawatzky, Gary Raines y Graeme Boham-Carter in 2010. At present is maitained by the University of Campinhas, Brazil and ...
3
votes
1answer
386 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'...
3
votes
2answers
35 views

Setting new size for printLayout using PyQGIS

I am trying to create an A0 layout from PyQGIS. I tried the following code but it doesn't work. from qgis.core import * manager = QgsProject.instance().layoutManager() layouts_list = manager....
3
votes
1answer
54 views

Custom renderer crashes QGIS because “renderFeature” is called in a different thread

I am trying to implement a custom renderer with Python in QGIS. I have put together a small toy example based on the code from the Creating Custom Renderers section of the PyQGIS Cookbook. To get ...
3
votes
1answer
211 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 = ...
3
votes
1answer
96 views

QGIS EditForm Layout Settings in Python

I want to design Editor Forms in QGIS 3.4 programmatically via QGIS' Python API. Step 1: Setting Editors and human readable names for fields works fine via calls to QgsVectorLayer....
3
votes
2answers
464 views

Getting coordinates from mouse click in QGIS 3 (python plugin)

I am trying to get coordinates from a mouse click in QGIS 3 and python 3 using the plugin builder. I have tried using the response from this post, and i can manage to get the coordinates printed to ...