All Questions
1,782 questions with no upvoted or accepted answers
14
votes
1
answer
826
views
Remove reference to raster layer object PyQGIS
I am developing a plugin to load a set of raster files on QGIS. When there is a large number of files to be loaded, the main UI freezes. So I use QgsTask to move the creation of raster layers to a ...
12
votes
0
answers
2k
views
PyQgis Exporting Print Layout: "ERROR 6: The PNG driver does not support update access to existing datasets."
I am trying to export a .tif loaded into a pre-configured print layout template and further exported as .png
def openLayer(project, fp, basename, vector=True):
layer = QgsVectorLayer(fp, basename) ...
10
votes
0
answers
378
views
Defining partial or complete overlap with QgsSpatialIndex
I'm working on adding some functionality to a QGIS plugin. It currently uses a QgsSpatialIndex to efficiently compute whether the features of a vector layer intersect (potentially millions) of ...
8
votes
0
answers
534
views
QGIS contextual menu overriding
I would like to override the default contextual menu in QGIS 3 in the ToC.
I've created a class that inherit from QgsLayerTreeViewMenuProvider.
from qgis.gui import QgsLayerTreeViewMenuProvider
from ...
8
votes
0
answers
2k
views
Getting Spyder IDE to work with QGIS?
I was hoping someone could help me get Spyder working with QGIS. I am finding the python editor limiting within QGIS as I would like to debug my code, use the variable explorer, and be able to run ...
8
votes
0
answers
655
views
Setting up PyCharm CE 4 to work with PyQGIS library in Mac OS
I am trying to set up PyCharm to work with PyQGIS library. I am using PyCharm CE v4 and QGIS version 2.8 I have tried to implement the instructions of several posts like:
http://osgeo-org.1560.x6....
8
votes
1
answer
4k
views
Saving QGIS Project file (*.qgs) with PyQGIS?
I'm having trouble with QGIS (2.18.12) project files on Windows, if saved via Python command. The project file is saved via:
project = QgsProject.instance()
project.write()
The file is saved, I can ...
7
votes
0
answers
274
views
QgsProcessingLayerPostProcessorInterface only processing the last layer
I have a QgsProcessingLayerPostProcessorInterface class as shown below.
class LayerPostProcessor(QgsProcessingLayerPostProcessorInterface):
instance = None
name = ""
color1 = ...
7
votes
0
answers
1k
views
Accessing the spatial index of a layer (shapefile) with PyQGIS
I built a manual index on a shapefile, through the process "Create spatial index", which can be found in the process toolbox > general vector tools.
This process creates a persistent ...
7
votes
0
answers
143
views
Why is QGIS holding references to layers that are not in layer list
I have a QGIS project, which has about 30 layers in the layer list. I removed one of the layers from the list, saved the project, closed QGIS.
(The layer itself was from a Geopackage database, which ...
7
votes
0
answers
703
views
Writing layer to GeoPackage using PyQGIS
I have a PyQGIS script which carries out a number of operations on layers and writes the results to shapefiles. However, I understand that GeoPackages have a number of advantages (not having multiple ...
7
votes
0
answers
527
views
Programmatically Enable/disable input parameters in a QGIS Processing plugin
Is there a way to enable/disable a parameter by a checkbox in the processing interface? In my screenshot below, I would like to disable the Output Wall Aspect Raster when the Calculate wall aspect ...
7
votes
0
answers
874
views
QGIS crashes when running script from Processing Script Editor
Encountering this weird bug. I'm using QGIS 3.4.7. I am trying to write a script but it crashes when I run it from the editor. But it does not crash when run from the Processing Toolbox. Right now the ...
7
votes
0
answers
342
views
QGIS plugin external libraries in plugin’s directory
I’m developing my first QGIS plugin and I have to use two external libraries not included in the default OSGeoW64 installation: Couchdb and Pandas.
I would like to include those libraries in my ...
7
votes
0
answers
356
views
PyQGIS composed Atlas generation
I have some layers :
layer 1
layer 2
layer 3
and I have create styles for any labels layer using base rule styles and labels and I have create a template .qpt and I use atlas correct.
In my ...
7
votes
0
answers
1k
views
Import Pandas or any Python module into QGIS internal Python
(Also asked in stack overflow -
https://stackoverflow.com/questions/43244062/import-pandas-or-any-python-module-into-qgis-internal-python )
I am developing a plugin for the current LTR version of ...
7
votes
0
answers
1k
views
Gdal and module import error when creating an .exe application with pyinstaller
I’ve been struggling since three days in a row to create a windows executable application from my python application. I have managed to get results but I’m not at all satisfied with the workarounds I ...
7
votes
1
answer
1k
views
How to load the layer style from PostgreSQL with Python
I would like to write a Python macro that upon opening my QGIS project file will reload the default style for each layer from the PostgreSQL 'layer_style' table. I have had a look at the documentation ...
6
votes
0
answers
305
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 ...
6
votes
0
answers
824
views
qgis_process run script from command line
qgis_process allows us to run scripts already installed in QGIS from the command line. But is there a way to run qgis scripts not yet installed?
e.g. if I have a file script.py
from qgis.core import ...
6
votes
0
answers
154
views
Is it safe to access layer object(e.g. QgsVectorLayer) in background task(QgsTask) in QGIS3
I was confused if it's safe for developers to access QgsVectorLayer in a background task(QgsTask), like reading data from layers?
Because descriptions in PyQGIS cookbook are different with different ...
6
votes
0
answers
256
views
Catching and canceling event when I press button using PyQGIS
I develop a script. When I select a feature from layer and press delete selected, I want to execute my function that checks something for this feature, and if the checker function returns False, it ...
6
votes
0
answers
595
views
Open multiple QGIS projects via PyQGIS simultaneously in different threads
I'm writing a standalone PyQGIS application. When the method qgis() is called in a new thread, it's supposed to open a QGIS project (with one layer in it) and close it again:
from concurrent.futures....
6
votes
0
answers
404
views
Applying graduated symbol renderer only on some features using PyQGIS
I have set up a graduate symbol renderer (QGIS cookbook - Graduated Symbol Renderer), and I am now trying to make it conditionally applied to some features only, depending on one (or more) attributes. ...
6
votes
0
answers
2k
views
Exporting QGIS Atlas using PyQGIS (qgis.core)
Windows 10, PyCharm, QGIS 3.10 installed via osgeo4w (64bit).
I set up a simple QGIS composer layout with a vector layer and a WMS base map on the map layout. The vector layer contains about 10 ...
6
votes
0
answers
859
views
Create new MultiPolygon with PyQGIS
I want to create a new MultiPolygon shapefile, I tried this code
Mp_Layer = QgsVectorLayer('MultiPolygon?crs=EPSG:26191', 'layer', 'memory')
QgsProject.instance.addMapLayer(Mp_Layer)
But when I ...
6
votes
2
answers
791
views
Added raster layers with PyQGIS do not show up
I have a list ("datList") with names of raster layers which I want to add. When I add raster layers in the Python Console everything works fine:
for da in datListe:
layerDir = "C:/[...
6
votes
0
answers
838
views
QGIS 3 Value Relation current_value() not working in custom ui form
I have a custom UI form made with Qt Designer with a couple of dropdown list, so I can easily edit a layer. I use a Value Relation on those fields to filter the displayed data. The problem is the ...
6
votes
0
answers
349
views
Speeding up execution of PyQGIS algorithms
I don't understand why if I do "manually" some algorithms I get results much faster than when I insert the same in a PyQGIS code (with the same input).
This happens, for example, with the ...
6
votes
0
answers
222
views
Indexing Data in QGIS
Each time I open a my project, it starts to index and takes as long as up to 4 hours at times. My project has some layers that are stored in a remote database. How do I bypass the indexing process?
6
votes
0
answers
270
views
Defining shortcuts for QGIS plugins?
I'm writing a plugin using QGIS. I want to associate a shortcut to a procedure called "test".
The code i am using is the following :
self.shortcut = QShortcut(QKeySequence(Qt.Key_Q), self.iface....
6
votes
0
answers
225
views
Seeking list of project properties that can be written in PyQGIS?
The methods QgsProject.instance().writeEntry() and QgsProject.instance().readEntry() can be used to programmatically set project properties. According to the QGIS API reference the properties ...
6
votes
0
answers
311
views
How to handle large tables in QGIS using Python?
I'm currently writing a plugin that calculates values based on a QgsVectorLayer's attributes. To display and print the values I'm using a QgsComposerTextTableV2. I have several problems with my ...
6
votes
0
answers
2k
views
Connect to QGIS 2.6 Python Plugin function via button on custom feature form
I am trying to connect to a QGIS 2.6 Python plugin function via a custom feature form button.
On my feature form, I'm attempting to do a few things :
enable the updateButton only if the ...
6
votes
0
answers
887
views
Programmatically removing layer from QGIS composer legend without removing it from map canvas?
I am working on a QGIS Python plugin which includes automated map production. I use a series of map templates, each of which has a main map, an overview map (with a layer set different to the main ...
6
votes
1
answer
951
views
Print Composer Template produces empty map?
I have a print composer template which I'm trying to populate with different subset queries from a CSV-derived vector layer using the Python API. However, all the output PDFs contain everything except ...
5
votes
0
answers
91
views
Fully updating QGIS' GUI after changing a layer style via Python
Let's say I changed a layer's style via PyQGIS:
# load "world" easter egg layer and then:
layer = iface.activeLayer()
layer.renderer().symbol().setColor(QColor.fromRgb(50,50,250))
Result
...
5
votes
0
answers
281
views
QGIS geometry editing listener
I would like to know if it's ever possible to make a listener on geometry editing.
What I know so far is a geometryChanged signal that can be used in listening to layer when its feature's geometry is ...
5
votes
0
answers
127
views
Prevent PyQGIS from converting EPSG code to OGC URN
I'm trying to access the Sentinel Hub's WFS via PyQGIS. Here's my code:
base_url = 'https://services.sentinel-hub.com/ogc/wfs/<my_service_endpoint>?'
params = 'SRSNAME=EPSG:4326&TYPENAMES=...
5
votes
0
answers
333
views
Loading layer from PostGIS with non-unique primary key
I'm trying to load (by mean of PyQGIS) a layer from PostGIS based on query involving a inner join with a non-spatial table. When I run the query in pgAdmin I get the desired output but when I ...
5
votes
0
answers
188
views
Changing feature attribute just after adding via QgsFeatureSink
How can I access a feature and change its attribute value, I just added to a processing-output before via sink.addFeature(feature, QgsFeatureSink.FastInsert)?
Things like feature.id(specificfeatid)[...
5
votes
0
answers
184
views
Passing list as reclassify input table parameter in qgis.reclassifybytable algorithm
Following up on Save and load the classes definition table in the QGIS reclassify by table tool, I decided to run the qgis.reclassifybytable algorithm using PyQGIS to reclassify an aspect raster.
Here'...
5
votes
0
answers
3k
views
Using PyQGIS functions outside QGIS
I want to use PyQGIS function crs.isValid() in normal Python file outside of QGIS like this:
wkt = 'GEOGCS["WGS84", DATUM["WGS84", SPHEROID["WGS84", 6378137.0, 298....
5
votes
0
answers
162
views
PyQGIS: What objects need to be destroyed in a custom expression
I'm using a custom (PyQGIS) function in expressions to make little detailed minimaps around each feature in a layer, and store it in the layer (gpkg) as a png.
My code works but makes QGIS (3.12) ...
5
votes
0
answers
236
views
QGIS processing tools - saving/exporting graph
I just tried QGIS processing tools for the first time.
When using shortest path search for the first time, the algorithm is building a path graph (of course). However, the graph is never re-used. ...
5
votes
0
answers
11k
views
Getting layer reference using a feature
Using an existing feature, is there a way/method to get the layer which contains that feature?
Example:
# new empty feature which doesn't belong to any layer
new_feat = QgsFeature()
#---------------...
5
votes
0
answers
2k
views
Selecting and deselecting features with PyQGIS
I'm trying to apply the algorithms "Random Points along Lines" at the feature level. I did some PyQGIS code to iterate through the features to select each individual instance and apply the algorithm ...
5
votes
0
answers
80
views
Preserving provider of original raster layer when it is modified for another resulting raster layer?
A while ago, I asked for a method to assign new QgsRasterBlock objects to a QgsRasterDataProvider objects at Assign new QgsRasterBlock object to a QgsRasterDataProvider object. The reason was for ...
5
votes
0
answers
1k
views
QGIS3 run model with python script
I want to run a model with a python script, including the parameters, because I can't "translate" the model easily into a script.
I have tried to run a copy of the processing log after running the ...
5
votes
0
answers
563
views
QGIS (Python) crashing when trying to iterate through layers in a thread
Version: 2.18, and I cannot upgrade to 3.
I am adapting a script I found elsewhere on stackexchange which is supposed to indefinitely refresh all layers in the TOC at one-second intervals. This is ...