Questions tagged [pyqgis]

Python bindings for QGIS.

Filter by
Sorted by
Tagged with
1
vote
1answer
8 views

PyQGIS change stroke width of polygon with categorized symbology

I have a polygon layer with categorized symbology. I want to change the stroke width of all the categories without touching the categories or colours. Here is the script I have after looking a similar ...
0
votes
0answers
10 views

PyQGIS: Raster Calculator in processing scripts crashes

I am currently writing a processing script for QGIS that goes as follows: Takes in a digital elevation model (DEM) tiff file, a shapefile mask of the study area, and a slope cutoff value in percent ...
0
votes
1answer
28 views

Merging group of point layers with QGIS Python console [closed]

I have two groups of layers as shown in this image, and I want to merge layers of each group separately with a Python script. I have tried the following script but it's not complete I think root = ...
0
votes
0answers
12 views

AttributeError: module 'processing' has no attribute 'runAndLoadResults'

I'm trying to run QGIS standalone app using processing.runAndLoadResults and keep getting this error: AttributeError: module 'processing' has no attribute 'runAndLoadResults' I'm working on MacOS i ...
0
votes
0answers
17 views

Upstream and downstream segments from a point (R) [closed]

I have a question regarding the use of sfnetworks for river/stream analysis. I have a river network consisting of around 4155 segments of 100 m each. I have a DEM for the catchment and I'm trying to ...
1
vote
1answer
27 views

Adding new provider to QgsProviderRegistry.instance().providerList() using PyQGIS

I'm trying to get vector layer from arcgisfeatureserver in a standalone app, didn't work, so I checked what providers I got on PyCharm: ['gdal', 'memory', 'mesh_memory', 'ogr', 'vectortile'] While in ...
2
votes
1answer
60 views

Looking for manual on how to properly setup standalone PyQGIS without GUI

My goal is to create a standalone PyQGIS script that is able to run QgsProcessingAlgorithm scripts without GUI. My setup runs on Windows and my IDE of choice is VS Code. I've followed the Windows ...
3
votes
1answer
95 views

Getting the value of OSM tag contained in the 'other_tag' field using PyQGIS

I got my data from OSM and a lot of metadata is stored in field "other_tags", which is in itself an HSTORE key/value field. For instance, my "other_tags" contains a key voltage ...
2
votes
2answers
66 views

PyQGIS outside GUI: module 'qgis.processing' has no attribute 'run'

When trying to use processing.run() from a standalone (no GUI) mode, I get the following error: module 'qgis.processing' has no attribute 'run' in the following trivial example: from qgis import ...
1
vote
1answer
39 views

PyQGIS custom application: no GUI appearing

I'm following the following instructions on getting Python to work with QGIS, outside the QGIS GUI itself: Using PyQGIS in custom applications. But for some reason the GUI is not appearing, yet the ...
2
votes
1answer
53 views

Updating Timestamp values in QGIS

As it is seen in the picture, I have the attributes table which shows the random extracted routes from Istanbul highway map and points on it. Points were uniformly distributed through 2000 random ...
0
votes
1answer
56 views

Copying features from one layer into another in PyQGIS using addFeatures

I am writing a plugin for QGIS 3.8 I have two layers, drop_layer and Fibre Cable. I want to copy all features from the drop_layer and append to Fibre cable layer. I use a function to create ...
2
votes
1answer
29 views

Modifying Timestamps in QGIS

As it is seen in the picture, I have the attributes table which shows the random extracted routes from Istanbul highway map and points on it. Points are uniformly distributed through 2000 random ...
6
votes
1answer
127 views

Selecting layers in group using PyQGIS

This script is applied to all layers on the TOC, and I want to improve it to apply only to layers of a specific group # Create an empty table in memory and add fields newtable = QgsVectorLayer("...
5
votes
1answer
28 views

Disabling automatic selection in QgsMapLayerComboBox

I build a plugin. It has a lot of comboboxes (QgsMapLayerComboBox). They are all empty when no project is loaded. When I open a project in QGIS, a layer is automatically shown in all comboboxes. All ...
0
votes
0answers
42 views

Using VS Code as an IDE to write and test scripts [closed]

I've been experimenting with running scripts inside QGIS itself, but unfortunately its interface is too buggy for me to work comfortably with. It's hard to get logging and step-by-step debugging and ...
0
votes
0answers
37 views

Improve the Python code used to open external files, if any, through the QGIS actions

Working environment : Windows 10 and QGIS 3.10.14 LTR (standalone old repository) Problem : in a shape file of points, representing signals, the column "Code" of the attributes contains the ...
-1
votes
0answers
37 views

Adding the output layers to a new group using Python [closed]

How can I edit the following script to add the output layers to a new group with a specific name? root = QgsProject.instance().layerTreeRoot() for child in root.children(): if isinstance(child, ...
3
votes
2answers
90 views

Get the bounding box for a QGIS point symbol

I'm looking to do some advanced label blocking for point features, based on the bounds of the symbol, rather than the point itself. It looks like I should be able to derive this from the ...
-1
votes
1answer
30 views

Processing script [closed]

This script runs on only one reference layer and I want it to iterate over all layers in group 1 as a reference layer and name each output layer with the name of its corresponding reference layer and ...
3
votes
1answer
48 views

Developing QGIS plugin: AttributeError: object has no attribute

I was tasked with making a small plugin for QGIS or add a small functionality to an existing one. What I am trying to do is take the "geocode with web service" from the plugin MMQGIS and add ...
0
votes
0answers
28 views

Code Attempt for the Problem [closed]

I am working on a QGIS file in which I have to count the number of neighboring municipalities with the same attribute and find out the number of municipalities with the same attribute within 10 mile ...
3
votes
1answer
24 views

Export Project to DXF dialog using Python

I'm trying to run 'Export Project to DXF' in QGIS using the Python console. The intention is to export multiple vector layers, as defined by a Theme Visibility State, in the same way as if you ...
1
vote
1answer
34 views

For loop to buffer shapefile at multiple distances, add each to the layers window, style & save to geopackage; PyQGIS

Can someone help me straighten this code out. I want to create three buffers, at 100, 250 and 500m respectively and add these to the contents table. I've tried creating a for loop but not having ...
7
votes
1answer
90 views

What is signal when specifying the CRS of a layer using PyQGIS?

What is the signal when the CRS of a layer changes? I tried QgsProject.instance().crsChanged, but this is a signal that happens when the project CRS changes.
1
vote
1answer
30 views

"An error has occurred while executing python code" on QGIS startup (3.16.15)

I had installed QGIS 3.16.15 through OSGeo installation package and began receiving this error message when starting QGIS. I completely uninstalled using the OSGeo advanced installation package, and ...
4
votes
1answer
81 views

Unable to save my temporary layer

I am getting the following error while saving my temporary layer. Traceback (most recent call last): File "C:\PROGRA~1\QGIS31~1.14\apps\Python39\lib\code.py", line 90, in runcode exec(...
4
votes
2answers
73 views

Running the GRASS algorithm in standalone Python code using the PyQGIS processing module

What is the right way to import GRASS algorithms for a standalone Python script? I tried the solutions (solution1, solution2), but they didn't help me. Here's the code that doesn't import GRASS ...
4
votes
1answer
32 views

Unable to get the geometry of temporary layer created from selected features using PyQGIS

I need a temporary layer with the geometry created from selected features for a processing tool. The temporary layer is created but the geometry is missing. The attribute table is blank. But when I ...
7
votes
1answer
83 views

Sorting layer order in QGIS based on mixed string/numerical layer names

In QGIS, is there a way to automatically order the layers in the Layers Panel? I'm looking to sort 50 layers, output of a Split vector layer operation (see here) in a predefined order that is not ...
4
votes
1answer
59 views

QgsFileWidget mandatory field in QWizard issue

I'm trying to create a mandatory QgsFileWidget in a QWizard form for a plugin but the result is a Next button that doesn't get active when I choose the path to save the project. Here is the snippet of ...
1
vote
2answers
101 views

unsupported operand type(s) for +: 'int' and 'QVariant'

Type error :unsupported operand type(s) for +: 'int' and 'QVariant' Traceback (most recent call last): ,line 260, in rac s=s+ar Code : def rac(): cur_prov = self.dlg.comboBox_2.currentText() ...
3
votes
2answers
91 views

Adding double typed PyQGIS vector attributes to layer

I am trying to create a new vector memory layer with attribute data populated as follows and cannot figure out why it works with integer or string typed data but silently does not populate any rows ...
3
votes
4answers
107 views

QgsVectorLayer selected Features sort/order by Attribute

In a standalone application, I have a Layer to which I select some features. Then I need to do an iteration, and I need it to be done in the order of a value of a field / attribute (In my example ...
2
votes
1answer
44 views

PyQGIS Legend doesn't update with renderer

I am using QGIS 3.22.2. I am relatively new to QGIS and have been trying to automate part of a workflow, including changing the rendering of a raster. Following the PyQGIS cookbook, I have this code: ...
0
votes
0answers
29 views

Loading an existing virtual layer in Python

I have a virtual layer that I have created using the virtual layer creation tools provided by QGIS. Is there a way to load this layer in Python using QgsVectorLayer for instance? The vector layer ...
2
votes
1answer
23 views

QGIS linestring length as meters from degrees(map unit)

I wrote a code that gives the line string length as degrees but I need the unit as meters. I can't convert it to meters from degree. layer = iface.activeLayer() for i in layer.getFeatures(): geom ...
6
votes
1answer
95 views

First added layer loses its symbology when adding the same layer twice but with different names using PYQGIS QgsProject.instance().layerTreeRoot()

I’m trying to insert the same layer from a GPKG several times to the same QGIS project. I’d like to give it different names first as well as symbology and filters afterwards. The code below works for ...
0
votes
0answers
16 views

Loading PostgreSQL table to QGIS using Psycopg2 and PyQGIS

I am creating a plugin that allows the user to export multiple tables from a PostgreSQL database to QGIS, for this I am using psycopg2. So far, my code allows me to: Connect to the database. Get the ...
3
votes
1answer
43 views

Prevent custom Processing Algorithm from returning output on error

In my script I make a copy of input layer and perform some actions on it. I can't figure out how to stop QGIS from returning the output layer on error. I've tried returning nothing, but if parameter ...
3
votes
1answer
61 views

Creating arc with start, end, centre and radius using PyQGIS

I am trying to create some polygons where some of the sections correspond to curves/arcs. I have been provided with start point, end point, centre point, radius and direction (clockwise/ anti-...
3
votes
0answers
89 views

QgsDefaultValue depending on another default value doesn't update

I set the default value of two fields in the same table as follows: idx = layer.fields().indexFromName('FieldA') layerLandwirt.setDefaultValueDefinition(idx, QgsDefaultValue('$area',True)) idx = layer....
1
vote
1answer
31 views

Push button execution not returning any messages in the log

I need to work with some layers and provide output in the form of an Excel file. I have applied a push button in my QT tool design. I have also defined function which is supposed to work after I press ...
1
vote
1answer
25 views

Collapsing legend in ToC via PyQGIS

I am creating QGIS simple plugin which adds and set styles. It works like a charm, however i want to collapse all legends(categories) from styles in given layer i tried layer....
2
votes
1answer
25 views

QgsLayerTreeNode ignores expansion calls

I'm developing a Python plugin for QGIS. My goal is to add a layer group and then add a vector layer to it. The group is collapsed by default, and I'd like to expand it. But the setExpanded() method ...
0
votes
1answer
40 views

Copy a Geopackage to another folder using PYQGIS

I try to copy a GPKG to another folder. The result is the correct named copied GPKG but there is only one layer in the copy. It’s the layer with the same name as the GPKG. The other features (1x ...
0
votes
1answer
33 views

Point geometry intersects line geometry not working in PyQGIS

I have two geometries, one is Line Other one is Point. I tried find intersects between features QgsGeometry(point).intersects(QgsGeometry(line)) I have two cases: case1: if point placed on line ...
1
vote
2answers
49 views

Adding and filtering layer with map canvas extent using PyQGIS

I'm creating a small QGIS3.16 plugin with PyQGIS. I'd want to add a vector (PostGIS) layer to QGIS, and immediately filter it with the QGIS canvas extent. I found the QgsFeatureRequest(rectangle:...
1
vote
0answers
24 views

Renaming layer raster by overlay vector using PyQGIS [closed]

I split my raster .tiff into several rasters using a vector mask. Now I am wanting to rename those rasters by the id of the polygon used to split. How do I rename each raster by the id of the overlay ...
2
votes
2answers
41 views

Connecting QgsCheckableComboBox Qt Signal

I tried to connect Qt signal of QgsCheckableComboBox when checkedItemsChanged. I tried below: def showEvent(self, event): print("show event") self.loadLayersToCombox() self....

1
2 3 4 5
126