Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [pyqgis-3]

Python bindings for QGIS 3.

1
vote
1answer
14 views

Expand or Collapse Layer Groups in PyQGIS3

PyQGIS2 has a function to expand/collapse a layers with a subset of styles in the Layers panel as follows: self.iface.legendInterface().setLayerExpanded(self.segments_layer, False) I know that in ...
2
votes
1answer
48 views

Making Upload button for shapefile in QGIS plugin?

I am new to Plugin Builder and creating my first plugin called NearestNeighbour. The below is GUI of my plugin made using Qt Creator I read in this link that it is important to rename Dialog Box, ...
1
vote
1answer
17 views

'NoneType' object has no attribute 'identify'

I'm trying to run a console script, but it gives an error: : AttributeError:'NoneType' object has no attribute 'identify' Yet it works well in QGIS 3.7 Here is the script: import sys import time ...
0
votes
0answers
19 views

AttributeError: 'NearestNeighbour' object has no attribute 'dlg' [on hold]

I am learning to make my first python plugin named NearestNeighbour(different from the one we have in QGIS3, name are coincidentally same) which take two vector layer. With the help Qt Creator I was ...
1
vote
1answer
16 views

Parsing an input parameter to gdal:rastercalculator formula in QGIS 3.6 Python script

For training purposes I'm writing a QGIS 3.6 Python script. The script takes as inputs a raster layer and band, and three float numbers (refmult, refadd, sunel) and computes a simple formula: ((layer@...
1
vote
1answer
41 views

Set label precision with QgsRendererRangeLabelFormat class

I'm trying to control the number of decimal places represented for a layer in my project. I can do this in the symbology tab like this: I want to do this in PyQGIS. Here is an example of how I would ...
1
vote
1answer
24 views

Area Value not getting reflected in attribute Table using PyQGIS?

I have a WardBoundary.shp file in my project. I need to find the area of each polygon ( representing different wards).With the help of this comment on Adding Area column in Polygon layer using PyQGIS?,...
-1
votes
1answer
43 views

Adding Area column in Polygon layer using PyQGIS? [on hold]

I have a WardBoundary.shp file with Polygon Features in it. I have to calculate the area of each Polygon and write into attribute Table. I can do manually by using '$area` but I need to automate ...
1
vote
0answers
19 views

Where is “Nearest neighbour analysis” tool in pyqgis documentation?

I have a group of point features for which I want to run the Nearest neighbour analysis using python. The problem is that I cannot find that function in the documentation. The closest I got was: ...
1
vote
0answers
25 views

Open attribute table script in QGIS 3.6 graphical modeler

I am looking for a script which will allow me to open an attribute table of the final output of a graphical model in QGIS. I know that you can use the following lines of code in the console but ...
1
vote
1answer
14 views

How to get Memory layer dispalyed in Vector Panel List using Pyqgis?

I have two point layer in my Project Centroid.shp and Nodes.shp.I have used Distance Matrix to find nearest Nodes point from Centroid Point. I have saved the output in FinalDistance.csv. The ...
3
votes
1answer
28 views

selectionChanged connection is being called twice

I have this function with: self.iface.mapCanvas().selectionChanged.connect(self.openThePano) which waits for a feature selection change to connect to the function openThePano the issue is that once a ...
2
votes
0answers
35 views

Slow retrieval of features

I have a vector layer with lots of features and I'd like to create a new layer in Python, containing only a subset of those features. To be more specific, I downloaded OpenStreetMaps data of Austria (...
1
vote
1answer
20 views

Is it possible to print a map in PyQgis3 of a database table without rendering the layer in the project gui?

There is a way to print a map using pyqgis3 without rendering the vector layer in the project interface? (by giving just the connection to the table, the map extent and the style )
2
votes
1answer
44 views

How can I display an image on QGIS from a DJI drone using python?

I have a few images from a DJI drone and I can get all of the information from the image exifread. I am trying to get an image to be displayed in the correct location on a QGIS map. Is there an ...
1
vote
1answer
28 views

Update QGIS Canvas while debugging

I am upgrading some QGIS 2 plugins to QGIS 3 and need to do some debugging. It appears that the canvas does not update until the code stops running, regardless of any calls to self.iface.mapCanvas()....
-2
votes
0answers
20 views

Creating grids in vector layer using PyQGIS 3.6 [closed]

I want to learn how to create a grid in a vector layer without using UI, i.e. using PyQGIS. How can I achieve such a result?
0
votes
0answers
17 views

import qgis.core in Spyder- DLL load failed

First off, I'm working with QGIS 3.4.5, Spyder 3.6 installed through ArcGIS Pro (2.3.2) python package manager on Windows 10. I can't get the qgis.core module to load and I need some help. I'm ...
1
vote
1answer
34 views

QGIS 3 PyQGIS Script - Merge Layers and Export to csv with KML geom field

I previously had a script in 2.18 that exported csv files with kml geometry's file by file. I'm now wanting to move to QGIS 3 and do the same process except Merge the point layers then add the ...
1
vote
0answers
14 views

How to add or delete one category in Categorized Symbol Renderer PyQGIS QGis 3.x

I need code for add o delete Categorized Symbol in QGIS 3 category = ? More information: https://qgis.org/pyqgis/3.4/core/QgsCategorizedSymbolRenderer.html
0
votes
0answers
41 views

Running PyQGIS script inside QGIS console via Plugin?

I have some calculation and processing done on vector data. I have written code in pyqgis( and executing inside Console).I need to create a plugin (for my use only) which don't have any input button ...
0
votes
0answers
11 views

Editing a map created with PyQgis3 in Qgis Print Layout

I create a new print layout using PyQgis and then I open it in the layout designer. Everything seems ok till I try to refresh the page or update the map extent, then map disappears. project = ...
3
votes
1answer
56 views

Making a custom expression “portable”…?

In a QGIS project im using a custom expression. As far as i know they are stored locally in a .py file located in the user profile. What would be the solution to make this custom expression "...
2
votes
1answer
38 views

Where to get QGIS 3 Join by Field Value Script?

I´m trying to solve my problem with Join attributes by field value and for that I want to make a script on PyQGis to solve that. Is there a location where I can found the script used in Join by field ...
2
votes
1answer
22 views

How to duplicate Layout PyQt5 QGIS 3?

I want script in python3 with QGIS 3? For example: This code create a layout 2019_A4 and add Layout Manager. I need a code make same in QGIS3 using QgsLayoutManager with Methods duplicateLayout ...
4
votes
0answers
61 views

QGIS projects in PostgreSQL (pyQGIS - saving proj to DB)

I'm currently working on some code to automate the creation of a QGIS project from tables in a PostgreSQL DB. For info I'm working in QGIS 3.4. I'm almost there, but I'm stuck on one thing How do I ...
6
votes
2answers
80 views

How to change form content dynamically in QGIS 3.6

By using "Identify Features" QGIS shows a form for viewing and editing attributes in the canvas. Now I want to change the visible form elements dynamically by attribute value. An example in ...
1
vote
0answers
38 views

Deleting vector layer from Geopackage using PyQGIS?

Programmatically I have added the vector layers to an existing Geo Package in QGIS 3.2 using python. Similarly, I would like to delete a layer from the existing Geo package using python code. But ...
1
vote
0answers
37 views

How to determine the status of snapping in QGIS 3?

I can use toggleEnabled to turn snapping on and off, but is there anyway to know the status of the snapping tool (on or off)? as toggleEnabled doesn't return a value nor does it take a value.
1
vote
1answer
29 views

removeGroup() in QGIS 3

I am updating a plugin from QGIS 2 to 3. I need to iterate through the groups (the names are dynamic) and remove them with their respective child layers. I need to get a list of groups and then ...
2
votes
1answer
39 views

Error after loading new plugin Qgis 3.4

In Qgis 3.4, after creating a plugin with plugin builder, compiling it with pb_tools, I still can't load it to Qgis. I keep getting the following error message: "Couldn't load plugin 'test_api' due ...
3
votes
1answer
72 views

Using libraries other than PyQGIS to develop plugin for QGIS?

I develop a plugin for QGIS. Before to integreted it in the QGIS I developped it with GIS library (Fiona, shapely, geopandas, ...) and it work well. Now I try to build it with plugin_builder of QGIS. ...
1
vote
0answers
24 views

PyQGIS Creating Numpy Array from QByteArray (QgsRasterBlock.data()) and vice versa (QGIS3) [closed]

I am looking for a way to convert the values contained in a QgsRasterLayer object to a numpy array and vice versa without using any GDAL methods. To obtain the numpy array I go through ...
4
votes
3answers
97 views

Sort layers in table of contents in QGIS 3?

When I load a bunch of layers into QGIS, they seem to load in reverse alphabetical order. I'd like to sort them alphabetically. In this thread a solution is proposed, but that does not work in QGIS 2....
4
votes
1answer
70 views

Add Help Menu entry in QGIS 3 from `startup.py`

I would like to add a menu entry in the Help menu pointing to some web ressource, say https://gis.stackexchange.com. The following code executed from the python console works perfect: from qgis.utils ...
1
vote
1answer
16 views

How to set vector symbol outline properties in pyqgis 3?

I have a polygon vector layer and I want to style it within a processing script. Part of the code creates a categorized symbology for my layer but I cannot find a reference online on how to access the ...
1
vote
1answer
43 views

Load layer styles from PostGIS DB with QGIS 3 with PyQt5

I'm trying to load styles that are stored in a PostGIS database. We have them organised in sets, for each layer that is in the DB. I added comments in the code. This code was previously 2 lines. ...
2
votes
1answer
86 views

IDW interpolation in Python in QGIS 3.4

I have a problem with IDW interpolation. I need to use canvas extent and other attributes (I created an option with only attribute 0, other attributes aren't working). The documentation is not very ...
4
votes
1answer
47 views

Setting layer identifiable, seachable and removable with Python in QGIS 3?

With PyQGIS, I want to set project layer properties (Project Menu > Properties > DataSource) such as Identifiable, Searchable and Required (for Read Only, the method is QgsVectorLayer....
0
votes
1answer
28 views

Setting style for categorized vector in PyQGIS?

I'm writing a plugin in QGIS3 which produces a vector file from a thresholded raster (i.e. polygons all have a value of 1 or 0). So far so good. I'd now like to load it in QGIS and display the ...
3
votes
0answers
38 views

Hiding Layer Source using PyQGIS

I am developing a plugin for QGIS that loads the layers of a WFS. For security reasons I would like the user could not know the layer source. How can I remove the path of the layer in Vector ...
2
votes
1answer
32 views

How to move a layer position on the layers order

I am looking for a way of moving a layer to the top of the layer order once another layer is loaded. Using the following code extracted from this answer I get the error: AttributeError: '...
2
votes
0answers
22 views

Toolbar button with drop down menu

I want to create my own Toolbar with a Toolbar button which has a drop down menu: The following code works fine in the QGIS console: from qgis.core import Qgis from PyQt5.QtWidgets import QToolBar,...
1
vote
1answer
55 views

QGIS 3 startup script is not executed

Following the documentation for QGIS 3 startup script, I have placed a 'startup.py' script in the following path: C:\Users\Me\AppData\Roaming\QGIS\QGIS3\profiles\default\python\startup.py But the ...
2
votes
2answers
67 views

Adding elevation to point in PyQGIS?

I am trying to add elevation to a 2D point in a QGIS 3 plugin, preferably in a concise and straightforward way. Not finding this easy. I think part of the problem is that in QGIS 3, fromPoint() has ...
1
vote
0answers
22 views

How to retrieve the data source of the active layer? [closed]

I am trying to get the data source of the layer in the Python action within the layer property. My code in the Python action is: layer = iface.activeLayer() QMessageBox.information(None, "parDir: ", ...
1
vote
0answers
22 views

QgsSingleBandPseudoColorRenderer not automatically applied after added

Summary I am trying to apply a Single Band Pseudo Color Renderer (SBPCR) to a raster layer, importing the shader from an XML. I've hit a dead end trying to get my SBPCR to apply. QGIS Version - 3.4....
2
votes
2answers
123 views

Search and Replace text in All Fields in QGIS 3

I want to replace a string in ALL FIELDS / Columns of table without having to do it using field calculator in every field manually using replace( "RoadName1" ,'Wharf','WharfXXX'). I have layer = ...
1
vote
0answers
41 views

Merging multiple QgsRasterLayer objects to create virtual raster (.vrt file) using gdal

I am creating multiple QgsRasterLayer objects in pyqgis and I need to merge them into a virtual raster .vrt file which will eventually be loaded as a layer in QGIS. The QgsRasterLayer objects are ...
2
votes
0answers
23 views

Calling a Python function for each page in an atlas

I have made a script to do some calculations for each page of a QGIS atlas (QGIS Atlas with insert map) The script is adjusting the bounding box of a map on the layout page. To make it run for each ...