Questions tagged [pyqgis]

Python bindings for QGIS.

1,432 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
13 votes
0 answers
535 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 ...
user avatar
  • 136
11 votes
0 answers
360 views

Multithreaded DB connection for QGIS plugin

I am using QGIS 2.18.21 and PostgreSQL 9.6. on a Windows 8 machine. I am trying to do processing of a certain database task in the background, and I want the user to be able to continue to work in ...
user avatar
10 votes
0 answers
533 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) ...
user avatar
10 votes
0 answers
322 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 ...
user avatar
9 votes
0 answers
439 views

QgsRubberBand Move Event

I have created a QgsRubberBand which copies feature from layer. I need to be able visually move this rubberband on mouse event 'move'. Actually same visualisation like during self.iface....
user avatar
8 votes
0 answers
1k 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 ...
user avatar
  • 81
8 votes
0 answers
612 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....
user avatar
  • 221
7 votes
0 answers
101 views

QgsProcessingLayerPostProcessorInterface only processing the last layer

I have a QgsProcessingLayerPostProcessorInterface class as shown below. class LayerPostProcessor(QgsProcessingLayerPostProcessorInterface): instance = None name = "" color1 = ...
user avatar
  • 1,385
7 votes
0 answers
107 views

What does context mean in PyQGIS?

When writing PyQGIS scripts, especially processing script and expression function, I come across the term context. I use it, but I don't know what all contexts mean actually. There are also Qgs***...
user avatar
7 votes
0 answers
338 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 ...
user avatar
  • 1,344
7 votes
0 answers
208 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 ...
user avatar
  • 463
7 votes
1 answer
219 views

QGIS 3.6 and QGIS 3.10 report different geometry types for the same shapefile

I used QGIS 3.6.3 to create a polyline shapefile, and the program reported the polyline as LineStringZM. When I opened the same shape file in QGIS 3.10.3-2, the polyline was reported as ...
user avatar
  • 143
7 votes
0 answers
584 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 ...
user avatar
  • 537
7 votes
0 answers
265 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 ...
user avatar
7 votes
0 answers
334 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 ...
user avatar
  • 1,023
7 votes
0 answers
842 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 ...
user avatar
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 ...
user avatar
  • 2,616
7 votes
2 answers
429 views

Multi-field labeling of shapefile with PyQGIS

I wrote the following code in order to draw the line labels with multiple fields. However, the label do not appear automatically in QGIS and I have to switch the "Layer Properties/Labels", ...
user avatar
  • 791
6 votes
0 answers
147 views

Adding a fixed table to layout in QGIS

I wonder how to add a fixed table into QGIS layout. I've tried this solution but it doesn't work : model = MyOwnQgsFeatureFilterModel(layout) tableEnsemble = QgsLayoutFrame(layout, model) ...
user avatar
6 votes
0 answers
186 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 ...
user avatar
  • 2,113
6 votes
0 answers
97 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 ...
user avatar
6 votes
0 answers
70 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 ...
user avatar
  • 2,617
6 votes
0 answers
287 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....
user avatar
  • 151
6 votes
0 answers
221 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. ...
user avatar
  • 641
6 votes
0 answers
1k 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 ...
user avatar
  • 1,365
6 votes
0 answers
230 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 ...
user avatar
6 votes
0 answers
178 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?
user avatar
6 votes
0 answers
2k 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 ...
user avatar
  • 311
6 votes
1 answer
747 views

Competing versions of GDAL

This is confusing, and a question I've harvested from a duplicate, so let me start with my setup. OS: Windows 7 x64 GIS Client 1: ArcGIS Desktop 10.5 GIS Client 2: ArcGIS Pro 1.4 GIS Client 3: ...
user avatar
  • 1,325
6 votes
0 answers
864 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 ...
user avatar
  • 681
6 votes
0 answers
478 views

QgsRasterFileWriter.writeRaster() is crashing python program

I am doing NDVI analysis on a farm image. After NDVI, I need to convert the image into singleband pseudocolor image using following Python code. def calculate(): file_name = CUR_DIR + "\...
user avatar
6 votes
0 answers
292 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 ...
user avatar
  • 61
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 ...
user avatar
  • 2,035
6 votes
0 answers
862 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 ...
user avatar
6 votes
0 answers
918 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 ...
user avatar
5 votes
0 answers
42 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 ...
user avatar
5 votes
0 answers
52 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=...
user avatar
5 votes
1 answer
106 views

Internationalization of QGIS processing scripts

How can one translate QGIS processing scripts GUI and user messages to other languages ? The QGIS documentation explains how to translate Python plugins, but not processing scripts.
user avatar
  • 137
5 votes
0 answers
100 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 ...
user avatar
  • 153
5 votes
0 answers
100 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)[...
user avatar
  • 24.6k
5 votes
0 answers
64 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'...
user avatar
  • 6,698
5 votes
0 answers
455 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....
user avatar
  • 1,385
5 votes
0 answers
392 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 Shape files. However I understand that GeoPackages have a number of advantages (not having multiple ...
user avatar
5 votes
0 answers
106 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) ...
user avatar
  • 6,330
5 votes
0 answers
106 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. ...
user avatar
5 votes
0 answers
332 views

Azimuth calculations - PyQGIS

According to the QgsDistanceArea docs, an azimuth for computeSpheroidProject should be in radians, clockwise from North So, to build a new point with computeSpheroidProject i use math.radians(...
user avatar
  • 93
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() #---------------...
user avatar
5 votes
0 answers
410 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 ...
user avatar
5 votes
0 answers
811 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 ...
user avatar
5 votes
0 answers
52 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 ...
user avatar
  • 25.8k

1
2 3 4 5
29