Questions tagged [pyqgis-3]

Python bindings for QGIS 3.

Filter by
Sorted by
Tagged with
4
votes
1answer
1k 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 ...
4
votes
2answers
1k 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 ...
1
vote
1answer
287 views

QGIS 3 startup script is not executed

Following the documentation for QGIS 3 startup script, I have placed a 'startup.py' script in the following path: C:\Users\Me\AppData\Roaming\QGIS\QGIS3\profiles\default\python\startup.py But the ...
15
votes
6answers
2k 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 ...
2
votes
1answer
242 views

Getting Layer Properties of QGIS on standalone application using PyQGIS API

I am using PyQGIS API for developing the standalone application to load the certain VectorLayers. I used the QgsMapCanvas to load the map and QgsLayerTreeView to show the layer tree view using code ...
0
votes
1answer
43 views

Load a table with NO geometry_column using PyQGIS

I had to backup a PostGIS model in a geopackage and I wonder how to load a non-spatial table, aka a table with NO geometry_column.
5
votes
2answers
908 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....
7
votes
1answer
341 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 ...
4
votes
1answer
1k 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
2k 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 ...
2
votes
1answer
495 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 ...
4
votes
1answer
1k 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
2answers
455 views

Change Output name in Script - QGIS 3

I exported a model as script using the properly option in QGIS 3.8. The Script works perfectly, but the output name is changed. Heres a print of the model: I want that the script´s output name, from ...
2
votes
1answer
219 views

Setting placement labels on “Offset From Point” with OffsetX,Y parameters in PyQGIS?

I'm trying to set properties of QgsVectorLayer using QGIS 3. I want to put labels with "Offset from point" and define "Offset X" and Offset Y". I saw on the documentary that there is a class "...
2
votes
1answer
627 views

Loading print layout using an existing template (.qpt) with PyQgis3

I'm trying to load a print layout (.qpt) which I saved earlier via PyQgis. I found this earlier entry, but it's for QGIS 2.x and thus doesn't work for QGIS3: Programmatically load composer from ...
1
vote
1answer
279 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 ...
1
vote
1answer
310 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 ...
1
vote
2answers
323 views

Offset Line with Python in QGIS

I wanted to know how could I do a offset line of one layer in a new layer. I take my layers, even if I only have one active (streets) canvas = iface.mapCanvas() layers = canvas.layers() In my case, ...
-1
votes
1answer
604 views

Adding Area column in Polygon layer using PyQGIS? [closed]

I have a WardBoundary.shp file with Polygon Features in it. I have to calculate the area of each Polygon and write into attribute Table. I can do manually by using '$area` but I need to automate ...
6
votes
1answer
658 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(...
7
votes
1answer
363 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
1answer
656 views

Save QGIS project to PostgreSQL/PostGIS database using PyQGIS

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 ...
6
votes
1answer
2k 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? ...
5
votes
1answer
10k 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 ...
5
votes
1answer
211 views

Using a custom UI for a QGIS processing algorithm script

In QGIS 2.x I have a PyQGIS script that utilises a custom form created in Qt Designer. I could simply call the form and connect a button to a function with the following: class MyWidget(QtGui.QWidget)...
4
votes
1answer
154 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
1k views

Applying graduated renderer to polygon using PyQGIS 3?

I'm trying to symbolize a polygon layer using a graduated color ramp, with no success. In the attribute field of my layer I have a column: 'PatCNT' with integer values from 2 to 6 for each row. I'...
2
votes
1answer
131 views

Qgis 3 : QgsEditorWidgetSetup for date

I need to make a date format in QGIS 3 but, in the program I need to use, QgsEditorWidgetSetup('Date',{'yyyymmdd'}), I want to get this: But I don't know how to use QgsEditorWidgetSetup to make the ...
6
votes
1answer
644 views

Deleting vector layer from Geopackage using PyQGIS

Programmatically I have added the vector layers to an existing GeoPackage in QGIS 3.2 using Python. Similarly, I would like to delete a layer from the existing GeoPackage using Python code. But there ...
4
votes
1answer
1k 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 ...
4
votes
1answer
192 views

Adding constrain/check after adding first point of line and after last point of line

I want to customize the QGIS editing tool in the following way. Scenario: The first and last point of the line layer must have a point layer. Steps: User selects a line layer. User starts/toggles ...
3
votes
1answer
114 views

Programmatically styling 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 ...
3
votes
1answer
1k 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 setExtent(...
2
votes
1answer
302 views

What is the equivalent of QgsMapToolIdentifyFeature in PyQGIS 3?

I was trying to use the QgsMapToolIdentifyFeature() tool as shown in an answer of StackOverflow, but when executed it gave the error: 'QgisInterface' object has no attribute '...
2
votes
1answer
230 views

Build Close Vertex Finder in QGIS

In OpenJump there is a tool called ClosedVertexFinder which you can use to find vertices which are too close to each other. https://github.com/ssinger/roadmatcher/blob/master/src/com/vividsolutions/...
2
votes
0answers
36 views

Trying to save grouped CSV (and eventually SHP) layers in QGIS

So, I'm trying to automate the creation of layers in QGIS using Python the data in CSV files to drive symbology shading, layer naming and file naming. The part I'm really having trouble with is saving ...
2
votes
1answer
348 views

How do I access stroke color and width of a simple marker with python in QGIS?

I'm trying to set up style properties of a vector layer using python. I was able to modify the marker properties but I cannot modify those of Simple Marker, like width or color. Here is my code : ...
2
votes
1answer
782 views

Why a QgsExpression does not evaluate a feature as expected in PyQGIS 3?

When I run following code in QGIS 2.18: layer = iface.activeLayer() expression = QgsExpression( u'"area" > 2e8 AND "area" < 3e8' ) feats = [ feat for feat in layer.getFeatures() ...
2
votes
1answer
258 views

Where to get QGIS 3 Join by Field Value Script?

I´m trying to solve my problem with Join attributes by field value and for that I want to make a script on PyQGis to solve that. Is there a location where I can found the script used in Join by field ...
2
votes
0answers
990 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 ...
1
vote
2answers
487 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 - ...
6
votes
2answers
1k 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 ...
6
votes
3answers
1k 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....
5
votes
1answer
1k 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
1answer
722 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
1k views

Getting line geometry out of two points using QGIS?

I have one input point layer and out of that, I want to create an output LINE vector layer. For each feature in my output line vector layer, I define a geometry which takes 2 point geometries. ...
3
votes
1answer
151 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
2answers
586 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
2answers
225 views

Renaming 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 ...
3
votes
2answers
612 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, ...