Questions tagged [pyqgis]

Python bindings for QGIS.

1,138 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
9
votes
0answers
321 views

Open QGIS project files in exclusive mode / alert if project file already in use

I have QGIS-Project-Files saved to a network drive and was wondering if it is possible to warn users that a project file is already opened by an other user to prevent concurrent editing of the same ...
8
votes
0answers
262 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 ...
6
votes
1answer
247 views

PyQGIS 3 - Add New Layer to Spatialite Database

For the most part, working with QGIS layers has been a pleasure, but I've run into some difficulties recently when trying to create a new vector layer in the SQLite database I've been using. I've ...
6
votes
0answers
505 views

Adding layer using QgsMapLayerRegistry within thread PyQGIS Plugin

I am developing Python QGIS plugin, where I am opening two threads in run function with one thread performing calculation while second thread is printing value looping and when first thread is ...
6
votes
1answer
305 views

Save as output layer from QGIS processing algorithm to PostGIS database using PyQGIS

I have two layers(layer1,layer2) in PostGIS database where I have connect in QGIS project. My database have specific precision. Now I want to use from QGIS processing some algorithms like ...
6
votes
0answers
300 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 ...
6
votes
0answers
654 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 ...
6
votes
0answers
848 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 postgres 'layer_style' table. I have had a look at the documentation ...
5
votes
1answer
87 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 ...
5
votes
0answers
342 views

Labelling a rubber band (QgsRubberBand)

It is possible to label QgsRubberBand or QgsVertexMarker with a text annotation (QgsTextAnnotationItem). See this MWE: ... r_polyline = QgsRubberBand(iface.mapCanvas(), False) r_polyline....
5
votes
0answers
820 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 ...
5
votes
0answers
124 views

Speed 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 extract ...
5
votes
0answers
301 views

QgsRubberBand Move Event

So, basically I've created a QgsRubberBand which copies feature from layer. And I need to be able visually move this rubberband on mouse event 'move'. Actually same visualisation like during self....
5
votes
1answer
235 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", and toggle ...
5
votes
1answer
609 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: ...
5
votes
0answers
349 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 + "\...
5
votes
0answers
814 views

Importing numpy array into QGIS?

I have some computation on a numpy array and want to display the result in QGIS. So far ok, but loading the result into QGIS fails. Here my code fragment: zData2 = np.subtract(myarray,zData2) #do ...
5
votes
0answers
565 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 but with not success till now. I am using PyCharm CE v4 and QGIS version 2.8 I have tried to implemnte the instructions of several posts like ...
5
votes
0answers
1k 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 ...
5
votes
0answers
816 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 ...
5
votes
0answers
894 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 ...
4
votes
0answers
38 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) ...
4
votes
0answers
41 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. ...
4
votes
0answers
54 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....
4
votes
0answers
288 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 ...
4
votes
0answers
53 views

Measure loading times of QGIS projects

For QGIS there is already a method to measure loading times of plugins ( qgis.utils.plugin_times): How to tell which QGIS plugins are slow to load? Is there something similar to measure loading ...
4
votes
0answers
132 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 ...
4
votes
1answer
234 views

Layout export from stand-alone PyQGIS script shows empty map

I have a problem with exporting of a QGIS layout by the pyQGIS. I have prepared the qgz project and also the qpt layout. When I try to export the layout to PDF by QgsLayoutExporter.exportToPdf by ...
4
votes
0answers
197 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 ...
4
votes
0answers
135 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?
4
votes
0answers
94 views

Halftone effect gridded points inside polygon

I am trying to create smooth looking polygons by gridded points in QGIS (2.18.16), with a fading effect towards the boundary of the polygons (halftone effect). By using the 'fillGrid' function from ...
4
votes
0answers
316 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 ...
4
votes
0answers
257 views

Installing third party python library in QGIS 2.18.x Windows

We are running into a strange behaviour while trying to use pyoidc with QGIS 2.18.x windows standalone version. Due to pip/pipy no longer working with QGIS 2.18 (see this post), we installed the ...
4
votes
0answers
230 views

Get signal on delete group on QGIS 2.18.16

I tried : QgsProject.instance().layerTreeRoot().willRemoveChildren.connect(self.onWillRemoveChildren) It works if I delete a group within in the root node. But if I delete a layer within a group ...
4
votes
0answers
179 views

Minidump in C when executing Python script

I have written a python script which should calculate the azimuth for a line (with two given points). But every time I run the script, I am getting the following error message: If I click OK, QGIS ...
4
votes
1answer
196 views

PyQGIS spatial operators(contains,equals,etc.) w.r.t. layer geometries(polygon,point,line,etc.)

I am trying to implement QGIS spatial query functionality in my plugin. I want to eliminate spatial operators which are not suitable for certain geometries. For eg. when I select layer with point ...
4
votes
0answers
134 views

Relation/difference between area calculated by PyQGIS QgsDistanceArea().measurePolygon() and QGIS $area

What is relation/difference between area calculated by QgsDistanceArea().measurePolygon() of PyQGIS and $area from geometry $area in QGIS? I am getting area as 0 for one polygon using QgsDistanceArea(...
4
votes
0answers
245 views

Geocoding an address involving non-ASCII characters in PyQGIS

I have installed the "GeoCoding" plugin in QGIS and it worked well even though I have used non-ASCII characters to geocode (i.e. Hacettepe Üniversitesi). However, when I tried to do the same in PyQGIS ...
4
votes
0answers
31 views

QGIS script accessing old version of layer

I have added a couple of fields to a postgis table which is loaded into a layer in QGIS. When I access the attribute table in QGIS I can see the two new fields but when I run a script (using ...
4
votes
0answers
677 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 ...
4
votes
0answers
699 views

Right-hand-rule in QGIS

It seems that there isn't a plugin to perform the right-hand-rule on a layer or selected features. Can this be done by using some Python code? Is there a function that works in the same way as ...
4
votes
0answers
301 views

Reopening QGIS project from PyQGIS

I am opening a QGIS project using the following snippet: new_project = False if not os.path.exists(self.qgis_project_path): prj_template_path = os.path.join(self.qgis_template_path, 'project.qgs')...
4
votes
0answers
107 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 ...
4
votes
0answers
246 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 ...
4
votes
0answers
78 views

Loop distance point PyQGIS

I have a .shp of lines where I'm able to calculate the sum of segments length but I'm trying to put a point at a given distance in meters. The problem is it puts a point at every segment. When I give ...
4
votes
0answers
99 views

Issues updating field values programmatically for particular field data type on 64bit Windows computer using QGIS 2.8.7

I have an issue with a plugin for QGIS 2.8 I'm developing when using it on a Windows 64bit machine (as opposed to 32bit). I am trying to update values in a particular field in my plugin, and the ...
4
votes
0answers
417 views

PyQGIS: vector layer does not get displayed after rendering

My project goal is to write a standalone app for Unbuntu and QGIS 2.14. It should get a layer of simple points and their name from a Postgres database and show them in a layer. In addition there ...
4
votes
0answers
76 views

Parallel feature request connection limit

I have a large pool of feature requests that need to be performed on a PostgreSQL layer. Please assume that these requests cannot be joined into larger requests. If I spawn several threads to perform ...
4
votes
0answers
858 views

module object has no attribute classFactory

I asked this question several days ago on the QGIS developer list but didn't get any love. I'm hoping someone can help me resolve this error. I have a custom repo and a custom plugin that I'm ...
4
votes
1answer
297 views

Showing only selected features from a a layer in the QgsComposerLegend?

I have developed a custom qgis plugin. I have a button to export the map canvas in the form of image along with the legend. I came up with the following code for the legend: legend = ...

1
2 3 4 5
23