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
0
votes
2answers
29 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 ...
0
votes
0answers
29 views

A generalization to write better code in python QGIS python console (3.16) (for people with non-coding background) [closed]

1. Background The community here has tremendously helped me write and debug my code so far: from reading an ESRI shapefile to performing TIN interpolation, and generating (and saving) print layout ...
2
votes
1answer
71 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?
2
votes
1answer
37 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
0answers
25 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
vote
1answer
31 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 ...
3
votes
1answer
232 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 ...
3
votes
1answer
94 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?
1
vote
2answers
187 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
0answers
56 views

Display label attributes created in the GUI in QGIS Python Console for later use within PyQGIS

I want to define a label for a layer created dynamically in a Plugin with PyQGIS. I managed this, as there is a big amount of good examples you can find in the internet. When creating the symbology ...
0
votes
2answers
59 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, ...
0
votes
0answers
55 views

Couldn't open Manage and Install plugin for QGIS 3.14.16 Pi

This might be quite straightforward to resolve but as a beginner, I am unable to figure out what to do. Opening Manage and Install Plugins... or most other plugins such as Mergin returns an error ...
2
votes
1answer
108 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 ...
2
votes
1answer
50 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=...
0
votes
0answers
36 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 ...
8
votes
1answer
256 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 ...
0
votes
1answer
88 views

How do you get the path of a file you saved in memory: or as temp file with pyqgis

So whenever I do something like buffer in QGIS with Vecotr>>Geoprocessing Tools>>Buffer... the source output I get for my temporary file looks like this: That works fine if I'm doing more QGIS ...
1
vote
1answer
260 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 ...
0
votes
2answers
234 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') ...
2
votes
1answer
240 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 ...
0
votes
1answer
50 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-...
4
votes
1answer
95 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 ...
2
votes
1answer
54 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 ...
1
vote
1answer
75 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 = ...
1
vote
1answer
151 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 ...
1
vote
0answers
357 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 ...
1
vote
1answer
174 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 ...
4
votes
1answer
233 views

Using Boolean Parameter in QGIS Graphic Modeler

I am trying to create an if/else condition with a boolean parameter in QGIS graphic modeler. The parameter will be used inside Field Calculator2 algorithm.By default the parameter is False. I am ...
5
votes
1answer
157 views

Python script output to console doesn't update beyond first page in QGIS

I'm debugging a python script that includes a Print statement. I'm running the script from the QGIS python editor and expecting to see output in the QGIS python console, however once the script has ...
2
votes
1answer
2k views

Error when using input() pyqgis (RuntimeError: input(): lost sys.stdin) QGIS 3

I need the user to input a value. I'm using input() on qgis python console, but getting this error: RuntimeError: input(): lost sys.stdin How can I solve it?
4
votes
0answers
111 views

Using Python code from QGIS 3.x Graphical Modeler in console?

I want to use "Join Attribute by Location (summary)" processing algorithm in Python console of QGIS 3.10. After design my algorithm process (join sum of field name "abc" form layer 2 (point layer) to ...
2
votes
0answers
136 views

Method selectedFeatures() works too slow in QGIS 3 Python console

I loaded spatial table(about 100 millions rows) from PostgreSQL(PostGIS) in QGIS3 and use method selectedFeatures() in QGIS 3 Python console. For such big tables it work very slow (it takes up to 10 ...
1
vote
0answers
19 views

filter by last digit works in points but not in lines

I have three-point layers T, A1 and A2. T is original points and A1 and A2 are generated by some algorithms. I am trying to compare the result of A1 and A2 with T. On T, A1 and A2 I can apply a ...
2
votes
1answer
64 views

Cannot add multiple basemaps at once using Python console of QGIS [closed]

I am using Qgis 3.8. I want to download a bunch of basemaps to have easy access to in the future. I tried using python console with URl: https://raw.githubusercontent.com/klakar/QGIS_resources/master/...
1
vote
0answers
186 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
0answers
148 views

Calculating distance of individual points along line in PyQGIS? [closed]

I have a vector layer and need the distance between the points. This is an intermediate step for my further calculation and programming with Python. The starting point is stored in another layer (...
1
vote
1answer
32 views

Extra [ ] in layer QGIS Python Console

I'm trying to write a "simple" plugin as training and to automate a task repetitive task as well. I would like to have the map layer hardcoded instead of make sure you select the correct one but if I ...
2
votes
0answers
148 views

GeoPandas spatial join generates error in QGIS 3.8 Python console

I want to execute a spatial join using GeoPandas in the Python console QGIS 3.8 like this: dfsjoin = gpd.sjoin(point, polygon) but it doesn't work. It always shows the following error: Exception ...
-1
votes
2answers
1k views

Getting position of point in PyQGIS?

How to get position of QgsPoint objects in pyqgis/ python console using QGIS 3.x? For example: 1 points in vector layer TEST_P migeometria = f.geometry() posicion=geom.asPoint() print(posicion.x()) ...
2
votes
1answer
289 views

Setting value to defaults Layer properties using PyQGIS 3

I have a vector layer, how to set defaults value in fields from the Python console. Layer Properties / Attributes Form / Defaults | In option: Default value |______________|
1
vote
1answer
192 views

Seeking PyQGIS equivalent to Geopandas or SQL?

Using sql "DBpop2016" = maximum("DBpop2016" , group_by:= "DAUID") OR geopandas print (data.groupby('DAUID') ['DBUID','DBpop2016'].max()) I can select the single DB (of which there are several) ...
4
votes
0answers
191 views

Added raster layers with PyQGIS do not show up

I have a list ("datList") with names of raster layers which I want to add. When I add raster layers in the Python Console everything works fine: for da in datListe: layerDir = "C:/[...
2
votes
1answer
662 views

Set layer rendering 'refresh layer at interval (seconds)' using PyQGIS from python console?

I am trying to use the python console to achieve the following manual procedure of setting each layer to refresh automatically at a specified time interval. The manual process: Layer Properties > ...
1
vote
0answers
41 views

How to update datasource of handle bad layer with Python console in QGIS 3.4

How do I update the datasource of file project in QGIS, for example myexample.qgz from Python console? What is the command needed, or scripts standalone? For example: layer = iface.activeLayer() ...
0
votes
0answers
122 views

Running PyQGIS script inside QGIS console via Plugin?

I have some calculation and processing done on vector data. I have written code in pyqgis( and executing inside Console).I need to create a plugin (for my use only) which don't have any input button ...
2
votes
1answer
794 views

Extracting raw data from WCS raster using QGIS python console?

I am trying to replicate the following manual workflow in the Python console of QGIS 3.4.7 Manual workflow: 1) Connect to WCS service. Name: USGS National Map Elevation OGC-WCS URL: https://...
1
vote
1answer
196 views

Enable “Render layers in parallel using many CPU cores” from python console QGIS [closed]

How can I enable "Render layers in parallel using many CPU cores" option from QGIS python console?
0
votes
2answers
636 views

Loading vector layer in Python console?

I am trying to load a vector file to QGIS Python console. v_layer = iface.addVectorLayer("G://Consultancy\Data\Transfer\Bodhi (Louis) Gorringe\QGIS\Shapefiles\Biological Shapefiles\Seabirds\At sea ...
1
vote
0answers
425 views

Qgis Python console not working

I have a small problem with the Python console in Qgis. I am working through some code .py but lately the console does not show results, for example I write directly on the cosola print "prueba" ...
2
votes
2answers
567 views

Write to QGIS python console from plugin with sys.stdout

From my own QGIS plugin, I want to print text to the python console (see motivation below). Most simply, I use import sys sys.stdout.write('Outputtext') And get: AttributeError: 'NoneType' ...