All Questions
7,900 questions
1
vote
1
answer
84
views
Loading results of split vector tool into group using PyQGIS
I try to write a script to automatically merge some input layers (all of the same structure) of a GeoPackage into one, then split it by a specific attribute and save the output as GeoPackages to a ...
1
vote
1
answer
165
views
Creating group or menu of multiple plugins in QGIS
I will create a bundle of plugins (one is already created). Instead of storing each plugin loosely as a single plugin, I would like to have them stored in a group, similar to a menu like this:
How ...
0
votes
1
answer
58
views
Sublayer from a Geopackage file shows as geometrytype 0 (unknown), but it contains points. It doesn't show the points either. How do I fix this?
I have geopackage file that contains sublayers that containts points. I want to access the sublayer and create a new file of it. Despite the points it shows the geometry type as unknown. The points ...
1
vote
1
answer
49
views
Optional argument has wrong value when used with action trigger
QGIS 3.36.2, Python 3.12.3
I've got a regular action that is part of a toolbar and that calls a function when pressed, which uses an optional argument with a default value:
class MyClass:
def ...
0
votes
0
answers
27
views
Reduce raster file size during QGIS Python script processing
I wrote a Python script based for QGIS that is using the raster calculator to create a new raster based on two existing raster inputs. My problem is, that each output file is 35 GiB and I do have not ...
0
votes
1
answer
69
views
Creating QGIS projects with iteration using PyQGIS - Problem with the location of layers added
In the following PyQGIS script, I iterate through each shapefile in input_directory, where each file represents an individual prefecture. To manage project isolation and ensure clean operations, I ...
0
votes
1
answer
99
views
QGIS Python Get and layout item's Uuid
I am working on synchronising the view extents of maps on layouts.
I can do this using .layoutByName, .itemById, .extent and then .setExtent to get the Map I want from the right layout then find its ...
2
votes
1
answer
101
views
Custom panel is created but does not display properly in custom plug-in
I am using the answer to Adding custom panel to QGIS to add a custom panel to my existing custom QGIS plug-in. So far, the plug-in only uses modal dialogues. I try to show the widget from the callback ...
1
vote
1
answer
148
views
Deleting GeoPackage vector layers and releasing open file handles with PyQGIS
On Windows 11 I have a PyQGIS script that creates layers from gpkg files. This all works perfectly fine.
I want to delete these layers, recreate the gpkg files and reload them as layers again and this ...
1
vote
0
answers
61
views
Why PyQGIS is not calculating the square root correctly in this expression
I have a shapefile with ~100 fields, the first ~50 fields are motion towards the east, and the last ~50 are motion towards the north. There are 50 fields because each represents a date. I want to ...
0
votes
1
answer
89
views
How to add OpenStreetMap layer as bottom layer via QGIS processing script
I want to add an OpenStreetMap layer as the bottom layer of my project via a script. This works from the console:
project = QgsProject.instance()
root = project.layerTreeRoot()
all_layers = root....
3
votes
1
answer
124
views
Attach functions to QGIS processing algorithms
I am trying to find a way to attach a function to run whenever any processing algorithm either starts, succeeds or fails in the main QGIS application.
The functions should be attached when a plugin is ...
0
votes
0
answers
60
views
How to keep attributes after a clipping operation in PyQGIS?
I'm trying to do a spatial clipping operation between 2 point layers, representing buildings and earthquakes, and a buffer area created by the user. The problem is that after operation, all attributes ...
1
vote
1
answer
63
views
Layers corrupted after saving, closing and opening of QGIS project with PyQGIS
Using a Python script, I create a layer from a CSV file and then write it out to a gpkg file.
I then create a group in the layer tree, load it in the gpkg file and add it as a child of the group. This ...
0
votes
0
answers
32
views
Stretch Singleband Pseudocolor with Cumulative Cut
I'd like to use the QGIS Python Console to stretch a raster layer that's already symbolized as Singleband Pseudocolor. I can push either button, , but I'd rather script it for a layer(s). The only ...
0
votes
0
answers
39
views
Incorrect display of map themes
I have created layer styles and wanted to create specific map themes with another script. Unfortunately, the styles are not loading properly and the map themes are faulty and sometimes not selectable.
...
0
votes
1
answer
131
views
QGIS script keeps crashing
The following is the only the beginning of my script but this is where the problem is located. It runs fine the first time, but break the second time I try running it. I am running the script directly ...
0
votes
0
answers
77
views
How to add a north arrow using stock QGIS images in Python
I am trying to add a north arrow to a map (QgsPrintLayout) using PyQGIS. The closest thing I could find is from this GIS.SE question (Adding north arrow using PyQGIS):
north = QgsLayoutItemPicture(...
2
votes
0
answers
47
views
Assigning band name when using QgsRasterFileWriter/QgsRasterDataProvider in PyQGIS
I want to write binary data to a new raster file using PyQGIS QgsRasterFileWriter. Everything works fine but I would like to also assign a specific band name to the written raster band. How can I do ...
1
vote
0
answers
47
views
Adding data-driven command in PyQGIS
I want add to my code line which add option placed label based to data. I would use string in_mask(0) as string, because i want hide labels under the mask.
layer = QgsProject().instance()....
0
votes
0
answers
51
views
QGIS/GDAL warp(reproject) throws 'ERROR 5: dfMax should be strictly greater than dfMin' when run in Python script
I have ~ 150 .xyz-files (DEMs) which I try to reproject. When I reproject them within QGIS via raster -- > warp everything works fine. First I tried the batch processing option with warp(reproject)...
0
votes
0
answers
232
views
Issue with Google Earth Engine Plugin in QGIS
I am trying to resolve an error from using the Python console on QGIS. I have QGIS version
QGIS version 3.34.4-Prizren on my linux Ubuntu 22.04.4 LTS, Codename-Jammy. Then I successfully installed ...
1
vote
0
answers
33
views
QGIS Snapping on invisible(by scale) features [closed]
I using QGIS 3.34 (but in 3.36 same problem).
When I turn on snapping, it snaps to layers, which are invisible by scale. But it isn't snapping to features which are invisible by rules in style (and ...
2
votes
1
answer
63
views
Deactivating the render checkbox of status bar with PyQGIS
I was wondering whether it is possible to activate/deactivate the Render function of the QGIS canvas:
I searched everywhere online but I found nothing even about the function itself.
0
votes
0
answers
40
views
PyQGIS capture screen around mouse pointer
I'm developing a PyQGIS plugin, that shows different terrain details for the area hovered by the mouse pointer. I'd like to implement a screenshot feature that would allow the user to screenshot the ...
1
vote
1
answer
108
views
import module qgis.core in standalone script with pyqgis without running bat before with environment?
To run a python script (example file "standalone.py") with module qgis.core I have to use a specific bat file (that call the py file!) with the following environment!
"rem Call ...
0
votes
1
answer
93
views
QgsRasterBandComboBox/ ComboBox unable to process raster calculator
I'm creating a plugin to calculate NDVI and NDWI indices in QGIS v3.36.2. I have successfully created the GUI as below and successfully loaded the layers and bands of the layers. The data I am using ...
0
votes
1
answer
173
views
How to use a python virtual environment on QGIS?
I'm currently developing a QGIS plugin and I want to use pydantic in this plugin.
I'm currently using python 3.12 and QGIS 3.36.
It is not recommended to install package in the python system ...
1
vote
1
answer
46
views
I can't update any attribute values in PyQGIS
I've been using PyQGIS for a few of weeks. I'd write a script which shows all earthshakes responding to given parameters, so I wrote this code:
from PyQt5.QtGui import *
from PyQt5.QtCore import ...
2
votes
1
answer
129
views
TypeError when using QgsRasterFileWriter.writeRaster in PyQGIS
In the QGIS 3.36.1 Python Console, I'm trying to create an output raster so I can write pixel values sampled from another raster.
output_raster_path = r'D:\Output Raster.tif'
output_raster = ...
2
votes
2
answers
221
views
Applying if-condition for NULL values in QGIS Python Console
I want to create Excel synoptics from shapefiles or PostgreSQL databases.
To know where the start and end points are, I think I need to create logical identifiers for all my entities instead of a ...
1
vote
1
answer
341
views
MultiPolygon to Polygon in Python [closed]
I need to change geotype from MultiPolygon to Polygon. Most of the original features are Polygon, but are automatically imported through API as MultiPolygon. How can I change all the types ...
0
votes
0
answers
121
views
Issue with custom QGIS process algorithm
I have a written a custom processing algorithm which iterates features within one vector layer and eliminates polygons in the second that are within each feature from the first under a specific size. ...
1
vote
0
answers
54
views
Saving QgsSymbol as image with specific DPI using PyQGIS [closed]
I want to save QgsMarkerSymbol as a high dpi image (png) invoking the asImage method and then save its result (QImage) in a local directory. I tried using a custom QgsRenderContext object like in the ...
1
vote
0
answers
90
views
splitGeometry does not produce two geometries with PyQGIS [closed]
I am working on a script that checks features for (rough) rectangularity and splits them if they are not.
If I correctly understand the splitGeometry method, it should produce two geometries if ...
0
votes
1
answer
113
views
Annotations on QGIS map in Python
I would like to use the create a text annotation at point tool on QGIS from a python code. The goal is to use it in a plugin I'm creating so that the user can display text on the map.
The problem is ...
1
vote
1
answer
49
views
Using 'showProjectPropertiesDialog' method of QgsInterface to open 'Project Variables' page
I'm trying to open the Project Properties window on the "Variables" page, using pyqgis.
The docs mention that a currentPage string parameter can be passed to QgsInterface....
2
votes
1
answer
85
views
Attachments of ArcGIS Rest Server Layer in QGIS
Current Setup:
I have a connection to our ArcGIS Enterprise Portal (on-prem) using the Add ArcGIS Server Layer connection in QGIS. I have created an Desktop Application Item in the portal and I can ...
1
vote
1
answer
155
views
Smoothing with PyQGIS
I want to smooth a polygon in QGIS. The smooth tool is not sufficient. I need much stronger smoothing. In the picture below you can see my current polygon after smoothing it with the QGIS smooth tool (...
1
vote
1
answer
106
views
Using PyQGIS zoomToSelected(...) in QGIS Python processing script freezes map canvas
I am currently struggling with the zoomToSelected(...) function in my QGIS Python processing script.
Users should select a city district via the GUI and then the tool should zoom to this feature and ...
0
votes
1
answer
73
views
How do I speed up selection of a large number of features
I'm looking for ways to speed up selection of a large number of features (10k+) from a list of attribute values.
I'm developing a plugin to trace a pipe network, and select the tranversed pipes. The ...
3
votes
1
answer
161
views
Using QgsProcessingParameterEnum in QGIS Python processing script
I am currently working on a processing script for QGIS. In the function def initAlgorithm() I am defining several parameters. One of the parameters is using QgsProcessingParameterEnum with a pre-...
1
vote
1
answer
39
views
How to make PyQGIS to return 4 raster subdivisions calculated by inequations
I've been making in Raster Calculator, one by one, for every Return Period (2, 5, 10, 50, etc.) different sub-rasters of 4 sections of water depth, it's very tedious and I know there is a faster way ...
0
votes
1
answer
70
views
Changing project CRS using PyQGIS not working
I have a fairly long PyQGIS script running in the Python Console Editor in QGIS. The script creates 5 layers:
3 layers derived from DEM data, generally in CRS EPSG:28356 (GDA94 / MGA Zone 56), and
2 ...
1
vote
1
answer
70
views
Reset style in QGIS3
I try to erase, make blank, or no-style layer, as you want.
I don't find any option in QGIS, so I try Python but
from qgis.core import *
import qgis.utils
layer=qgis.utils.iface.activeLayer()
layer....
0
votes
0
answers
29
views
Why does PyQGIS start saying roo.children() is empty after a while?
I am working on a small extension to the QgsProject Class.
import sys
sys.path.append("C:/Program Files/QGIS 3.34.6/apps/qgis-ltr/python")
from qgis.core import (QgsApplication, QgsProject, ...
2
votes
1
answer
145
views
"Could not load source layer for INPUT: memory: not found" error in Processing Script using PyQGIS
I have a workflow where a raster should be polygonized and afterwards simplified. The simplified vector should be saved as a shapefile. I am using the template script from QGIS to create a processing ...
0
votes
1
answer
57
views
How do I enable linting in PyQGIS modules on MacOS?
I'm running QGIS 3.36 on a MacBook Pro M1. I would like to work on a processing script, but of course I would like to do this in my IDE (VS Code) not the built-in console.
I have QGIS installed in ...
0
votes
1
answer
65
views
GRASS r.viewshed not working with elevation? - PyQGIS
I'm making a QGIS plugin that uses grass:r.viewshed to analyze the area of terrain visible from different points. However, I've noticed, that when using a viewpoint where the elevation between the ...
2
votes
0
answers
57
views
Managing amount of DB connections of QgsDataSourceUri with PyQGIS
So basically I have a simple code that adds vector layers to the QGIS project from PostgreSQL.
self.uri = QgsDataSourceUri()
self.uri.setConnection(
self.host,
self.port,
self.db,
self....