Skip to main content

New answers tagged

1 vote

Easiest way for non-programmers to add my script to QGIS

You can make your script as plugin. By plugin "Plugin Builder 3" you can create a base for you plugin (and i higly reccomend you to use "plugin reloader" for you debuging). On QGIS ...
Dezmonder's user avatar
0 votes

Attach functions to QGIS processing algorithms

I found the answer to my question, and also a workaround once the "high road" answer kept crashing QGIS. The correct way (crashes QGIS) The "high road" way is to use the signals ...
Dror Bogin's user avatar
  • 3,555
0 votes

Easiest way for non-programmers to add my script to QGIS

Changing the path to the default script folder in the options for every user to a central location gives you easy control over which scripts are available, as well as the users easy access via the ...
Erik's user avatar
  • 16.5k
1 vote

QGIS 3 Python script don't iterate through raster layers in print composer and saves only one raster layer with different years

I see a couple of issues. Nowhere are you updating the layer in the map item of the layout. So, it continues to display only what is on your current map canvas. The lines of code at the bottom, that ...
Matt's user avatar
  • 17.6k
0 votes

How to import other scripts in the same folder?

You can prepend the directory where interfaceParam.py is saved to your PATH and then import the script. In the example the interfaceParam script is imported under the namespace ip. import sys sys....
Matt's user avatar
  • 17.6k
0 votes

Get signal on layer scale based visibility changed in PyQGIS

The scale is a function of the canvas. Layers don't have a scale. The layer can be displayed in a canvas at a particular scale. QgsMapCanvas (which in a plugin can be accessed through iface.mapCanvas()...
couteau's user avatar
  • 96
1 vote

QGIS crashes when I set the labels

You can't use the same QgsVectorLayerSimpleLabeling instance to label two different layers. You currently have: edificiIdonei.setLabeling(etichette) terrFiltrati.setLabeling(etichette) I suspect ...
couteau's user avatar
  • 96
0 votes

Exporting several layers as GeoPackages at the same time in QGIS

There's a 'Save vector features to file' tool and in my case the expression that I used to batch name the outputs was this: file_path( @INPUT ) || '\\' || left( base_file_name( @INPUT ),11) || '...
DannyD's user avatar
  • 11
2 votes
Accepted

"Enable" custom icon to give it QGIS' default white border

try action_start.setCheckable(True) when you create the action and then when you want the associated button to appear checked, action_start.setChecked(True). If your action is showing/hiding a ...
couteau's user avatar
  • 96
0 votes

Creating a 'group' or 'menu' in QGIS of multiple plugins

What you've shown in the embedded image is the Processing Toolbox, which is a QDockWidget containing a QTreeView showing the installed processing algorithms in a tree-structured menu. You should not ...
couteau's user avatar
  • 96
0 votes
Accepted

Load results of split vector tool into group using PYQGIS

path = pathlib.Path(results['output_folder']) group = QgsProject.instance().layerTreeRoot().addGroup("New Group") for f in path.iterdir(): if f.is_file() and f.suffix == ".gpkg&...
couteau's user avatar
  • 96
0 votes

Sublayer from a Geopackage file shows as geometrytype 0 (unknown), but it contains points. It doesn't show the points either. How do I fix this?

Geometry columns in GeoPackage layers can be created to hold a specific type of geometry or they can be created with the generic “GEOMETRY” type, in which case they can hold any type of geometry. See ...
couteau's user avatar
  • 96
1 vote

Make the legend that auto wrap in QGIS

Expression Builder has a wordwrap function that you can use to wrap text in a legend (including it's elements). Example: wordwrap(@symbol_label, 37, ' ')
Comrade Che's user avatar
  • 7,271
0 votes

Running script converted from PyQtDesigner on PyQGIS

When using the Python console, it seems that the __name__ variable is set to "__console__", even if you execute a script. I guess you're just testing in the console, so you could just change ...
SirLostalot's user avatar
0 votes

How to import other scripts in the same folder?

you can try: from . import interfaceParam, bufferBuilder, clipping, graphicBuilder, endDialog remove ".py" and using point as current directory. Also: from {your plugin name} import ...
Dezmonder's user avatar
0 votes

Reading Excel file using PyQGIS

As it says in the xlrd documentation: This library will no longer read anything other than .xls files. Hence working with the xlrd Python package while reading Excel files can lead to the following ...
Taras's user avatar
  • 33.3k
0 votes

Deleting GeoPackage vector layers and releasing open file handles with PyQGIS

You might need to provide more of your code -- specifically, where are you attempting to overwrite the file. At first glance, I suspect that the reason the file is remaining open is that calling ...
couteau's user avatar
  • 96
0 votes
Accepted

Creating QGIS projects with iteration using PyQGIS - Problem with the location of layers added

I fixed the problem by adding project.setCrs(QgsCoordinateReferenceSystem(2100)). The code is presented below: [...] project.setCrs(QgsCoordinateReferenceSystem(2100)) project.write(path_project) ...
Ilias Machairas's user avatar
2 votes
Accepted

Optional argument has wrong value when used with action trigger

It happens because the triggered signal passes the value of the QAction’s checked state to any connected slots. Your slot is receiving that value, which is false by default. Because the signal is ...
couteau's user avatar
  • 96
1 vote
Accepted

QGIS Python Get and layout item's Uuid

Layouts do not have a uuid. The layout manager can return a list of layouts, so you can use the index of that list to target them instead E.g.: manager.printLayouts()[0]. The list should be in the ...
SirLostalot's user avatar
0 votes

How to get selected indexes of a QgsAttributeTableView

I'll try to ilustrate the situation with my case, constructing dialog for a plugin on QGis. First, to get the signal is necessary connect the method to table view element in dialog: self.dlg.view....
giofronza's user avatar
0 votes

QGIS Multi-Basin Delineation (Pour-Point) Hydrology

The watershed tool and related functions from Whitebox would potentially be of use. The watershed tool specifically takes a set of points as outlets. https://www.whiteboxgeo.com/manual/wbt_book/...
Rob's user avatar
  • 183
3 votes
Accepted

Custom panel is created but does not display properly in custom plug-in

This short snippet is working for me (QGIS 3.34): from qgis.utils import iface dock_widget = QDockWidget("DockWidgetTest", iface.mainWindow()) label = QLabel('Test') dock_widget.setWidget(...
juliustoth's user avatar
0 votes

QGIS plugin: Problems importing resources (resources_rc) file - plugin doesn't load - PATH problems?

To complement Worth Lutz answer, you can replace " <include...>" from <your_base>.ui file editing __init__.py file class factory: import os def classFactory(iface): file_dir ...
giofronza's user avatar
0 votes

How to add OpenStreetMap layer as bottom layer via QGIS processing script

You can try not adding your layer as bottom, but to move it after adding. from qgis.utils import iface #your_layer = iface.activeLayer() ltv = iface.layerTreeView() ltv.setCurrentLayer(your_layer) ...
Dezmonder's user avatar
2 votes
Accepted

Layers corrupted after saving, closing and opening of QGIS project with PyQGIS

I had missed adding the layer to the project, so it wasn't truly part of the project, it just appeared to be. The answer was to add the layer to the project without rendering it, and then add the ...
John_nz's user avatar
  • 41
0 votes

How to get User and Password of a PostGIS layer from PyQGIS

In QGIS3 you can do the following: layer = iface.activeLayer() if layer.providerType() == 'postgres': uri = QgsDataSourceUri(layer.dataProvider().dataSourceUri()) password = uri.password()
juliustoth's user avatar
0 votes
Accepted

Attachments of ArcGIS Rest Server Layer in QGIS

I finally found a solution to my problem. I am using the openProject() macro in the Project Properties -> Macros section. It will query the self endpoint of the portal which describes the current ...
Bernd Loigge's user avatar
  • 2,940
1 vote

QGIS script keeps crashing

As @bugmenot123 commented, this sort of script is intended for use outside of QGIS, but I tested it externally and it still crashed, so: Try changing: qgs.exitQgis() To: qgs.exit() I have seen this ...
SirLostalot's user avatar
0 votes

Listen to parameter change to update other processing parameters in QGIS

Not exactly what you need, but at least part of it: you can copy the parameters as JSON to/from the clipboard with the “Advanced” button at the bottom left.
Florian Jenn's user avatar
0 votes

QGIS Raster Calculator via python: no substraction and division possible

The issue is in the expression. It is mandatory to put spaces for a correct interpretation of minus sign. You have: '(MIR@1-green@1)' instead of: '(MIR@1 - green@1)' As MNDWI is a normalized ...
xunilk's user avatar
  • 30k
1 vote

Automatically loading layers on startup (problem) using PyQGIS

After some time away from qgis scripts, this is the solution I found: Apparently, when you try to add a python script file to QGIS "add scripts to toolbox", it gets coppied to qgis scripts ...
Pedro Cury's user avatar
0 votes

QGIS raster calculator using Python console

Your code has two problems mainly. The first one is layers list. It is really a list of names; not a list of raster layers. There are problems referencing them properly with your approach in the loop. ...
xunilk's user avatar
  • 30k

Top 50 recent answers are included