Questions tagged [pyqgis-3]

Python bindings for QGIS 3.

Filter by
Sorted by
Tagged with
4
votes
2answers
591 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
140 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 ...
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 ...
2
votes
1answer
311 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 ...
2
votes
1answer
424 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 ...
1
vote
1answer
231 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
votes
1answer
177 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 ...
7
votes
1answer
251 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://...
4
votes
1answer
279 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(...
3
votes
1answer
86 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 ...
5
votes
1answer
139 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 ...
3
votes
1answer
474 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
932 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? ...
2
votes
0answers
761 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 ...
2
votes
1answer
152 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
1answer
139 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 ...
1
vote
1answer
422 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'...
4
votes
1answer
566 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 ...
3
votes
2answers
346 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, ...
3
votes
2answers
229 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
1answer
679 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
407 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
1answer
47 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
516 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 ...
3
votes
2answers
252 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....
2
votes
1answer
100 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
349 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
640 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
188 views

Grouping layers using PyQGIS makes them not visible on canvas?

I've tried using the information in the following posts in order to group layers in PyQGIS (Qgis 3) Adding layer to group in layers panel using PyQGIS? Adding layer group using PyQGIS? https://docs....
2
votes
1answer
123 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 ...
2
votes
1answer
79 views

QGIS 3 export report in Python

In QGIS we have new layout type: Report. I didn't find tutoral to export this in PDF in Python. Where can I find Python code examples?
2
votes
1answer
160 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 ...
2
votes
1answer
43 views

In PyQGIS can I get the total length of a road where it's broken up into segments?

In PyQGIS can I get the total length of a road where it's broken up into segments? In SQL I would run SELECT format_number(ROAD_ID,0) as Road_ID, ROAD_NAME as Road, format_number(Sum(st_length(...
2
votes
0answers
249 views

Deleting vector layer from Geopackage using PyQGIS?

Programmatically I have added the vector layers to an existing Geo Package in QGIS 3.2 using python. Similarly, I would like to delete a layer from the existing Geo package using python code. But ...
1
vote
0answers
71 views

Updating identify tool every time feature is selected with PyQGIS3

I want to use the "Identify Feature Tool" in code (PyQGIS3). What I've found in the internet doesn't use the tool, people usually print in console point features and ids. I also found a tool that ...
1
vote
1answer
184 views

Making automatic updated date and time field in QGIS

I wish to create a field which automatically updates with the current timestamp when edits are made to a feature. I am using QGIS 3.4 and I am testing this using a shapefile. Following @Joseph's ...
1
vote
1answer
100 views

Getting Layer Properties of QGIS on standalone appliction 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 ...
1
vote
1answer
267 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
1answer
104 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 "...
1
vote
1answer
104 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
113 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 : ...
1
vote
1answer
462 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() ...
1
vote
1answer
39 views

PyQGIS update field in line dataset when it is within a polygon

I am trying to update a field in a (Road centerline) table based on a value from another table when it is within a Polygon (Locality boundaries). Based on posts like QGIS layer.geometry.intersection()...
1
vote
0answers
152 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 (...
1
vote
1answer
111 views

Apply color ramp to (QgsSingleSymbolRenderer) Simple marker

I'm using a QgsSingleSymbolRenderer to display various points and lines etc for a Line geometry. I have a Single symbol symbology to display the last vertex as a: Line > Marker line > Marker &...
1
vote
1answer
101 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
76 views

How to rename 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 ...
1
vote
1answer
333 views

How to get the Z values of existing lineStringZ with pyqgis?

I can get the values of 3D QgsPoints with mypoint.get().z() When I iterate through a layer to get a specific polyline and then iterate through the polyline to get the start and end points- start_point ...
0
votes
1answer
52 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): #...