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
46 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 ...
  • 21
1 vote
0 answers
17 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 ...
  • 11
0 votes
1 answer
30 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 ...
3 votes
1 answer
108 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 ...
  • 1,114
3 votes
2 answers
150 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 ...
  • 65
6 votes
1 answer
108 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.
2 votes
0 answers
45 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: ...
  • 1,632
0 votes
0 answers
32 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 ...
0 votes
1 answer
87 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 ...
  • 142
0 votes
1 answer
46 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.
  • 55
0 votes
1 answer
95 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\"&...
  • 115
0 votes
1 answer
94 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 ...
  • 115
2 votes
1 answer
161 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, ...
0 votes
0 answers
36 views

Using SpinBox in raster calculation

I wrote this code in QIS plugin to subtract the ex_value of a spinBox from raster if the Raster value is higher than the max value from the spin Box. but the error message is('QSpinBox' object is not ...
4 votes
1 answer
108 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. ...
  • 565
3 votes
1 answer
259 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\...
  • 467
3 votes
1 answer
146 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 ...
  • 67
2 votes
0 answers
64 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....
  • 95
6 votes
2 answers
496 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;...
  • 125
0 votes
0 answers
69 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 ...
1 vote
0 answers
56 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 ...
1 vote
0 answers
44 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 ...
  • 169
5 votes
1 answer
245 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(...
  • 325
1 vote
0 answers
65 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 ...
1 vote
1 answer
150 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 ...
  • 65
3 votes
2 answers
185 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 ...
  • 33
3 votes
2 answers
342 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 ...
  • 175
1 vote
1 answer
2k 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 "<...
0 votes
0 answers
106 views

Joining Layers with PyQGIS [duplicate]

I need to make a LEFT JOIN (using a Python QGIS script) between two layers: a shape (point): s_node a csv (table): t_infos Can you show me how to do that? The result (the joined layers) has to be in ...
  • 604
5 votes
1 answer
557 views

Adding Yandex Satellite TMS via QGIS Python console

I add a TileMapService layer to QGIS map window using a Python console. But added layer is not displayed. What is wrong? tmsLayer_name = 'YandexSat' uri = "url=http://sat04.maps.yandex.net/tiles?...
2 votes
0 answers
660 views

QGIS says Python is not supported and cannot access plugins or console

Following the recent PSA recommending users to upgrade from 3.16.12 to 3.16.13 (link), I've been having trouble accessing my plugins and Python console ever since upgrading. I've done some digging and ...
2 votes
1 answer
54 views

Sum of raster file in QGIS using Python Console

I have 8760 raster file for the precipitation in the netherlands on hourly base, from the first day of the year (01.01.2020) till the last hour of the year (31.12.20). What I have to do with these ...
  • 21
3 votes
1 answer
465 views

Converting multiple MapInfo tab files to shapefiles using PyQGIS and GDAL

I am trying to put together a script to convert multiple (>50) Tab files into shapefiles. I am planning on executing this through the python console in QGIS 3.8.1 When I run the below code all I ...
  • 31
0 votes
0 answers
30 views

Finding mean and stdDev of vector layer field using PyQGIS [duplicate]

I am going to standardized a vector layer field in Python console in QGIS, for that I want to get mean value and stdev value of the field. How do I find mean and stdev in using PyQGIS. I tried this. ...
6 votes
2 answers
351 views

Invalid syntax in expression using PyQGIS

I am trying to calculate VCI using NDVI values in QGIS Python Console. I am getting invalid syntax for my expression. layer1 = NDVI_layer layer1 = iface.activeLayer() idx = layer1.fields()....
1 vote
1 answer
317 views

Recursively Load Shapefiles from Directory Structure Based on Name Pattern using PyQGIS

I have a directory repository which contains multiple subfolders, which themselves contain multiple sub(sub)folders. Inside the subfolders or sub(sub)folders there are shapefiles. I am looking for a ...
8 votes
1 answer
283 views

Calling Rotate Feature tool from QGIS Python Console

To rotate feature(s) in QGIS you need to be in editing mode, select one or more features then use 'Rotate Feature' tool present inside Advanced Digitizing Toolbar: But how can we call this action ...
1 vote
1 answer
284 views

QGIS / Python - Select features until the cumulative sum target is reached

I have a polygon feature of municipalities with the value of production of some good in the attribute table field production. I need to know which are the municipalities with the lowest production ...
  • 279
0 votes
0 answers
221 views

PRISM gridded (.bil) file to county(.csv) conversion

I want to convert PRISM gridded temperature data from .bil to US county-level in CSV format. All together I need to do this for all daily files from 1981-2019. I am writing the following Python code ...
2 votes
0 answers
262 views

Retrieving data from PostgreSQL and importing it as layer in QGIS Python Console

I am trying to write a piece of code to query and then import a subset of a PostgreSQL as a vector layer onto the map. I am able to connect and add the whole SQL table into QGIS. But I am not sure how ...
0 votes
0 answers
283 views

Live data on QGIS Cloud?

I have a line layer that is rulebased labeled to show green segments and red segments based on 'status' attribute. Currently, I download data from an excel sheet on sharepoint as a csv and then import ...
  • 195
1 vote
2 answers
671 views

Creating rectangles from CSV coordinates via Python console in QGIS

As of v3.10, there is an asPolygon method for qgis.core.QgsRectangle. This runs: QgsRectangle(1804512.8556, 5453390.58088, 1813512.8556, 5461390.58088).asPolygon() However, no vector data (i.e. an ...
  • 389
2 votes
1 answer
554 views

Shortcuts in QGIS's Python Editor

I want to be able to: Run Run Selected in python editor using shortcuts. It does not seem possible under Settings - Keyboard shortcuts. Is there any way?
  • 60.9k
2 votes
2 answers
215 views

QGIS crashes when using Interpolation (TIN) from Python Console in QGIS, but works well when using GUI

QGIS 3.16.5 seems to crash when I use the following code block in the QGIS console. However, there seems to be no issue at all when clicking through the same options using the GUI. The TIN ...
0 votes
0 answers
29 views

Creating a roughness ASCII file from a raster dataset [duplicate]

I'm trying to create a roughness file (derived from topography) in the ASCII format for a European raster dataset. This dataset is from the EEA. I've already made an ASCII grid file of the raster data ...
  • 1
1 vote
1 answer
99 views

Conducting operation to shift DEM tilted on Z axis using PyQGIS

I have two DEMs of a stream channel created with photogrammetry from different times. One of the DEMs used ground control points and is georeferenced correctly. The other model did not use ground ...
4 votes
1 answer
1k views

Running my Python script from outside the QGIS Python Console

I have a Python script that runs in the QGIS Python console but I would like to run it outside of the console, so that a map can be created without having to be within QGIS. The script runs perfectly ...
  • 193
4 votes
1 answer
585 views

Configuring QGIS for external editor

The editor pane in the python console has a button "Open in External Editor". How do I tell QGIS what program to use as the external editor?
  • 5,781
2 votes
2 answers
911 views

Refreshing map canvas in for loop in QGIS 3

I have a console script where I'm trying to iterate through saved bookmarks from the open project to have the map pan/zoom to the bookmark extent. I would like to eventually save each map canvas as ...
0 votes
2 answers
264 views

Getting records from attributes table in Python console using PyQGIS [closed]

I have layer with 5 millions records. I would like to get 1 record from attributes table and show in Python console. Is it possible? This does not work: > from qgis.core import QgsProject, ...