Questions tagged [pyqgis-3]

Python bindings for QGIS 3.

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

How to rename the result of a QGIS Processing Algorithm

When calling a QgsAlgorithm from within another, the result will be named after this algorithm output regardless of what is setup as the output of the main one. For instance, taking the code from ...
1
vote
1answer
47 views

Change attribute values of multiple fields via PyQGIS

I am starting with PyQGIS and I would like to change the values of two fields within selected features: from qgis.PyQt.QtCore import QVariant parent = iface.mainWindow() mc = iface.mapCanvas() myLyr =...
3
votes
1answer
60 views

Easy way to close open clipped contours with the edges of the clipping mask?

I am trying to programmatically (with pyqgis) clip contour lines that I've generated in QGIS, but make it so that the clipping mask forms the new edges of the contours, rather than leaving the ...
2
votes
0answers
62 views

Error name '__file__' is not defined

I have a complement (image_1) that works perfect. But I get an error by wanting to make a change. I add the code of my two .py files. I want to change this address: "C:/Users/SENARA/AppData/Roaming/...
1
vote
1answer
148 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. ...
0
votes
1answer
107 views

QGIS 3.0 migration - unable to install PyPDF2

I am migrating my Plugin to QGIS 3.0. Currently a bit stuck trying to install PyPDF2. I have been trying different things for the last couple of hours or more, without success. I have got another ...
0
votes
1answer
36 views

Remove a QgsRectangle from a RectangleMapTool in PyQGIS

In a QGIS plugin, I implemented a RectangleMapTool that I apply to my canvas. Thus, the user has the possibility to select a bounding box to define the spatial processing footprint. Once he has ...
14
votes
6answers
1k views

PyCharm 2019 is not working with QGIS anymore

Since the update to PyCharm 2019 I am unable to load the QGIS Python modules. I can not use auto completion either. I already deleted the cache (by invalidating the cache in PyCharm and also by ...
1
vote
1answer
138 views

Exporting map to PDF from template using PyQGIS?

I'm trying to update a QGIS plugin to PyQGIS 3 but I have some troubles to update the code for exporting layout to PDF. The layout derives from a template file. This is the "old" code: canv = iface....
1
vote
2answers
444 views

How to get the Z values of existing lineStringZ with pyqgis?

I can get the values of 3D QgsPoints with mypoint.get().z() When I iterate through a layer to get a specific polyline and then iterate through the polyline to get the start and end points- start_point ...
3
votes
1answer
101 views

PYQGIS 3 Using the ouptut from GRASS v.distance algorithm

I have a script which is trying to run v.distance on two existing shape files, buildings.shp which containing some polygons and singleasn.shp which contains a single point. This will be run from the ...
2
votes
2answers
91 views

Use QGIS general tools/actions in my plugin

I am creating a QGIS plugin that will use some general tools available in QGIS like "identify features" and a plugin like a "digitizing tool". Is it possible for example to link a button of my plugin ...
1
vote
0answers
19 views

GRASS is crashing every time I am running this pyqgis script. Any suggestions?

I have the following script that it keeps on crashing. How can I find a solution to this issue? import pandas as pd import processing from PyQt5.QtCore import * from PyQt5.QtGui import * resol=0....
2
votes
1answer
113 views

Getting Layer Properties of QGIS on standalone application using PyQGIS API

I am using PyQGIS API for developing the standalone application to load the certain VectorLayers. I used the QgsMapCanvas to load the map and QgsLayerTreeView to show the layer tree view using code ...
2
votes
1answer
100 views

Setting value to defaults Layer properties using PyQGIS 3

I have a vector layer, how to set defaults value in fields from the Python console. Layer Properties / Attributes Form / Defaults | In option: Default value |______________|
1
vote
1answer
35 views

pyqgis 3 vector layer labeling settings dialog

I am working on a pyqgis standalone application with the latest QGIS 3 libraries and in python 3.7. I would like to allow users to modify any vector layer's labeling style, I know in QGIS program, one ...
1
vote
1answer
63 views

Showing attribute table in QGIS plugin

I'm trying to develop a plugin which grabs a layer from the project and shows its attribute table in a tableView. My code is as follows: def getVectorLayer(self): layer = None layername = ...
3
votes
1answer
96 views

PyQGIS output to specific layer

I have a Python script that I have exported from a QGIS model and I want to specify the layer it creates as output. If defaultValue=None it outputs 'Reportpmbc': '...
2
votes
2answers
453 views

nextFeature method for FeatureIterator object in QGIS 3 seemingly not working?

How do we get the next feature from a QgsFeatureIterator object in QGIS 3? I tried the following with no success: l = QgsProject.instance().mapLayersByName('Dissolved')[0] f = l.getFeatures() f = f....
1
vote
1answer
351 views

Using GRASS in Python script QGIS 3

I am creating a Python script in QGIS 3 and I want to use the processing module. I want to transform my raster file to a vector file with the GRASS algorithm r.to.vect. My problem here is that the ...
0
votes
0answers
69 views

Taking snapshot from for loop in PyQGIS 3?

I am pretty new in PyQGIS and programming in general, and I am trying to get images from four different layers. If I do just for one time with Qtimer option, works... but the problem appears when I ...
2
votes
1answer
85 views

Applying custom plugins using PyQGIS script

I've downloaded the select within plugin to select features inside polygons objects. I've imported the plugin as import SelectWithin as sw in the console but QGIS does not suggest any of its ...
4
votes
1answer
110 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
2answers
45 views

Refresh Oracle and Spatialite Layer with PyQgis

I'm working on a Dockwidget with PyQgis. I made an insert into an Oracle DB and a Spatialite DB and I would like to see the new insert (it's a point). The Layer where the new point is add is ...
1
vote
2answers
59 views

Make flashFeatureIds's duration to depend on an action

I'm working on a Plugin PyQGIS. I've wrote a method that calculate a buffer, with this buffer I get the id of a line, with this id I flash the line for a few seconds. I used flashFeatureIds: self....
4
votes
1answer
37 views

How can i prevent a form from closing unless data is accepted by validation

I try to use a custom-form in QGIS 3 to validate input-data before saving the data in a database. It would be nice to have the form open unless every input is correct. But the dialog/form closes even ...
2
votes
1answer
196 views

Build Close Vertex Finder in QGIS

In OpenJump there is a tool called ClosedVertexFinder which you can use to find vertices which are too close to each other. https://github.com/ssinger/roadmatcher/blob/master/src/com/vividsolutions/...
1
vote
1answer
31 views

PyQGIS: How to store the result of cliprasterbymasklayer

This Question is a follow up Question to this one I recently asked. In my plugin I have a function that clips rasters by mask and I would like that the function returns the raster layer object. And ...
1
vote
2answers
46 views

Select by location using separate features iteratively (pyqgis)

I am looking for a way to run select by location, specific to the features of the 'INTERSECT' layer. I have got bus locations and bus stops and want to figure out when the bus has entered and left ...
4
votes
1answer
102 views

Get the reference of Attribute Table while opening in QGIS

I have a problem related to this question and the script. I can add some functionalities to Attribute Table (AT) by the script in the post. But according to the post, I have to open the AT using ...
2
votes
1answer
377 views

Deep Learning in QGIS: installing Tensorflow

I am trying to install tensorflow (with or without GPU support) with the keras API in the QGIS 3.4 LTR python 3 environment but without success. I do have a working install of tensorflow-gpu that I ...
0
votes
2answers
50 views

PyQGIS in PysScripter

I am trying to add the PyQGIS in PyScripter, I have followed the tutorial provided in QGIS tutorial: IDE settings for writing and debugging plugins. I have created the bat file as follows: SET ...
2
votes
1answer
60 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.
4
votes
1answer
75 views

Zoom to feature by clicking cell in the Attribute Table

I have a layer which has FID field representing the unique ID of features. In QGIS, there is a Zoom to selected rows button on top of the Attribute Table. It has a shortcut (Ctrl + J) and it doesn't ...
2
votes
1answer
321 views

PyQGIS - Print Layout Legend. setLegendFilterByMapEnabled()

I'm creating a legend in my print composer and only want "visible", or active, layers shown in the legend. This means I want only layers with the box checked in my layers panel. Here is how I create ...
0
votes
1answer
52 views

Getting bounding box of polygon

I'm having difficulties to get the bounding box of a polygon. My code is the following: def getBoundingBox(self): boundingBox = [] polygon = self.getVectorLayer() vertices = polygon....
1
vote
1answer
19 views

How close an editing session in pyqgis3

I have a custom tool to add feature points. The attribute values are provided filling a custom dialog. The code was writted following this topic. At the end of the procedure, outside the tool, if I ...
3
votes
2answers
173 views

Apply a color ramp to vector layer using PyQGIS3?

I'm trying to apply a color ramp to a QgsGraduatedSymbolRenderer in PyQGIS 3 (QGIS 3.8) using the following code: Getting the QgsGradientColorRamp: myStyle = QgsStyle().defaultStyle() ...
0
votes
0answers
21 views

Set the Output of a script as Input of another one

What is the correct way to call the output file of a script? Since QGIS can't name it automatically. I have this script that works perfectly, just drop a file identical to the original. from qgis....
1
vote
0answers
53 views

PyQGIS grass7:v.distance parameter error “The number of columns and the number of upload parameters should be equal!”

I am currently working on a Python script for QGIS in which I would like to obtain the (minimum) distance from each point (polygon centroid) in the points layer centroid_layer to the line layer ...
5
votes
2answers
133 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....
1
vote
1answer
79 views

Tab widgets in QGIS plugin - run different scripts

Is it possible to run separate python processes through tab widgets of the same QGIS plugin. I have created a QGIS plugin using the plugin builder. From QT designer I added two tab widgets to the ...
1
vote
0answers
25 views

Rotating raster cells with QGIS GDAL

I've written a PyQGIS script based on this answer to the following question: Writing numpy array to raster file My data shows up at the correct, expected location but the raster cells, which are ...
6
votes
1answer
120 views

Get index of QgsAttributeEditorField from QgsVectorLayer

I have a QgsVectorLayer and right now I'm retrieving it's fields like that: for index in layer.attributeList(): print(layer.fields()[index].name(), layer.attributeDisplayName(index)) Now I ...
1
vote
1answer
52 views

Qgis 3 : QgsEditorWidgetSetup for date

I need to make a date format in QGIS 3 but, in the program I need to use, QgsEditorWidgetSetup('Date',{'yyyymmdd'}), I want to get this: But I don't know how to use QgsEditorWidgetSetup to make the ...
1
vote
0answers
18 views

Which type of slash to use in path - QGIS 3.8 with Python [closed]

I'm a beginner using Python. I had a problem loading a shapefile in QGIS 3.8 using Python, while loading a rasterfile worked perfectly. I found the solution here: Can't load a shapefile with ...
3
votes
1answer
52 views

Creating a Line feature in PyQGIS QGIS 3.x

In QGIS GUI, a line feature is created from this icon 1.jpg How to Create a line with a fixed distance from a vector layer in python console. This my example: from qgis.core import * from qgis....
2
votes
1answer
32 views

pyqgis create layer from a list of points

I am working with pyqgis in QGIS3 and i want to create a point layer from an intersection beetween a point and a polygon layer. I can identify wich points intersects my polygon layer but i can't use ...
3
votes
1answer
46 views

Create rotated point grid inside polygon

I want to create a rotated grid inside a polygon using a starting point and a rotation angle. I have started with the python script found here. I have altered the original script to accommodate ...
3
votes
0answers
32 views

PyQGIS Layout - Change Image Source QGIS 3

Looking for a solution to loop through existing layouts in a QGIS 3.6 document and change a source of an image. The image is the same in each of the layouts. What I have is: from qgis.core import ...