Questions tagged [pyqgis-3]

Python bindings for QGIS 3.

Filter by
Sorted by
Tagged with
3
votes
0answers
33 views

Changing Map Tip popup direction dynamically

Is there a way to dynamically (or semi-automatic) change direction of a popup? Default direction is 'right-down', which in some cases, where hovered feature is at the bottom of a canvas, Map Tip is ...
2
votes
0answers
92 views

Integrating WinPython Spyder with QGIS?

I'm using Winpython 3.6.7 and I want to create a standalone application using QGIS 3.4.11. When I append the QGIS path using the sys module, nothing happens. import sys sys.path.append("C:\OSGeo4W64\...
1
vote
2answers
83 views

Select features within an envelope in PyQGIS

I am trying to select (point) features within an envelope (buffer) of the start point of a line feature. I have line_layer = QgsProject.instance().mapLayersByName('DSC_Roads')[0] chainage_layer= ...
2
votes
0answers
27 views

Force virtual layer to based on layer's filter (query builder) [closed]

I have a layers, which are filtered by query builder. Next I want to create virtual layer (VL), that is based on that filtered layers. Sadly, I'm getting VL with all features from the layers. Query ...
0
votes
0answers
26 views

/{z}/{x}/{y} Template for QgsRasterLayer in PyQgis3

I took the following code which works in QGIS2 and changed QgsMapLayerRegistry to QgsProject for QGIS3. Running the code in QGIS 3.8.3, the layer is created, but the tiles do not display. The Scale ...
1
vote
1answer
33 views

QgsVectorLayer error empty

I try to develop an app using QGIS Api. My code looks like this (it's an app with a gui) : QgsApplication.setPrefixPath("C:\OSGeo4W64\apps\qgis", True) qgs = QgsApplication([], True) qgs.initQgis()...
0
votes
0answers
31 views

QgsVectorDataProvider addFeatures doesn't take attributes

I'm trying to add features in empty QgsVectorLayer with addFeatures, I got the layers without attribute: def create_features(input_file, wid, hite, focal_lgth): features = [] filename_def = { ...
1
vote
0answers
17 views

PyQgis 3 Script for PDF Exporting not showing map?

Im writing this script for exporting PDFs, I managed to get an output PDF as I wanted but its not showing the Map window. If i get into the Composer, the map is blank but magically refreshes and shows ...
2
votes
1answer
30 views

Error when creating script: QgsExpressionContextUtils not defined

This is the piece of code that is failing: ##nomenclatura = string '1.1.E.3.52' ##pdfOutput = output string from qgis.core import QgsProject project = QgsProject.instance() QgsExpressionContextUtils....
1
vote
1answer
53 views

Joining PyQGIS script parts

On my way to find a solution to This Question, I´m trying to merge some automatic generated script with This example. My thought is that after the last step, I could insert the script that does ...
4
votes
1answer
166 views

How to fix the error '_core.QgsProcessingException: There were errors executing the algorithm.'

I am trying to get the overlapping features between two layers in a loop. This works fine in most cases but raises an exception in some cases. The exception traceback does not even give any hint what ...
1
vote
0answers
46 views

Adding layers to project from a processing tool in QGIS3

I'm trying to add some layers created during a process to a project. There seems nothing to be added (TOC empty) but when I close QGIS It says: This project includes one or more layers as ...
1
vote
0answers
64 views

PyQGIS console error in QGIS 3.8.2

I have problem with python console in QGIS. Traceback (most recent call last): File "C:\PROGRA~1\QGIS3~1.8\apps\Python37\lib\code.py", line 90, in runcode exec(code, self.locals) File "",...
2
votes
1answer
197 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/...
3
votes
3answers
156 views

How to load external files in PyQGIS?

I have lots of models in QGIS 3.8. I´m translating them to Python scripts to still use in the Tollbox but qith reduced processing time. Using the QGIS automatic "export model as Python script", I´m ...
2
votes
0answers
59 views

Getting layers path in Layer properties window in QGIS 3.4 by PyQGIS?

I'm going to know how I can get layers full path in table of contents in QGIS3.4 when my QGIS is closed and it's running such as daemon? Rememebr: my shapefiles are in some different folders. This ...
3
votes
2answers
53 views

Working with memory ouputs in PyQGIS3

I have the following code snippet I run in QGIS 3.4 which goes through a list of shapefiles (my_wild) and runs a polygon to lines process. It performs the process and adds them to the map as expected, ...
2
votes
1answer
147 views

Change Output name in Script - QGIS 3

I exported a model as script using the properly option in QGIS 3.8. The Script works perfectly, but the output name is changed. Heres a print of the model: I want that the script´s output name, from ...
3
votes
2answers
55 views

Setting new size for printLayout using PyQGIS

I am trying to create an A0 layout from PyQGIS. I tried the following code but it doesn't work. from qgis.core import * manager = QgsProject.instance().layoutManager() layouts_list = manager....
1
vote
0answers
45 views

RuntimeError occurs randomly on pyqgis loop

I wrotee a loop in pyqgis 3 to apply processing to each polygon of a layer. Apparently randomly, a RuntimeError occurs and crashes my script. Here is the loop part of my script, with the first ...
2
votes
1answer
45 views

How to get QGIS project title with PyQGIS?

I would like to get the project title with PyQGIS to use it as a parameter of a Python script.
2
votes
1answer
40 views

Writing log message in QGIS's script algorithms GUI tab for PyQGIS 3?

I want to write some log in the log tab of processing algorithm User Interface like this post but for QGIS 3 (PyQGIS 3). It seems that "progress.setText('Youpi')" does not work anymore. What's the ...
2
votes
1answer
84 views

PyInstaller and QGIS 3.4

Currently I am developping a standalone python app and I am now working on the packaging with PyInstaller. Configuration : OS : Windows 10 QGIS : 3.4.9 PyInstaller : 3.5 Pyinstaller correctly finds ...
0
votes
1answer
83 views

PyQgs: unresolved reference for QgsProject() and QgsVectorLayer()

In my code I'm using the classes QgsProject() and QgsVectorLayer(). However PyCharm gives me the following error: Unresolved reference 'QgsProject' Inspection info: This inspection detects names ...
2
votes
1answer
70 views

Saving layout template with PyQGIS?

I am searching for a way to save a layout as .qpt file, is that possible with PyQGIS and how?
2
votes
1answer
85 views

Load layer From Oracle using QgsDataSourceUri in QGIS3 always return Invalid Layer

I'm tring to load spatial layer from Oracle but when i called function QgsVectorLayer(uri.uri(), "LAYER" , 'oracle') it still inValid layer This is my code > def LoadFromOracle(tablename): > ...
1
vote
2answers
115 views

PYQGIS 3: Change layout scalebar item to a round scale (e.g. 1:5000)

I'm loading a layout template to a .qgs project and would like to set up the scale bar so that it has a round numeric scale (e.g. 1:5'000, or 1:25'000 but not 1:12'500). How do I do that? Here is my ...
2
votes
0answers
89 views

Unable to load layers created with Processing Toolbox PyQGIS 3

I figured out that besides from the python editor within QGIS, the layers that I'm creating with a Processing Toolbox are not saved and displayed in my .qgs projects. --> see image: 1) what I get ...
1
vote
1answer
78 views

PYQGIS 3: Save custom layout in .qgs project

I iteratively create .qgs projects, load different layers in them, create a layout and export the maps. The .qgs projects are created but when I open them, my custom layout is not there! Therefore it ...
1
vote
1answer
72 views

PyQgs tool that replaces layout text labels with attributes from an input table

In the Qgs Project is a csv table file with two fields and two features/Objects. The script I'm writing is supposed to replace two textlabels in my only open layout with the attributes in the second ...
1
vote
1answer
27 views

PyQgs: how to get a list of all textlabels in my Layout

I have a print layout with a bunch of items, two text labels among them. For the pluging I'm wrting right now I need a list with the two text labels. My initial idea was labels = QgsProject.instance()...
3
votes
1answer
68 views

Custom renderer crashes QGIS because “renderFeature” is called in a different thread

I am trying to implement a custom renderer with Python in QGIS. I have put together a small toy example based on the code from the Creating Custom Renderers section of the PyQGIS Cookbook. To get ...
0
votes
0answers
44 views

Pyqgis import non-spatial CSV to Qgs project

I'm trying to upload a .csv file to my QGIS project via Pyqgis. According to the following thread Using non-spatial CSV with PyQGIS it should work that way: uri = 'file///C:/Users/denni/Desktop/test....
1
vote
0answers
23 views

Using QGIS plugin that's designed for use in interface within PyQGIS?

I need to use a plugin that's designed for use within the QGIS interface in PyQGIS. For example https://github.com/dgoedkoop/joinmultiplelines works great but I want to run it within a script, so ...
1
vote
0answers
37 views

PyQGIS replace text label in Layout view by new text label from csv tabel

Currently, I'm stuck working on my first python plugin and hope to get some adivce here. The plugin should take a csv file (or .xlsx would be even better) which has two string columns. Column 1 has ...
2
votes
1answer
47 views

In PyQGIS can I get the total length of a road where it's broken up into segments?

In PyQGIS can I get the total length of a road where it's broken up into segments? In SQL I would run SELECT format_number(ROAD_ID,0) as Road_ID, ROAD_NAME as Road, format_number(Sum(st_length(...
1
vote
1answer
43 views

PyQGIS update field in line dataset when it is within a polygon

I am trying to update a field in a (Road centerline) table based on a value from another table when it is within a Polygon (Locality boundaries). Based on posts like QGIS layer.geometry.intersection()...
1
vote
1answer
27 views

PyQGIS changeAttributeValue not saving modified records

I've been trying to save some changes to the a dataset using PyQGIS but I can't see any changes even after closing/reloading the layer attribute table. I have tried a few different options but none ...
3
votes
1answer
213 views

Change vector layer symbology PyQGIS 3?

I'd like to change the symbology of my vector layer and can't figure it out how to read the documentation. I would like to have an polygone with an orange outline, a dashed fill style and an orange ...
2
votes
1answer
106 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
157 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
1answer
68 views

QGIS 3.4.2 on Windows: pyqgis 3 rule-visibility depending on scale

I have a plugin for QGIS 2.18. In QGIS 2.18 it was possible, to toggle the visibility of each of the 7 "sublayers" (see below) by python-code: symbol = QgsMarkerSymbolV2.createSimple({'name': '...
2
votes
1answer
77 views

Feature is snapped?

I try to detect, if a newly created feature is snapped according the snap options: def isSnapped(self,feat): try: snapper = QgsSnappingUtils(self.iface.mapCanvas()) snapper....
1
vote
1answer
38 views

Changing Layers Attributes in pyqgis

I am trying to change the attributes of a table in pyqgis. However, when finishing the changes, I cannot see them in the layer. I am using QGIS 3.8.1 Here is the simple version of my code layer....
3
votes
1answer
119 views

Get Layer's Raster Band Data in pyQGIS

In QGIS I am trying to read raster band data from a specific layer in my Python plug in. I can easily get access to the layer from the console with something like this. iface.mapCanvas().layers()[0] ...
1
vote
0answers
32 views

Issue with writing virtual layer as CSV in PyQGIS [closed]

I am trying to figure out why I can't write a in memory virtual layer to the file system. The folder exists QgsVectorFileWriter.writeAsVectorFormat(vlayer, r'c:\temp\xyz.csv', "utf-8", None, "CSV") ...
2
votes
1answer
86 views

Multipart geometry after pyqgis-3 intersection()

I'm trying to intersect two polygons with intersection() function of QgsGeometry (pyqgis-3). The problem is that the result is a multipart polygon instead a single part polygon and QGIS doesn't allow ...
2
votes
1answer
107 views

QGIS 3 export report in Python

In QGIS we have new layout type: Report. I didn't find tutoral to export this in PDF in Python. Where can I find Python code examples?
3
votes
0answers
158 views

PyQGIS script crashes QGIS 3 when remove a custom pluginLayer which has custom legend

I upgrade a 2.18 plugin to 3.4. PluginLayer has been refactored and I could not create a custom legend as simple as previous major version of QGIS 2 : QgsDefaultPluginLayerLegend was removed. Use ...
1
vote
1answer
71 views

Format Query statement for use in Virtual Layer query from PyQGIS

Based on QGIS: SQL query within python console to sum a column based on values of other two columns I am trying to write a script that will get the field names to use from PyQGIS but am having issues ...

1 2 3 4 5 8