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
1
vote
1answer
34 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
28 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
41 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
34 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
23 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 ...
3
votes
1answer
59 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 ...
0
votes
0answers
14 views

Python console does not show even after reinstall

I have a trouble which is related to the "Python console". It used to appear in my QGIS 3.4 but during analysis the program crashed and I lost the "Pythone console". I did uninstall and install many ...
4
votes
1answer
74 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 ...
1
vote
1answer
100 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?
2
votes
0answers
37 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 ...
1
vote
0answers
72 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
17 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
42 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
58 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
67 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
30 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
64 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
120 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
96 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
87 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) ...
2
votes
1answer
152 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
34 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
51 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 ...
1
vote
1answer
247 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
108 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
477 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
260 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
224 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' ...
1
vote
1answer
130 views

Running python code created in QGIS

I'm using QGIS 3.4 and Python 3.7.0 on Windows 7. From the Python console of QGIS, I created a test script ("test.py") which contains the following line: print('Hello) and this is saved in C:\...
2
votes
2answers
164 views

GIS software that can work only on Ubuntu Terminal? [closed]

Recently, I tried to open a QGIS project on Ubuntu, but I can only use Ubuntu's terminal for that which gives me the following error: QGIS starting in non-interactive mode not supported. You are ...
1
vote
1answer
51 views

Change main properties of map composer from cache to render from Python Console

I'm trying to print out a map from Python console. The issue is that when I add a layer to the map composer, the property of the map is set to cache. However, I want to change it to render so that the ...
3
votes
1answer
117 views

QGIS behaves different when i have the “python console” active compare to not active

I'm developing my QGIS3 plugin and I've realized that if I have the Python console active (so I can see it) the plugin behaves as expected, while if I don't see it doesn't. So this is the code: for ...
2
votes
0answers
50 views

Getting Python console in QGIS to do tab completion of file system? [duplicate]

I am trying to have the Python 3 console tab of QGIS 3 complete my file system. I've tried import sys but this does not allow me to do it.
-1
votes
1answer
71 views

Incorrect parameter value in Python Console in QGIS [closed]

I have a problem with python console.In Figure 1,the only thing I do is to define the 'inputFile' as 'filepath+fname' and 'outputFile' as 'FileSavedPath+fnameSaved'. But apparently there's an error. ...
0
votes
2answers
262 views

How to run the graphic modeler from the python console in QGIS? [closed]

How can I run the graphic modeler from the python console in QGIS?
2
votes
0answers
79 views

Changing the Location of Python Expressions QGIS3

I've recently started using QGIS and I've written a few custom functions to use with expressions in the Function Editor (see image below) From what I can find these appear to be saved in: C:\Users\...
1
vote
1answer
111 views

Enabling 'on the fly' CRS transformation via python console of QGIS?

I am using QGIS 2.18. Is there a way to enable the 'on the fly' transformation project setting from the python console?
1
vote
2answers
149 views

QGIS can't type in python console

I have troubles with python console in QGIS 2.18.23. When I type something like Print ("test ") and I press Enter, nothing happens and nothing is shown in the console. EDIT:System configuration: ...
1
vote
1answer
74 views

passing an URL to owslib in Qgis editor doesn't work properly?

I'm trying to determine the version number of several WFS using the python module owslib. since i need to use this version number in ogr2ogr (and for some reason, python's ogr2ogr only works in Qgis' ...
1
vote
1answer
217 views

python's .replace doesn't work in QGIS' python editor

I am trying to compare some files to a datalist. The datalist's names are all in english letters, while the datafiles have the scandinavian "æ" "ø" "å" letters. an example: the file "Kystnære_måger....
2
votes
0answers
359 views

User friendly list of processing algorithms in the QGIS 3 python console [duplicate]

The QGIS user guide section Using processing algorithms from the console has not yet been updated for QGIS 3 and while a previously answered question will do the trick with some extra work, it is not ...
3
votes
1answer
47 views

QGIS attribute data updating by not commiting

I am trying to change the values of an attribute in one of my layers. My code is as follows: from qgis.utils import iface from PyQt4.QtCore import * layer =iface.activeLayer() pr=layer.dataProvider() ...
2
votes
0answers
326 views

to extract data from tif files using QGIS [closed]

I am brand new to GIS. I haven't been able to find the solution online, I think I don't know enough to be searching with the right terminology. I have a number of tif files which I have successfully ...
2
votes
1answer
204 views

When PyQGIS script is run through console layer does not load successfully

I made a small script to save a shapefile to disk. I want to run the script through console. When I run the script through QGIS IDE, it runs successfully. But when I run it through the QGIS Python ...
1
vote
0answers
152 views

Shortcuts for QGIS python console commands

I would like to define a shortcut for "Save" in the python console, is there a way to achieve that ? Is it possible to define shortcuts only for the given context of the python console and make them ...
0
votes
0answers
206 views

QGIS not importing correct IPython version for IPython QGIS console plugin

I am trying to run the Ipython console plugin in QGIS 2.18 After installing the plugin, I tried running it, and got the following error: You need to install IPython 3.1.0 (and then restart QGIS) ...
12
votes
4answers
5k views

Getting QGIS 2.x python code to work in QGIS 3.x? object has no attribute 'legendInterface' problem

The following piece of code works well in QGIS 2.x, however it does not work in QGIS 3.x. myDir = 'd:/work/output_folder/' layers = iface.legendInterface().layers() pipe = QgsRasterPipe() for layer ...
2
votes
1answer
407 views

How to amend Python code to work in QGIS 3?

In another thread, I was given this code to import large numbers of dxfs into QGIS. This code works in QGIS2.18, but they just released QGIS 3.0 and have changed the codes to use a different version ...
2
votes
1answer
668 views

QGIS python Console Error - list index out of range

I have a text file which has the details of many .tif files which have to be converted to a single merged .vrt file in QGIS Python Console. text = "W:/04 Tools/07 MapMaker/workingfiles/text.txt" ...
4
votes
1answer
407 views

Add Column and Populate using the Python Console

I am trying to add a new column to the attribute table and populate the column with a string, using the python console in QGIS. I have done the same but populating the column with an integer (...