Questions tagged [pyqgis]

Python bindings for QGIS.

Filter by
Sorted by
Tagged with
1 vote
1 answer
56 views

Removing all legend entries except one in LayoutItemLegend using PyQGIS

For my QGIS Plugin want to remove all legend entries in my layoutItemLegend exept one entries (chiro_layer). I would like to browse all of my legend entries and delete this one if it does not match ...
11 votes
2 answers
7k views

Loading composer from template and generating atlas using PyQGIS

I am trying to build a plugin to load a print composer from file, generate an atlas and export to image. So far I have been successful in loading the template and exporting it to image. I have been ...
11 votes
4 answers
8k views

Iterating over layers and exporting them as PNG images with PyQGIS in standalone script

How do I export specific layers as a png from a QGIS .qgs map? From the table of contents the script would first export the "boundary, climits, and Div1_Irrig_1956_0" layers as one png. The ...
13 votes
3 answers
5k views

Adding layer to group using PyQGIS

I am trying to add new layers into a specific group which I can get to work if I know the index, but how can I get Python to find the index of a group so it can load the new layer into the group ...
2 votes
0 answers
28 views

PyQGIS: moving legend with changed reference point

I am trying to create a print layout using PyQGIS. As part of that, I want to move my legend to the bottom right corner of the map, using the lower right corner of the legend as the reference point. ...
1 vote
1 answer
18 views

How can I activate GeoTIFF compression in QGIS 3.x gdal_translate?

I am a beginner at Python so please excuse this stupid question. I am working on a simple QGIS plug-in for saving GeoTIFFs and I want to give the user the option to switch on compression when saving ...
0 votes
0 answers
12 views

What do CORE_EXPORT and GUI_EXPORT keywords mean?

In some QGIS classes there is a statement CORE_EXPORT or GUI_EXPORT between class operator and class name. What does this statement mean? Example in this part of surce code: https://api.qgis.org/api/...
1 vote
0 answers
16 views

How to remove all resources loaded from QGIS plugin?

I used the QGIS Plugin Builder to create a plugin where the main.py file imports dockwidgets and class from its own file and from other files. A button on the toolbar executes the run(self) function ...
6 votes
1 answer
44 views

Displaying milliseconds in Attribute Table using PyQGIS

I have a datetime string with microsecond. I use the following script to get a QDateTime object and add it to a memory layer: layer = QgsVectorLayer("Point?crs=EPSG:4326", "test", &...
2 votes
2 answers
343 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 ...
2 votes
0 answers
35 views

Creating QGIS project file without installing QGIS

Goal We want to automatically create QGIS projects (preferably in python), including a given set of Layers. Approaches We thought of creating a project file by defining it in a .qml file given a ...
0 votes
1 answer
35 views

PyQGIS script (.py) runs correctly on Windows but not on Mac

I wrote a script that takes a vector layer already present in my QGIS project and refactor fields as I wish. I created the script to avoid doing plenty of times the same refactorization manually every ...
1 vote
0 answers
17 views

How to check Length calculated in Cartesian or ellipsoid?

I am trying to do offset curve of a line my layer projection is ESPG:3857 WGS-84\pseudo-Mercator lyr=iface.activeLayer() geom=lyr.selectedFeatures()[0].geometry() newgom=geom.offsetCurve(5,2,1,0.0001) ...
17 votes
3 answers
9k views

Zooming to selected feature using PyQGIS

I want to create a function that selects a feature and zooms to it (similar in QGIS). Therefore there is following function: QgsMapLayerRegistry.instance().addMapLayer(self.vlayer) def zoomTo(self): ...
23 votes
2 answers
1k views

Can qgis_core work with external python distribution such as Anaconda?

I've built a Python application that has its own GUI. I am trying to use qgis.core/PyQGIS as map display only. Specifically, I have anaconda 2.3 and its Python distribution (2.7.11). It seems that ...
-1 votes
0 answers
19 views

Find Pattern in Urban Function using PyQGIS [closed]

How can the following task be performed: Use CSV with latitude, longitude and Urban functions (Supermarket, malls ,etc) Calculate distance using latitude and longitude fields Use polygon feature ...
10 votes
3 answers
9k views

Deleting column/field in PyQGIS

How to remove or delete column fields in a shapefile using PyQGIS?
0 votes
0 answers
71 views

DEM color ramp settings, disabling continuous legend, label precision with PyQGIS script [closed]

I have a script to automate my workflow in QGIS. substring = "_DEM" strings_with_substring = [name for name in names if substring in name] for i in strings_with_substring : DEM = ...
4 votes
3 answers
699 views

Making automatic updated date and time field in QGIS

I wish to create a field which automatically updates with the current timestamp when edits are made to a feature. I am using QGIS 3.4 and I am testing this using a shapefile. Following @Joseph's ...
0 votes
0 answers
24 views

Render a polygon in QDialog and enabling it's vertices to be clicked? [closed]

I am trying to add some functionality to a custom plugin I made. In order to automate georeferencing, I need user input to get raster orientation. Is there a possibility of rendering a polygon in a ...
8 votes
3 answers
3k views

Setting layer transparency using PyQGIS

I have a raster layer loaded in QGIS 2.0 and I'd like to be able to set its transparency via the Python console. I'm new to the API and have not been able to find out how to do this. Here's what I ...
1 vote
1 answer
70 views

Updating layer attribute in QGIS processing script

In a QGIS processing script I try to update an attribute value in a feature with changeAttributeValue but I am not able to. I'm following: https://courses.spatialthoughts.com/pyqgis-in-a-day.html#...
2 votes
1 answer
126 views

QGIS Raster Calculator using Python to combine two layers

I am a QGIS beginner and I want to combine two layers using the raster calculator via Python. For the beginning, I simply want to add the two layers but currently, I don't get an output file. Code is ...
3 votes
1 answer
2k views

Adding CSV layer in PyQGIS

I am trying to load a series of CSV files as vectors in PyQGIS. I run this code to try to get the first one: uri = 'file://D:/Saved Stuff/gulags/1.40.csv?delimiter=;&yField=y&xField=x' layer = ...
2 votes
0 answers
31 views

Update Layer Name From External Script using PyQGIS

I have setup a dev environment to run QGIS 3.16 scripts from VSCode by following the instructions here... https://blog.locatepress.com/setting-up-pyqgis3-with-vscode-python3-on-windows/ I have written ...
-2 votes
0 answers
25 views

Unable to add delimited text file using PyQGIS and CSV [closed]

I am using the following code uri = "C:\\Users\\Tejas\\Downloads\\sample\\sample\\AWS-FINAL-USE.csv?delimiter={}&xField={}&yField={}".format(";", "LON", "LAT&...
0 votes
0 answers
42 views

Registering events in geometry generator

I have a problem with a geometry generator I wrote to display lines in a specific manner. The code is similar to this simplified example: # This contains geometries in a simili-layer line_cache = {} ...
9 votes
4 answers
3k views

Maximum value of field of vector layer using PyQGIS

If I have a vector layer in QGIS, how do I use Python to find the maximum value which a given field has? I need to convert the values in one field into values between 0 and 1. I guess I therefore need ...
2 votes
2 answers
167 views

QGIS polygonize issue: GDAL DLL load failed

I am using QGIS Desktop 3.10.0 and I have some issues with the polygonize tool. When I run the polygonize tool, a warning shows up saying that there is an “Import Error: DLL load failed” (see Figure 2)...
1 vote
1 answer
55 views

Using PyQGIS to buffer the width different than the height of a rectangle

So I have a polygon in QGIS (3.18) and it will always be a rectangle (I create it using minimum bounding geometry, oriented rectangle) I want to buffer the width out using some math to get the total ...
2 votes
1 answer
508 views

How to close open files after processing.runalg() command (Qgis: Error No 24)

I'm creating a pyqgis script. In this script I use the processing.runalg command several times. The problem is that these processes are within a for loop. After several iterations, the error number 24 ...
1 vote
0 answers
21 views

Using PyQGIS to replicate my PostGIS result of placing radial lines over polygons

As shown in this photo I have some polygons. I want to make a grid over these polygons (lets say the squares of the grid are 100x100) and over each square I want to place radial lines going through ...
0 votes
0 answers
21 views

Define the users which can open and edit QGIS Project

We have copied our QGIS projects and layers in our network drive and everyone can open and see them. But only some of them (specific usernames) shall be able to edit the layers. Is there eny way in ...
0 votes
0 answers
39 views

Is there a way to filter out polygons/lines using geometry in QGIS?

I am currently working on a project to digitize utility data, however my input layer is not classified. I am currently using length of the features to filter out unnecessary lines/polygons. Is there a ...
2 votes
1 answer
31 views

Creating Virtual Field from QGIS Python Console

I would like to create a new virtual field with a specific expression (like 2*"ID") on an existing layer. Is it possible to do so from the Python console? I've tried using addExpressionField ...
8 votes
1 answer
91 views

Looking for PyQGIS equivalent of ArcPy tool for passing Geometry object to processing algorithm

In ArcPy, you can pass a geometry object as parameter to geoprocessing tool: import arcpy coordinates = [[20, 30], [30, 30], [30, 20], [20, 20]] array = arcpy.Array([arcpy.Point(x, y) for x, y in ...
2 votes
1 answer
49 views

Setting direction to clockwise using PyQGIS

I am looking for a way to change the direction of the pie charts of a layer from counter-clockwise to clockwise in QGIS 3. I looked in the docs but I don´t seem to find a way to do this. Does anybody ...
2 votes
1 answer
51 views

PyQGIS: how to filter feature attributes according to symbol in the legend

I can reach feature attributes as follows: for feat in layer.getFeatures(): print(feat.attributes() ) This gives me whole attributes. I want to filter attributes according to each symbol in the ...
1 vote
0 answers
16 views

Spatial sorting using Hilbert Curve in custom function in QGIS results in unpacking error

I am trying to implement spatial sorting using a Hilbert Curve. I have taken the code for calculating the Hilbert Curve distance from https://en.wikipedia.org/wiki/Hilbert_curve and converted it to a ...
5 votes
1 answer
173 views

Automating classification of symbology in PyQGIS

I have created this code to categorize my layer symbology based on the attribute plant_allo. However I still have to press the classify button which I also want to automate in PyQGIS. Can anyone help ...
1 vote
0 answers
19 views

Color gradient in Point layer, based on attribute

I have a collection of points[nr, x, y, z] with elevation z added to the map like this: ... for i in range(len(points)): seg.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(points[i][1], points[i][...
7 votes
1 answer
1k views

Creating Virtual Field in QGIS Python Console

Is there any example about how to create a virtual field and subsequently change the attribute of a non-virtual field without wiping out the virtual field? Both are required to be done in the Python ...
-2 votes
1 answer
29 views

Couldn't load plugin 'produce_training_data_for_deep_learning' due to an error when calling its classFactory() method [closed]

ModuleNotFoundError: No module named 'gdal' Traceback (most recent call last): File "C:\PROGRA~1/QGIS32~1.2/apps/qgis/./python\qgis\utils.py", line 423, in _startPlugin plugins[...
1 vote
1 answer
483 views

gdal.rasterizeLayer in QgisPython results in Nan values

I have a vector layer projected in WGS84. I would like to use gdal.rasterizeLayer() from the python console to convert it to a raster. I would like to burn values from a field. I followed the gdal ...
1 vote
1 answer
339 views

Checking SAGA version from a python plugin in QGIS 3.4.0

I use QGIS 3.4.0 on Windows and I want to verify SAGA version with processing.algs.saga.SagaUtils.getSagaInstalledVersion(). But I get an error: module 'processing' has no attribute 'algs' This was ...
1 vote
1 answer
51 views

Conditional signals in QgsTask managing algorithm output

Last question from my QgsTasks questions trilogy... I'd like to insert a new processing algorithm with a raster as an input (let's say 'fill sinks' for instance) to the code provided by @Ben W in his ...
3 votes
1 answer
46 views

Using PyQGIS to displace polygon to larger intersection

I have a buffer that intersects with 2 polygons. How can displace the buffer to the polygon with the largest intersection? in addition So far my code determines how many polygons my buffer ...
1 vote
1 answer
129 views

Layer failed to load using PyQGIS on macOS Mojave

The following is the code that I wrote with the help of PyQGIS Developer Cookbook from qgis.core import * from qgis.gui import * import os #Reference to QgsApplication qgs = QgsApplication([], False)...
0 votes
1 answer
31 views

Requests Python module in QGIS return nontype or empty CSV

I am using the Requests Python module to query a 3rd party API that returns a polygon of an address, the returned CSV returning only part of the header, while it is working fine when using the code ...
0 votes
0 answers
45 views

PyQGIS in PyCharm attributes error

please I really need someone to help me here. This is the second time I'm posting this. I'm actually new to Python and QGIS. I'm using PyCharm as my code editor to write a standalone code. trying to ...

1
2 3 4 5
130