Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [pyqgis]

Python bindings for QGIS.

0
votes
0answers
9 views

Get progression bar into PyQGIS 3 standalone script

When I run a treatment inside QGIS with Processing toolbox (native algorithms) I get a progression bar : Is there a way to use this percentage inside a standalone PyQGIS script? I searched in the ...
0
votes
0answers
12 views

How can I assign colors based on attributes using Python in QGIS?

Very new to the environment. I have the .shp, .shx and .dbf files. I want to go through every element on the screen and change its color based on whether its 'Area' attribute is < 10. How can I do ...
3
votes
1answer
80 views

Custom function works in “Zoom to Features” but not “Select Features”

I'm trying to update the Using Custom Functions tutorial to QGis 3 and Python 3 and I've run into an interesting issue. With the following code I can create an expression GetUtmZone()='33N' and it ...
0
votes
1answer
45 views

PyQGIS - 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
0answers
21 views

Unable to load output layer from Python algorithm in QGIS 3

I'm building a Python algorithm for QGIS 3, to be run from the Processing Toolbox. I've finished debugging the algorithm body, which seems to work, but QGIS is unable to load its output. Here's the ...
1
vote
1answer
37 views

PyQGIS - Plugin returns error from processAlgorithm. Invalid Result

I've written a script which automatically creates a print layout and exports it. Now I'm trying to integrate the code into my plugin's code. The plugin has some existing functionality and I'm adding ...
0
votes
1answer
28 views

Installing packages into OSGeo4W64-QGIS-Python and not in Standard Python installation on Windows?

On my Windows 10 PC there are (at least) 2 Python 3.7 versions installed: a) "Standard Python 3.7 64 bit with IDLE, which I downloaded from the site python.org and installed. b) The Python 3.7 which ...
1
vote
2answers
39 views

Opening multiple attribute tables using .showAttributeTables()

I've got a question about .showAttributeTables() - i'm trying to open two attrbute tables at the end of a query (selection of lines within a polygon layer) - I thought I could simply do somthing like ...
1
vote
0answers
8 views

pyQgis snap-symbol doesn’t show

I have a script that prints coordinates on mouse klick including snapped coordinates if snap is active. The strange thing is that there’s no symbolism on the canvas that shows that you are snapping on ...
0
votes
0answers
38 views

Creation of Menu items in QGIS 3

I've got some code which adds menu items with some inactive by default. They only become active when the reverse item (to open the data) above it are triggered. I am now looking at using a loop to do ...
2
votes
3answers
40 views

KeyError but field exists (PyQGIS)

I have 10 fields in my shapefile, and I want to use Python (3.7) to access the value of one field in QGIS. When I run my code (below) I get a KeyError: '6' (index position of the field), implying ...
1
vote
0answers
21 views

Feature geometries sometimes treated as equal, sometimes not (PyQGIS)

QGIS 3.4x64 and Python 3.7 seem to sometimes treat my geometries as equal, sometimes not. I'm debugging code using a reduced dataset with 3 points. Points A and B have the same geometry, and point C ...
2
votes
1answer
52 views

Getting name of group that layer is in using PyQGIS?

I've been using the "Layer List" plugin (https://plugins.qgis.org/plugins/layerList/) that does a great job of creating a text file with all the layer in a qgs project file. I want to extend it to ...
1
vote
1answer
23 views

Multiple steps in runandload

How is it possible to perform multiple processing steps for one layer without creating additional ones? I wanted to add several fields to attribute table using qgis:fieldcalculator but every time it ...
1
vote
1answer
56 views

ImportError: No module named qgis.core on Windows 10

I am trying to execute the following code on my Windows 10 with QGIS 2.18.20. from qgis.core import * from qgis.utils import * import os, sys QgsApplication.setPrefixPath("C:/Program Files/QGIS 2.18/...
3
votes
0answers
39 views

How to test the geometry type from a list of layers and then join it with PyQGIS 3

Summarizing my problem, I'm a beginner and I'm developing a plugin that will be able to do several spatial joins. For this, it will have to separate the spatial from the non-spatial layers and do the ...
2
votes
1answer
34 views

QgsProcessingParameterString(), Store user input?

I'm adding some stuff to a QGIS plugin and trying to figure out how to work with user inputs. In this case, the user input is a string, which seems simple to work with, but I can't find an example of ...
3
votes
1answer
59 views

Adding new feature via Python in QGIS attribute table

I want to add a new feature with the Add Feature button in the Attribute Table using one line of PyQGIS. I can show the attribute table via iface.showAttributeTable(iface.activeLayer()) Is there ...
3
votes
3answers
58 views

Automatically populate r.reclass rules based on table values

In QGIS I have a raster map showing land, snow and cloud zones, having resp. pixel values 1, 2, and 3. I extracted the mean altitude values (in m) of each zone on the basis of an underlying DEM and ...
1
vote
0answers
35 views

Python script creation, intersection Points and polygons [closed]

I have these two shapefiles, one with polygon geometry and the other with point geometry, that I am working on in QGIS. I want to create a script using Python to see the intersection of points and ...
1
vote
1answer
25 views

How to get file path from vector layer object in QGIS 3.x processing framework?

Using the QGIS 3.x processing framework, given a vector layer as an input parameter: (from the default script template) def initAlgorithm(self, config=None): self.addParameter( ...
2
votes
2answers
37 views

Duplicate points and bounding box in PyQGIS?

I am trying to find all points in a vector layer that do not have a duplicate point. To do this, for each point I create a list of features that intersect its bounding box ('candidates') then check ...
4
votes
1answer
42 views

Saving layer as shapefile using PyQGIS?

Using QGIS 3.4.4, I'm trying to save a layer as shapefile with the following code: import qgis.core import os working_folder = r'C:\myFolder' fc_Prospect = os.path.join(working_folder, Equipment....
1
vote
0answers
34 views

Installing all pyqgis modules without QGIS?

I am developing a desktop program with python (tkinter, csv, qgis.core modules, etc), and the idea is to be able to install it in a client's computer. I have the pyqgis libraries because I have ...
1
vote
0answers
19 views

Qgis 3.x: Python error when adding scripts to processing toolbox

When I add a script (any script) to QGIS 3.x I get the following Python error: NameError: name 'Uitvoermap' is not defined Traceback (most recent call last): File "C:/PROGRA~1/QGIS3~1.4/apps/qgis/....
4
votes
1answer
101 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 ...
3
votes
0answers
74 views

pyqgis - geometry generator - line pattern fill

I'm trying to make a line pattern fill in QGis using the geometry generator and a python function. The code is inspired from this answer : Save line geometry as points geometry in QGIS (pyqgis) from ...
2
votes
1answer
26 views

How to permanently change attribute values using PyQGIS?

I'm trying to iterate through all the features of a layer to change the value of some of its attributes. I'm using the following code: from qgis.core import * import os working_folder = r'C:\...
4
votes
1answer
150 views
+50

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
2answers
81 views

Adding missing python packages to QGIS Plugin?

In our plugin, we dependent on some external python packages. Some are available in QGIS, some (like pandas or fiona) are not. I've written small script, which checks requirements and if something is ...
1
vote
1answer
31 views

QGIS 3 - QSettings().value(r“[…]”)[0:2] error - 'NoneType' object is not subscriptable

I'm trying to find a solution to launch a plugin from outside the QGIS console I've succeeded to call the plugin from the python console in the QGIS software but I'm now trying to do it outside of ...
1
vote
0answers
16 views

QgsVectorLayerCache causes QGIS to crash when called within def run(self)

This is in reference to the similar question regarding QgsVectorLayerCache . The original code is taken from here I'm trying to implement this method within the def run(self) method. def run(self):...
1
vote
0answers
39 views

Launch a QGIS plugin from a batchfile

After having built a QGIS 3 plugin, I'd like to know how could I call my plugin without clicking on the plugin bar of QGIS to launch it. I've tried implement a first batch file for it : REM changer ...
3
votes
1answer
56 views

QGIS 2.18: Speed up QgsFeatureRequest in Python Script

I have two input layers. The first one is a line-layer named "graph" and the second one is a point-layer named "nodes". The "graph"-layer: The graph layer holds 177350 line features which are ...
1
vote
1answer
28 views

Getting pyqgis geometry() into PostGIS database via psycopg2 - Python 3.7 QGIS 3

Using pyqgis in a QGIS 3 Plugin, I can get features from a layer and geometry from features. Is there a way to pass the geometry into psycopg2 so that it will work in PostGIS? I did find the PPyGIS ...
2
votes
2answers
40 views

PyQGIS - Managing print layouts

I'm struggling to understand how to manage print layouts using python for QGIS. For example, I am starting with Zero exisiting print layouts in my layout manager. I create a new print layout and add a ...
1
vote
1answer
38 views

Adding feature class within file geodatabase in QGIS with Python?

I've been using ArcPy for quite a while, but I'm now trying to learn how to create geospatial workflows using PyQGIS. I'm starting with simple things, like adding a layer to the map. I'm trying with ...
0
votes
0answers
16 views

QGIS 2.18 Workaround minidump in C [duplicate]

I have an input POINT-layer with lots of features in it. What I am trying to do is to calculate the azimuth for two features. And the way I am doing this is the following: geomFrom = (...).geometry() ...
1
vote
0answers
22 views

Eventfilter on MapCanvas

I'm trying to capture MouseClick events on the QgsMapCanvas. The goal is to intercept the right mouse button and display a custom context menu. If the right mouse button is pressed with a modifier key ...
2
votes
2answers
37 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
0answers
36 views

QGIS BadLayerHandler - setDataProvider()

I've made a bit of a plugin to handle badlayers (I'm aware that Change datasource plugin had something for this but the code appears to have been removed now?). I've followed the advice provided in ...
1
vote
1answer
56 views

Getting log message from QGIS processing framework?

I run Python processing algorithms externally, and I want to get the log output I see when I run it from the QGIS 3 GUI at the log tab as shown in the screenshot: I want to get the full grey log ...
1
vote
1answer
44 views

Connecting ordered MultiPoint features with lines/arrows

I'm working through an XY problem, with the end goal of effectively visualising data representing different journeys. Given I have ordered data of the various positions (each with a time stamp) along ...
1
vote
1answer
102 views

Applying categorized render to polygons

I'm trying to apply a color ramp on a categorized render in QGIS 3.4 (via the Python console). I started by adapting the solution for a catagorized symbol layer - to QGIS 3.4 but this applies a ...
1
vote
0answers
20 views

Using QgsVectorFileWriter to write several layers on same Spatialite file?

Does anybody knows how to write several QGIS layers on a same spatialite file using QgsVectorFileWriter or another way to add several same layers type to a Spatiallite specific table using ...
0
votes
2answers
231 views

Loading vector layer in Python console?

I am trying to load a vector file to QGIS Python console. v_layer = iface.addVectorLayer("G://Consultancy\Data\Transfer\Bodhi (Louis) Gorringe\QGIS\Shapefiles\Biological Shapefiles\Seabirds\At sea ...
1
vote
0answers
35 views

Modifying style (line width/color) of vector layer in PyQGIS?

I'm currently updating some python code from QGIS 2.18 to QGIS 3.4 in 2.18 i used the following code : #First off I created a virtual layer using an sql query here vlayer = QgsVectorLayer( "?query=....
0
votes
1answer
37 views

Geometric networks (networkx) in PyQGIS

I'm working with code from the Disconnected Islands plugin in QGIS x64 and Python 3. Normally, the plugin uses networkx to create a geometric network and ends by writing the FID of features with no ...
1
vote
1answer
28 views

How to use SAGA Raster processing in processing scripts (QGIS3)

I want to make a processing script which uses the saga:inversedistanceweightedinterpolation algorithm (Interpolating a point layer - magnetometry measurements - to a raster. The SAGA runs so far but ...
2
votes
1answer
53 views

PyQGIS - Print Layout Legend. setLegendFilterByMapEnabled()

I'm creating a legend in my print composer and only want "visible", or active, layers shown in the legend. This means I want only layers with the box checked in my layers panel. Here is how I create ...