Questions tagged [pyqgis]

Python bindings for QGIS.

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

Make a Table with fields from different layer groups using PyQGIS [closed]

I have 3 groups, each group consists of 10 layers, layer names are the same in the 3 groups but with different attributes. and I want to make a table of 4 fields: layer names, layer lengths of group (...
0
votes
0answers
6 views

Coordinate transformation of QgsMeshLayer programatically?

I'm using the MDAL provider to load NetCDF data as a mesh layer in QGIS (3.20). The CRS metadata I wrote for the files doesn't seem to translate to QGIS, so I tried to make use of the ...
0
votes
0answers
20 views

I am facing an error in QGIS with the name "An error has occurred while executing Python code: "

The error is caused by Update tables in a plugin named MOLUSCE.
0
votes
0answers
32 views

Export QGIS layout as georeferenced PNG image with PyQGIS

I am using PyQGIS to export a map layout like this exporter = QgsLayoutExporter(layout) settings = exporter.ImageExportSettings() settings.dpi = 100 path = 'C:/data/test1.png' exporter.exportToImage(...
1
vote
1answer
23 views

Nested for: Outer for doesn't iterate

I wrote a code with a for nested inside another for. When I execute the code, the outer for starts with the first feature, runs as expected, then gets in the second for, runs it as expected, but then ...
1
vote
1answer
27 views

Access to features in PyQGIS loop

I have a point shapefile and I want to calculate the radius of the circle passing through three consecutive point and append it to the line that passing through two consecutive points. For this, I'm ...
0
votes
1answer
15 views

Scale Factors application not working on GEE PyQGIS

I'm trying to load some Lansadt 7 Collection 2 images on a QGIS project trought the following script: import ee from ee_plugin import Map ecorregiones = ee.FeatureCollection('users/paullcfias/...
0
votes
0answers
28 views

Georeferencing PNG image by GDAL in QGIS

I am not familiar with GDAL so far. Thereby I don't know how to start. By knowing the problem from the question below: Georeferencing PNG image in QGIS when the coordinates of image corners are known ...
0
votes
2answers
50 views

Add Today's Date to Attribute table using PyQGIS

I have the following script to merge a group of layers, and I want to edit the script to add a field containing today's date in the attribute table and also delete some fields by their names? root = ...
0
votes
0answers
24 views

Adding feature count of layers in table using PyQGIS

I have a group of layers and I want to make a table of two columns(Layer name, feature count) for this group, I tried the following script but it shows the same number for all layers. Can anyone tell ...
2
votes
1answer
49 views

Changing stroke width of polygon with categorized symbology using PyQGIS

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 ...
1
vote
0answers
25 views

Raster Calculator in processing scripts crashes using PyQGIS

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
0answers
36 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
1answer
20 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
18 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
31 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
64 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
2answers
98 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
70 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
78 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
57 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
30 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
128 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
43 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
40 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
49 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
25 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
35 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
92 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
31 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
82 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
103 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
92 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
45 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 ...

1
2 3 4 5
127