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
37 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 ...
user avatar
  • 47
2 votes
0 answers
31 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....
user avatar
  • 75
6 votes
2 answers
126 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;...
user avatar
  • 115
0 votes
0 answers
41 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 ...
user avatar
1 vote
0 answers
24 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 ...
user avatar
1 vote
0 answers
37 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 ...
user avatar
  • 159
0 votes
0 answers
32 views

How to colorize several raster layers using PyQGIS

I am using QGIS v. 3.22.4 on Ubuntu Mate 20.04. I am trying to colorize a bunch of raster layers (black and white) according to some parameter, so I want to automate this procedure with the python ...
user avatar
5 votes
1 answer
125 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(...
user avatar
  • 175
1 vote
0 answers
28 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 ...
user avatar
1 vote
1 answer
83 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 ...
user avatar
  • 53
3 votes
1 answer
64 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 ...
user avatar
  • 33
3 votes
2 answers
90 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 ...
user avatar
  • 165
1 vote
1 answer
398 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 "<...
user avatar
0 votes
0 answers
59 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 ...
user avatar
  • 1
5 votes
1 answer
170 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?...
user avatar
1 vote
0 answers
196 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 ...
user avatar
2 votes
1 answer
33 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 ...
user avatar
  • 21
0 votes
0 answers
27 views

Retrieve database path for using processing.run(INPUT: ...) inside the QGIS python console

I am creating a Python script inside the QGIS Python console for the automation of creating a buffer, clipping over multiple layers, and fixing geometries. The layers are in the PostgreSQL database. ...
user avatar
3 votes
1 answer
131 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 ...
user avatar
  • 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. ...
user avatar
6 votes
2 answers
206 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()....
user avatar
1 vote
1 answer
92 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 ...
user avatar
1 vote
1 answer
187 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 ...
user avatar
  • 237
2 votes
0 answers
150 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 ...
user avatar
0 votes
0 answers
183 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 ...
user avatar
  • 175
1 vote
2 answers
260 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 ...
user avatar
  • 369
2 votes
1 answer
267 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?
user avatar
  • 51.4k
2 votes
1 answer
124 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 ...
user avatar
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 ...
user avatar
  • 1
1 vote
1 answer
65 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 ...
user avatar
4 votes
1 answer
816 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 ...
user avatar
  • 173
3 votes
1 answer
323 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?
user avatar
  • 5,306
1 vote
2 answers
591 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 ...
user avatar
0 votes
2 answers
109 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, ...
user avatar
2 votes
1 answer
332 views

PyQGIS problem to find the path of the Python script

I have two Python scripts. The main script import the second script test_credenziali.py (main script) #!/usr/bin/env python # coding=utf-8 # Copyleft Roberto Marzocchi - Gter srl Innovazione in ...
user avatar
4 votes
1 answer
106 views

Making Voronoi polygons using Python Console of QGIS

I am using QGIS 2.6.1-Brighton. Can you find errors in my attempt to make Voronoi polygons using Python Console and suggest improvements? I have tried the following scripts but got the errors. output=...
user avatar
0 votes
0 answers
66 views

How to run an exported QGIS program as a stand-alone application?

I have a research partner who exported their QGIS algorithm to a python script, and my job is to use that Python file to create a web application that provides access to that algorithm. My eventual ...
user avatar
8 votes
1 answer
593 views

QGIS: Is there a way to make the "Python Console" a separate window?

QGIS 3.10; Ubuntu 18.04 When Plugins->PythonConsole is accessed, it opens as a panel, changing the shape of the map canvas. Can it be a separate window instead? Alternatively, is there a way to run ...
user avatar
  • 299
-1 votes
1 answer
327 views

Getting path of file saved in memory or as temp file using PyQGIS

Whenever I do something like buffer in QGIS with Vector >> Geoprocessing Tools >> Buffer... the source output I get for my temporary file looks like this: That works fine if I'm doing ...
user avatar
1 vote
1 answer
703 views

Loading GeoDataFrame as QGIS vector layer without exporting to shapefile

I'm using Python console in QGIS to manipulate geospatial data using geopandas. I want to load the output (GeoDataFrame) to the canvas as vector layer directly without exporting it to a file first. Is ...
user avatar
  • 107
1 vote
2 answers
1k views

ModuleNotFoundError: No module named 'colour' in QGIS Python Console

I'm trying to run a Python script in QGIS which imports the colour module. However, when I run it via the Python console in QGIS, I receive the ModuleNotFoundError: Python Console Use iface to access ...
user avatar
  • 21
0 votes
2 answers
415 views

Python console call HCMGIS "Centerline in polygons' gaps"

I use QGIS 3.10 (Python 3.7 via the console) and want to automate a few processes through a Python script (I'm a beginner in programming with Python). I have a layer with many polygons ('polygons') ...
user avatar
2 votes
1 answer
355 views

Errors while importing QGIS 3.10 from standalone Python, but not from QGIS's Python Console

I try to load a QGIS project in standalone Python on Windows 10. This is the code that I use: from qgis.core import * qgs = QgsApplication([], False) QgsApplication.setPrefixPath("C:\Program ...
user avatar
  • 181
0 votes
1 answer
64 views

Online Courses to Learn Writing Custom Python Scripts / Plugins in QGIS? [closed]

I am looking for resources to learn writing Python Scripts / Plugins for QGIS. The Developer Cookbook is a good start, but I am specifically looking for a video-based resource that teaches with hands-...
user avatar
  • 1,385
4 votes
1 answer
155 views

Referenced table not found in standalone Python script

I'm trying to run a Python script from OSGeo4W Shell. Im doing this by typing "python-qgis C:\path\test.py" Everything seems to go fine until the script launches the processing module. After that ...
user avatar
  • 173
2 votes
1 answer
90 views

Using QGIS Python Console in QGIS

I'm pretty new to using the console and still have a lot to learn so this might come across as a really stupid question. I imputed this code into the console: counter = 0 # Set the path for the ...
user avatar
  • 21
1 vote
1 answer
101 views

QGIS Python Console SQL Server Layer Incorrect Attributes

I am using the QGIS python console to load a SQL Server layer in QGIS using the follow code: uri = "MSSQL:{MYSERVER};database={MYDATABASE};tables= MYTABLE};trusted_connection=yes" lpBatch = ...
user avatar
1 vote
1 answer
252 views

PyQGIS script for loading several .xyz files into QGIS gives NameError

I found a script for loading several csv files into QGIS and modified it for .xyz Data. Yesterday on one Computer it worked and today on a different Computer it's not working anymore. Is there ...
user avatar
  • 2,287
2 votes
0 answers
724 views

To Iterate through all layers and all attributes for each layer

I am working in the Python console in QGIS 3.10. I want to iterate through all layers and for each layer iterate through all attributes and set them all to 'Hidden'. I want to do this in ...
user avatar
1 vote
1 answer
274 views

urllib.request from console or py file

I tried a code to get attribute values from internet. Line by line from console the code worked well. As soon I was running it as Python file, QGIS crashed without comments. Trying commenting lines ...
user avatar