Questions tagged [pyqgis-3]

Python bindings for QGIS 3.

Filter by
Sorted by
Tagged with
14
votes
6answers
1k 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
275 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
262 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
278 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 ...
6
votes
1answer
119 views

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 ...
6
votes
1answer
178 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 ...
6
votes
0answers
225 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 ...
5
votes
2answers
131 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....
5
votes
2answers
366 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
2answers
472 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....
4
votes
3answers
358 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
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? ...
4
votes
1answer
101 views

Get the reference of Attribute Table while opening in QGIS

I have a problem related to this question and the script. I can add some functionalities to Attribute Table (AT) by the script in the post. But according to the post, I have to open the AT using ...
4
votes
1answer
106 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, ...
4
votes
1answer
192 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
1answer
73 views

Zoom to feature by clicking cell in the Attribute Table

I have a layer which has FID field representing the unique ID of features. In QGIS, there is a Zoom to selected rows button on top of the Attribute Table. It has a shortcut (Ctrl + J) and it doesn't ...
4
votes
1answer
229 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
113 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. ...
4
votes
1answer
222 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
668 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
320 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
35 views

How can i prevent a form from closing unless data is accepted by validation

I try to use a custom-form in QGIS 3 to validate input-data before saving the data in a database. It would be nice to have the form open unless every input is correct. But the dialog/form closes even ...
4
votes
1answer
77 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
650 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
677 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
131 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
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
2answers
262 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
278 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
706 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
166 views

Apply a color ramp to vector layer using PyQGIS3?

I'm trying to apply a color ramp to a QgsGraduatedSymbolRenderer in PyQGIS 3 (QGIS 3.8) using the following code: Getting the QgsGradientColorRamp: myStyle = QgsStyle().defaultStyle() ...
3
votes
3answers
142 views

How to load external files in PyQGIS?

I have lots of models in QGIS 3.8. I´m translating them to Python scripts to still use in the Tollbox but qith reduced processing time. Using the QGIS automatic "export model as Python script", I´m ...
3
votes
2answers
118 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
535 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
453 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
1k 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
41 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
176 views

Change vector layer symbology PyQGIS 3?

I'd like to change the symbology of my vector layer and can't figure it out how to read the documentation. I would like to have an polygone with an orange outline, a dashed fill style and an orange ...
3
votes
1answer
95 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
53 views

Hide columns in QgsAttributeTableView with Python

I use this code to initialize QgsAttributeTableView and hide some columns in it in my custom widget: def __init__(self, layer, canvas, hidden_columns, cache_size=5000, parent=None): """...
3
votes
1answer
52 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
135 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 ...
3
votes
2answers
392 views

Struggling to use Field Calculator - PyQGIS

I'm using QGIS 3.4 (Madeira) and I am struggling to use python to calculate attributes of a new field in the attribute table. I have already joined a csv and a shapefile. I use the code below to ...
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....
3
votes
1answer
424 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
44 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
53 views

Routing a consecutive set of points on a network

I need to generate routes based on a consecutive set of points exactly as given in this routing script by Anita Graser. As given in this image, I have a layer of consecutive points as well as a ...
3
votes
2answers
49 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
89 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] ...