Questions tagged [qgis-python-console]

Python console embedded in the QGIS GUI, which enables users to use the Python bindings for QGIS (PyQGIS) in order to interact with QGIS objects and functions.

Filter by
Sorted by
Tagged with
2 votes
1 answer
41 views

How to update QGIS display from script run in console

Working from the Python console in QGIS, I am trying to create an 'animation' of sorts by selecting one line after another in a layer with parallel lines, with a pause on each line. I've started from ...
marcp's user avatar
  • 895
1 vote
0 answers
28 views

QGIS raster calculator using Python console

I want to calculate sum values of many rasters (from input folder) in QGIS Python using raster calculator. When I run script, QGIS crashes: Windows fatal exception: access violation import os from ...
user238054's user avatar
2 votes
2 answers
106 views

Use of automatically generated Python procedure

I asked a question some days ago (see Extent of a group of lines in a polyline shapefile) and got a nice answer that works: use aggregate procedure in the processing toolbox. Unfortunately, this ...
ClaudeVer's user avatar
  • 630
2 votes
1 answer
74 views

Loading WMTS raster of geoservice using PyQGIS

I have try a lot of PyQGIS lines codes to try to add any layer in WMTS from Geoservices using Python console in QGIS 3.34. Geoservice site: https://geoservices.ign.fr/services-web-experts-ortho Layer ...
Vincent Bénet's user avatar
2 votes
2 answers
151 views

Calculating information for selected parts of the polygon with PyQGIS

I have a polygon that is formed using Quick OSM. After that, I add an area calculation field to it, automatically using the QGIS tools. How can I use PyQGIS to get the sum of the areas of the ...
Чайный Бублик's user avatar
2 votes
1 answer
61 views

Exporting messages in Python Console with PyQGIS

I want to export the messages that appear on the Console Python (for example this below) using a script: But I can't find a way to store it in a txt file. Any suggestion?
freecma80's user avatar
  • 103
1 vote
0 answers
36 views

Running c++ executable file from python console in QGIS

I am trying to run a simple c++ program which I have already compiled from python console in QGIS3.32 My goal is to take the output of the C++ program which is nothing but adding 2 numbers, printing ...
BenStone's user avatar
  • 333
3 votes
1 answer
66 views

Run processing tools in Python console

I have created two scripts for my QGIS project. I need to do a manual step after the first script for the second script to work. The second step involves a QGIS tool called "join by nearest"....
pyjamajedi's user avatar
0 votes
0 answers
17 views

How can this error be handled while trying to add an hdf file to QGIS as a raster layer through its in-built Python console?

I have downloaded a file named "MOD13A2.A2015033.h25v08.061.2021319043521.hdf" to my Downloads folder (I am running my QGIS on Windows) and wrote the following code: raster_layer = ...
The Testosterone Fanatic's user avatar
1 vote
1 answer
106 views

Simple script is working in Python console but gets error in Script Editor (PyQGIS)

This simple script retrieving a value of raster pixel size works in Python console, but can't be processed in Script editor: "No script found. Seems there is no valid script in the file." ...
vkrk's user avatar
  • 11
0 votes
0 answers
43 views

GDAL Rasterize over attribute (rewriting raster issue) in QGIS

I'm trying to process gdal:rasterize_over in QGIS Python console. The same problem persists - this function is rewriting the input sample raster instead of making a new one as output. I've tried (look ...
vkrk's user avatar
  • 11
0 votes
0 answers
71 views

AttributeError: NoneType

I have this code I use in the QGIS Python console. I used it a few days ago and it worked, but I tried using it again and I got this error: Traceback (most recent call last): File "C:\PROGRA~1\...
Gabriel Mulero's user avatar
0 votes
1 answer
116 views

Python script run error QGIS

I have been using the Python console in QGIS to develop a script. However, I keep getting the below error whenever I try to execute it. This is line 43 which has the error
Alaa Torkey's user avatar
0 votes
0 answers
31 views

Changing Fontmarker Size Expression in QGIS 3.28 using Python Console

I am currently working on a geology and mineral occurrence map in QGIS 3.28. I have a vector rule-based layer in which mineral deposits are classified with different symbols. Some of these symbols ...
Iven Pepa's user avatar
  • 341
0 votes
1 answer
47 views

Unable to get road length using osmpy

I'm really struggling to get road lengths for my polygon. I'm new to python and QGIS and my script, while successful, doesn't return anything. I've installed osmpy and in the python console within ...
Jim Jimson's user avatar
2 votes
1 answer
175 views

NameError: name '__file__' is not defined when getting the path of the current script using PyQGIS

I am trying to run a script in the QGIS Processing Script Editor, but I get the following error: If I run the script from the PyQGIS console it works thanks to this changes in the console_editor.py (...
hrd's user avatar
  • 33
0 votes
1 answer
111 views

Clipping raster by specific polygon in layer using PyQGIS in Python Console

I have one raster and one vector layer and I need to clip raster by each specific feature (polygon) from vector layer. So basically I need array of vector layers. Only answers I found is to mask by ...
Tomislav Muic's user avatar
0 votes
1 answer
23 views

How do I use 'grass7:v.net.spanningtree' from the QGIS python console?

Assume there are map layers named filtered_edges and points. I have written the following in the QGIS python console: import processing fe = QgsProject.instance().mapLayersByName('filtered_edges')[0] ...
bj3t's user avatar
  • 45
0 votes
1 answer
53 views

Copying data from one attribute to another with Python in QGIS

I'm trying to update an attribute in a layer in QGIS with data from a joined field in the same layer. I have looked at a few different instructions and tutorials, but for some reason I can't get all ...
eastwing_imh's user avatar
2 votes
0 answers
78 views

Using from qgis.gui import * in QGIS standalone application

I have QGIS 3.28.7 installed on my computer and in its Python Console this command works: from qgis.gui import * I tried to use it in some Python IDE's. For example, in Spyder. The following paths ...
eug100's user avatar
  • 63
2 votes
0 answers
216 views

Running QGIS Plugins in Python console

I usually use Python console in QGIS to run frequently used processing algorithms. This time, I wish to use one of the QGIS plugins (plugin named QNEAT3) and I have downloaded it. I am able to use it ...
Swathi Venkatesh's user avatar
4 votes
0 answers
58 views

How to search within the QGIS python console?

In the QGIS 3 Python console, there are often lots and lots of messages printed out as various QGIS/PyQGIS functions run. Is there a way to search for a specific word or phrase in this message window?...
tinlyx's user avatar
  • 11.1k
0 votes
0 answers
16 views

Error when trying to edit shapefile in QGIS python console [duplicate]

I am trying to edit a given shapefile in QGIS 3.x using the python console. Here is the code: from qgis.core import QgsField, QgsExpression, QgsFeature from qgis.utils import iface from PyQt5.QtCore ...
Deasy_pi's user avatar
2 votes
1 answer
172 views

Opening QGIS Python console from Linux command prompt

I am trying to run on a remote Linux cluster a PyQGIS python script I wrote, after managing to run my script locally, but I am having trouble setting up things in the Linux server. To run the script ...
CSG_10's user avatar
  • 21
1 vote
0 answers
33 views

QGIS python console "Could not create output"

I'm new to the python console in QGIS and am trying to automate some raster calculations. Below is the code I'm using. I've already changed the path to forward slashes, but when running the script it ...
Eline's user avatar
  • 11
0 votes
1 answer
77 views

QGIS Python console in bottom dock

For some time (can't state exaclty when, why or what I've done) I have a weird behavior of the python console. Persistantly, it opens in a floating window like this ... ... wich really annoys me. I ...
Jochen Schwarze's user avatar
2 votes
1 answer
317 views

Simple PyQGIS code working in QGIS python console but not in Python plugin

I wrote a python plugin whose purpose is to import a raster and put it in a group. My code works perfectly when I run it in the Python console of QGIS, but not when I run my plugin. The code is ...
ZKB's user avatar
  • 1,154
3 votes
2 answers
367 views

QGIS save selected layers to shapefiles by python console

I wrote the code below to save selected layers in the layerTree to a folder by Python, some of them are temporary layers, I don't know if it matters, and my main purpose is to save those temporary ...
LEI's user avatar
  • 65
6 votes
1 answer
120 views

Calling "Remove empty layers" plugin from the Python Console in QGIS

I've stumbled upon a great plug-in called "Remove empty layers", developed by @Germán Carrillo. I'm wondering if it's possible to use this plug-in in the Python Console.
Tobias Bowley's user avatar
2 votes
0 answers
127 views

Can I make QGIS Python console autocompletion work for imported libs?

In the QGIS Python console there is code completion available since a while (see here). However it seems to be quite limited as to its range, according to the doc the following libs are supported: ...
Honeybear's user avatar
  • 2,386
0 votes
0 answers
60 views

Multiple aggregate calculations by field value

I want to count the number of geometries on Layer B within 30m of the geometry on Layer A. How can I repeat the calculations in the Field Calculator multiple times, so that I have a count for each ...
osakanatengoku's user avatar
0 votes
1 answer
236 views

How to import multiple .csv files as .shp into Qgis with CRS and z [closed]

I am trying to load multiple (50) .csv files to Qgis as shp layers. My files are in a specific CRS (EPSG: 32642) and are points in z,y,z. I first looked for a plugin to do this and then decided to do ...
tukanium's user avatar
  • 192
0 votes
1 answer
88 views

How to start reading shapefile in QGIS using python console? [closed]

How do I start reading shapefile using Python console in QGIS? I am sharing the script that I am trying to follow, however, it gives me an error.
Hasan's user avatar
  • 55
0 votes
1 answer
199 views

Python console: Error processing when file is saved however with a temporary output there is no problem

I am trying to execute a very simple raster calculator code in the python console: processing.runAndLoadResults("qgis:rastercalculator",{'EXPRESSION':'\"Sentinel2_Image2_NDVI@1\"&...
GISJess's user avatar
  • 125
0 votes
1 answer
204 views

QGIS Plugin: Copying in Python console script into the QGIS plugin

I have a working Python console script and have created a plugin (processing provider through the plugin builder). Now I want to put the python console script into the plugin. Can I simply copy and ...
GISJess's user avatar
  • 125
2 votes
1 answer
444 views

Generating discrete legend labels instead of default maximum and minimum label on single bar - QGIS 3.18 to 3.22

Question: I used a python script in QGIS 3.16 to generate a raster and subsequently a print layout with legends. I am trying to use the same script to build the print layout in QGIS 3.22. However, ...
Ashish AJ's user avatar
4 votes
1 answer
145 views

Showing editor by default in QGIS Python Console

I use startup.py file in folder %AppData%\QGIS\QGIS3 to open the Python Console at QGIS start. Is there a way to also show the editor? I browsed a lot of pages in the API, but didn't find the answer. ...
ThiPa's user avatar
  • 649
3 votes
1 answer
524 views

Calculating NDVI using QGIS Python Console

I'm going to calculate NDVI using band 4 and band 3 of Landsat 5. The code I wrote: import os, re import processing from osgeo import gdal input_B4 = r'C:\Users\test\...
bsg's user avatar
  • 467
3 votes
1 answer
254 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 ...
MiroD's user avatar
  • 67
2 votes
0 answers
117 views

How to perform CRS Transformation to layers from the built-in python console in Qgis?

I'm trying to automate some tasks in Qgis, using the built-in python console. I have around 20 layers with different CRS, which I would all like to have the same one. I'm not sure how to approach this....
Niek's user avatar
  • 95
6 votes
2 answers
823 views

Adding points with coordinates delimited by commas from CSV file in QGIS Python Console

I can't figure out how to add point from a CSV file with the Python Console. This is my CSV file: UTM32_E;UTM32_N 562834,932;8762874,054 560758,523;8762624,904 562483,074;8762760,832 562131,643;...
Meije3984's user avatar
  • 155
0 votes
0 answers
89 views

Difference between processing script editor and Python console when using PyQGIS

I am a PyQGIS beginner. I'm having trouble to understand the difference between running and writing a Python script from the Python console and from the processing script editor. So far, I've seen ...
Pyqgis_beginer's user avatar
1 vote
0 answers
111 views

Is it possible to run grass v.generalize as part of a separate console (ie not inside QGIS)

As per the documentation : There is not a processing console in QGIS, but all processing commands are available instead from the QGIS built-in Python console. That means that you can incorporate ...
James Dupont's user avatar
1 vote
0 answers
51 views

Address open Layer in QGIS project by processing script, convert Python console into a processing script

I created this code in the Python console, a new point layer is created with some attributes and set into edit and AddFeature mode. I would like to bring it in QGIS algorithms. I have tried a few ...
miraculix's user avatar
  • 169
5 votes
1 answer
357 views

Removing extra space at top of the legend in print composer from Python console in QGIS

I have a legend with no title but there is still a large white space above the layer/subgroup title that I would like to remove. I tried using legend.setTitle("") and legend.setStyleFont(...
ia200's user avatar
  • 367
1 vote
0 answers
83 views

Executing PyQGIS scripts from .bat file to control open instance of QGIS

I'm trying to run PyQGIS scripts via a 3rd party program, to perform actions to layers inside an open QGIS instance. I'm able to have the outside program shell and execute a bat file to run them. I'm ...
Kaizen777's user avatar
1 vote
2 answers
198 views

QGIS "Convert lines to polygons" Tool loses geometry in the Python console but not through the interface

I have found a bug with the "convert lines to polygon" tool of QGIS and would like to know if the bug is known and if there is a workaround? I want to convert my MultiLineString Z to ...
Muesgen's user avatar
  • 65
3 votes
2 answers
293 views

Export Project to DXF dialog using Python

I'm trying to run 'Export Project to DXF' in QGIS using the Python console. The intention is to export multiple vector layers, as defined by a Theme Visibility State, in the same way as if you ...
kelvin's user avatar
  • 33
3 votes
2 answers
586 views

Create a point layer from CSV using Python console in QGIS?

I'd like to transfer manual processing steps to a python script. Though I'm not used to python yet. The steps I do in QGIS: Loading csv via right click in browser window into layer window. the loaded ...
mymymy's user avatar
  • 175
1 vote
1 answer
3k views

Installing Python module using pip via Python console in QGIS 3.22

Import module pip not works: import pip Traceback (most recent call last): File "C:\OSGeo4W\apps\Python39\lib\code.py", line 90, in runcode exec(code, self.locals) File "<...
Wenceslauw's user avatar