Questions tagged [pyqgis]

Python bindings for QGIS.

Filter by
Sorted by
Tagged with
0 votes
0 answers
6 views

Rule based renderer in PyQGIS

I tried to represent objects of one layer in a different colours depending on a specific attribute. So I came across the rule-based renderer and also already found an algorithm how to use it. (How to ...
user avatar
  • 31
1 vote
1 answer
16 views

Set linestring color by property value in PyQGIS

I have a GeoJSON layer consisting of some LineStrings. Each feature has a color property: { "type": "featureCollection", "features": [ { "...
user avatar
  • 115
1 vote
1 answer
24 views

PyQGIS - QComboboxes reciprocally exclusive

I build a QGIS plugin with 2 QComboBox. These comboboxes are populated with the same list of values. Those values come from a query to a PostgreSQL database. When I select a value in the first list, I ...
user avatar
  • 1,337
0 votes
0 answers
21 views

Using SpinBox in raster calculation

I wrote this code in QIS plugin to subtract the ex_value of a spinBox from raster if the Raster value is higher than the max value from the spin Box. but the error message is('QSpinBox' object is not ...
user avatar
1 vote
1 answer
25 views

Creation of datasource failed (OGR error, unable to open database) using PyQGIS

In my script I'm trying to save some vector layer after processing it. In the rest of the script it works fine but in this section (after the if condition) I keep getting an error, no matter in which ...
user avatar
  • 175
1 vote
1 answer
47 views

Adding attribute entries in combobox in QGIS plugin

I am developing a QGIS plugin which contains 2 combo boxes: comboBox comboBox_2 combobox lists the vector layers available, however I would like the 2nd combobox_2 to list the all names available in ...
user avatar
  • 11
0 votes
0 answers
14 views

Reading particular column values of an attribute table in PyQGIS [closed]

What is the way to creating a list using particular column entries of an attribute table by using PyQGIS?
user avatar
  • 11
1 vote
0 answers
20 views

Using TIN Interpolation algorithm in PyQGIS

I was doing Tin interpolation using pyqgis, and this algorithm has this complex param called INTERPOLATION_DATA, where I'm stuck to create a valid string by the documentation described. From what the ...
user avatar
  • 161
1 vote
1 answer
35 views

Summing up fields with field calculator in PyQGIS

I am trying to sum up the content of the fields of my attribute table that have the string _Wert in their name. I tried to do it as shown in the following algorithm. But something is wrong with my ...
user avatar
  • 31
3 votes
1 answer
86 views

Create attribute in a field based on the part of the name of a file in a folder with Python in QGIS

I have a common path (F:\Comune) where there are folders with name that corresponds to the attribute of a field of the vector Zp.gpkg called "Numero". The field "Numero" for every ...
user avatar
1 vote
1 answer
33 views

Using QGIS default Random Color Ramp in Categorized symbology using PyQGIS

Based on this code below, is it possible to use Random Color option in Symbology? layer = iface.activeLayer() field_name = 'zona_manejo' field_index = layer.fields().indexFromName(field_name) ...
user avatar
  • 631
0 votes
0 answers
22 views

Load value in QGIS form field [closed]

I would like to know if it is possible to load a value in a field when I select an option from the combobox of a QGIS form. This is my form:
user avatar
1 vote
1 answer
20 views

Extrapolate URI from a WFS connection

Purpose: to create and add a vector layer instance to the project with Python This is what is written in https://docs.qgis.org/3.22/en/docs/pyqgis_developer_cookbook/loadlayer.html#id1 to connect with ...
user avatar
2 votes
1 answer
32 views

QGIS print composer: Extract segments of layer name to text box

I'm attempting to produce a series of maps in QGIS, each showing a different layer overlaid over the same region, each with an associated different title and legend to match each layer. I'm stuck with ...
user avatar
  • 21
2 votes
1 answer
64 views

Extract URL from WMS in layertree in QGIS

I get a QGIS project with more than 60 different WMS layers. The layers are in different subgroups. Now I want to get a list of all layernames and the URL of the layer. Therefore I tried the following ...
user avatar
1 vote
1 answer
28 views

PyQgis: How do I change point layer color in red AND blue with ruled based expression?

I want to change the color of my point layer with the ruled based option so that I create blue and red dots based on an expression. Now I get only blue dots. How do I create 2 renderers with a ruled ...
user avatar
0 votes
0 answers
26 views

How can I add different layers from XML file using PYQGIS?

I have multiple xml files contains different layer. I want to write a script to find just layers that their name is street_name and city_name? How can I open these files in qgis console?
user avatar
2 votes
1 answer
33 views

setDataSource() not working with query PyQGIS 3 [closed]

uri = QgsDataSourceUri() uri.setConnection(aHost=self.db_conn.host, aPort=str(self.db_conn.port), aDatabase=self.db_conn.database, aUsername=self.db_conn.user, aPassword=self.db_conn.password) ...
user avatar
  • 161
2 votes
0 answers
39 views

Efficient way to compare fields or expressions of intersecting features: bulk-loading vs. get features one-by-one

I want to find an efficient (especially in terms of memoryusage and processing speed) method to compare intersecting features by attribute/expression. For this script I am iterating over a ...
user avatar
  • 25.7k
1 vote
0 answers
33 views

Bringing PyQGIS and PyQt into already settled Anaconda Python environment in PyCharm

I have Anaconda Python environment with different packages required for developing a QGIS plugin (including the Plugin Builder Tool etc.). (qgsdata) C:\TempDaten\_dev\QgsData>conda info ...
user avatar
  • 1
1 vote
0 answers
18 views

Variable only updated in second run even with dependency using Graphical Modeler

I try to use variables for expressions in selecting features etc. I set the variable and also add a dependency in the following block. The protocol of the run also shows that the variable is set ...
user avatar
  • 11
1 vote
1 answer
40 views

'NameError: name 'importos' is not defined' when loading GeoJSON file QGIS

I am trying to load a GeoJSON file in QGIS. But I am reaching some difficulties (I am on Mac Os). I am using the following code: import os import glob json_paths = glob.glob(r"/Users/name/...
user avatar
2 votes
0 answers
53 views

Running Python script file exported from QGIS Graphical Modeller in external terminal

For instance, I have created a simple graphical modeler which gives NDVI as an output when the NIR band and Red Band are provided: I exported the Python script using 'Export as script algorithm' in ...
user avatar
0 votes
0 answers
14 views

Using Processing Algorithm script QGIS3 outside GUI [duplicate]

I get an error when I try to use a Python script using processing algorithms. If I use the following script, the program will encounter an error. So there is no processing. import processing ...
user avatar
3 votes
2 answers
115 views

Getting Python code that QGIS analysis tools are running in background

I know I can open the Python Console to type in code, and before I know I've been able to open something in QGIS to see the code running when I do something like intersection vector analysis, though I'...
user avatar
  • 33
2 votes
1 answer
41 views

Setting default value in QGIS field using QgsEditorWidgetSetup in PyQGIS

There are many questions like this but either they propose to implement a new method to update values or describe how to set default values for fields in GUI. I'm writing a QgsProcessingAlgorithm and ...
user avatar
  • 165
3 votes
1 answer
50 views

PyQGIS get active group

In PyQGIS we can obtain the active (currently selected) layer with >>> iface.activeLayer() <QgsRasterLayer: '007' (gdal)> With a group selected this returns None (?). QgsInterface does ...
user avatar
2 votes
2 answers
42 views

Deleting all fields from attribute table in QGIS processing script

I'm writing a script in the processing script editor of QGIS and at one point i want to delete all columns of my vector layer's attribute table. I tried to do it like this: lst = list(range(0,-1)) ...
user avatar
  • 31
1 vote
1 answer
37 views

Accessing SpatiaLite tables in custom QGIS Plugin

I have a SpatiaLite database that has relational tables to link geo entities that can be reflected in QGIS as layers. To link the relations I need some custom forms where I can select these entities ...
user avatar
2 votes
0 answers
42 views

Creating custom processing tool (sibling of Batch Nominatim geocoder) in QGIS

I want to create a custom processing tool for geocoding in QGIS. It will reproduce the "Batch Nominatim geocoder" geoalgorithm, besides several things: another URL of a geocoder will be ...
user avatar
  • 1
1 vote
1 answer
77 views

Adding "Draw on canvas" option for the input box of Qgis Graphical Modeler

I have a very simple model created in Qgis Graphical Modeler. It takes polygon vector data as input and generates random points inside. What I want is to add an option to introduce input data using &...
user avatar
  • 107
5 votes
0 answers
200 views

Making layer names in legend permanent using PyQGIS

While constructing a legend in Print Layout, I modify the names of the layers just in the legend, but not in the Layers panel (works as expected). Reproducible code is at bottom. However, after I ...
user avatar
  • 9,901
0 votes
2 answers
41 views

PyQGIS generate WMS service description XML for TMS service

I am currently writing a QGIS Plugin, for which i require a WMS service description XML file for the currently selected layer (as long as it is a XYZ layer), like this one for OSM. At least i think I ...
user avatar
3 votes
2 answers
45 views

Exporting several layers as GeoPackages at same time in QGIS

I have dozens of temporary Layers. I'd like to export them all as GeoPackages, but I am unsure how to go about doing so without doing each one individually. I was reviewing this code Exporting several ...
user avatar
0 votes
0 answers
10 views

Randomly faulty Northslopes with Raster Calculation in (Py)QGIS

So I am trying to calculate all Northslopes in the Area of the .tif files. When I do it manually with the raster processing tool within QGIS it's only working sometimes, when I use the attached Python ...
user avatar
4 votes
2 answers
105 views

Finding duplicates in field depending on another field's values using PyQGIS

I need to identify/select/print the duplicate values in a field depending on the values of another one. Example: Field1 Field2 100 1 100 2 200 1 200 2 200 3 200 2 300 1 300 2 300 3 300 4 ...
user avatar
  • 304
2 votes
1 answer
94 views

Plotting two sets of XY coordinates from same vector import file

I have written a QGIS plugin that creates a .CSV file and imports it into QGIS. In it there are two pairs of XY data in columns. I have the script to import the .CSV as a layer and specify one of ...
user avatar
  • 127
0 votes
1 answer
40 views

Finding nearest point feature in different layer, from start point of line feature

I have two layers: cables (LineString), with attribute lightpost_id lightposts (Point), with attribute id For every cable I want to set the lightpost_id to to the value of id of the lightpost point, ...
user avatar
1 vote
0 answers
31 views

Can't access features using QgsProcessingUtils.mapLayerFromString() if sink output is not temporary

I am writing a QGIS processing algorithm with several sink outputs. In the processAlgorithm function, I am trying to access one of the sink outputs using QgsProcessingUtils.mapLayerFromString() after ...
user avatar
  • 11
3 votes
1 answer
56 views

Showing editor by default in QGIS Python Console

I use startup.py file in folder %AppData%\QGIS\QGIS3 to open the Python Console at QGIS start. Is there a way to also show the editor? I browsed a lot of pages in the API, but didn't find the answer. ...
user avatar
  • 284
0 votes
0 answers
22 views

Plug-in to reshape sharp edges to circular string is not working near to start/end point of polygon

I am developing a plug-in in QGIS. By using two points I am creating a circular string to reshape sharp polygon edges to round. The plugin is reshaping 3 edges perfectly but failing reshaping near ...
user avatar
0 votes
0 answers
27 views

QGIS plugin: my QT5 designed dialog has problems when used on different resolution monitors

I'm starting now to approach development of QGIS plugins, and I've made one that has a simple QDialog user interface, designed with Qt Designer (I'm on Qt v.5.12.8 and QGIS 3.24). The QDialog contains ...
user avatar
  • 136
2 votes
1 answer
49 views

Adding PostGIS mixed-geometry layers in standalone QGIS scripts the same way as QGIS GUI?

I am trying to use PyQGIS to load PostGIS layers into QGIS 3 using the code below: from qgis.core import QgsProject, QgsVectorLayer, QgsDataSourceUri, QgsApplication #init Qgis QgsApplication....
user avatar
  • 10.3k
2 votes
2 answers
54 views

"overlay_*" functions not working in PyQGIS with getFeatures() expression

I am trying to use overlay_intersects() inside an expression in order to loop through the features from a target layer that intersect with a feature having a certain "id". request_string = &...
user avatar
2 votes
1 answer
88 views

How use QGIS Geometry Checker classes in python?

I write myself plugin for QGIS with Python3 API. For my plugin logic I need write my self geometry checker because of difficult logic and different actions when I find some of geometry errors. In ...
user avatar
0 votes
1 answer
51 views

Export WFS Features as Shapefile giving Error number: (8, '') using PyQGIS

I am new to PyQGIS and trying to export a WFS Feature as a Shapefile called Test.shp. uri = r"https://www.geoportal.rlp.de/mapbender/php/wfs.php?INSPIRE=1&FEATURETYPE_ID=2939&VERSION=2.0....
user avatar
3 votes
1 answer
53 views

Calculating NDVI using QGIS Python Console

I'm going to calculate NDVI using band 4 and band 3 of Landsat 5. The code I wrote: import os, re import processing from osgeo import gdal input_B4 = r'C:\Users\test\...
user avatar
  • 447
1 vote
1 answer
35 views

How to set Folder as Parameter in PyQGIS script?

I know how to set the parameter of a folder but, not sure if I am using the right class.   I want a user to select a folder which has items inside it, to be used for processing.   When I use self....
user avatar
  • 35
3 votes
1 answer
55 views

Finding lines with length of 0.0 inside polygon with Python script in QGIS

I have a vector layer (PostGIS) with line geometries. Some of these geometries have a length of 0.0, but they have two points with the same coordinate. I want to handle this features within a python ...
user avatar
  • 163
1 vote
1 answer
25 views

Which signal emitted when the user changes the theme in layer tree using pyqgis

Which signal is emitted when the user changes the theme in layer tree using pyqgis. Using QgsMapCanvas.themeChanged doesn't work.
user avatar
  • 389

1
2 3 4 5
132