Questions tagged [pyqgis]

Python bindings for QGIS.

Filter by
Sorted by
Tagged with
1 vote
1 answer
2k views

Unable to create empty memory layer for Line layer using PyQGIS?

# Get the currently selected layer inLayer = iface.activeLayer() # Get its list of fields inFields = inLayer.dataProvider().fields() # Convert its geometry type enum to a string we can pass to # ...
drama's user avatar
  • 367
1 vote
1 answer
830 views

pyqgis correct activate signal for combo box list

I am a pyqgis user and I am trying to create a QGIS plugin where that plugin have two tabs widgets and two combo box where first combo box have a list from layers and second combo box have list of ...
Chris Papas's user avatar
2 votes
2 answers
1k views

Extract corner coordinates of polygon extent in PyQGIS / GDAL

My goal is to extract corner coordinates (i.e. UpperLeft, UpperRight, LowerRight, LowerLeft) from polygon extent using PyQGIS or GDAL. In ArcPy there is a handy property of an extent class (i.e. ...
Basile's user avatar
  • 3,543
2 votes
1 answer
1k 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" ...
Sreeraj's user avatar
  • 729
4 votes
1 answer
569 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 (...
ste_j's user avatar
  • 105
3 votes
1 answer
994 views

Compute area in square meters rather than degrees using PyQGIS?

If you use the field calculator in Qgis considers the area in square meters, and when using the script gives the area in degrees. My layer is in the coordinate system WGS 84 vlayer=r"K:/temp/gpp_utm....
Георгий Викулов's user avatar
1 vote
0 answers
205 views

Error in reading project with delimited text layer using PyQGIS?

I have multiple QGIS maps with a KML vector layer and a delimited text layer on top (csv file). I want to save these maps as images using a script as follows in the python console to do this. for ...
zingsy's user avatar
  • 121
1 vote
1 answer
451 views

PyQGIS plugin doesn't work layer list combo box

I want to create a simple QGIS plugin with a simple combo box with list from my layers in _ _init_ _ : legendInterface = self.iface.legendInterface() listLayerName = [i.name() for i in ...
jessie jes's user avatar
  • 1,061
1 vote
1 answer
337 views

Problem executing algorithm

When I run the script below, I got this error: rps=10000 #RasterPixelSize layer = iface.activeLayer() extent = layer.extent() xmin = extent.xMinimum() xmax = extent.xMaximum() ymin = extent.yMinimum(...
Mustafa Uçar's user avatar
1 vote
1 answer
504 views

PyQgis - Multiple Maps in one page with different layers in each map

I'm trying to make a plugin for printing automatically PDF showing 3 different views from a set of layers in the same page. For this I have created a QgsComposition and I have added 3 QgsComposerMap ...
ROCIO MORA's user avatar
1 vote
2 answers
503 views

How to pan/zoom while QInputDialog

I'm iterating over a layer with a python-script in QGIS 2.18. I am going to pan to every feature and ask the user a question regarding this feature an do something depending on his answer. How is it ...
Ralf's user avatar
  • 380
2 votes
0 answers
462 views

QGIS Python - Error: Algorithm not found

Trying using the processing toolbox in a standalone python script the needed Algorithm could not be found: Error: Algorithm not found Error in sys.excepthook: Traceback (most recent call last): ...
CanadaRunner's user avatar
0 votes
1 answer
2k views

QGIS Python - 'NoneType' object has no attribute 'addFeatures'

Trying to convert a python console script to a standalone version of it. By following the general guidelines from QGIS-documentary https://docs.qgis.org/2.14/en/docs/pyqgis_developer_cookbook/intro....
CanadaRunner's user avatar
0 votes
1 answer
416 views

Setting current group as active group in PyQGIS? [closed]

While iterating on groups, I would like to set the current group as “an active group” in order that generated layers will be children of this active group. Is there any pyqgis expression to do this (...
ennine's user avatar
  • 863
2 votes
0 answers
62 views

Why isn't my layer loading via pyqgis despite the file name and path being correct? [closed]

I am writing up a python script on PyQGIS to load a point shapefile. # -*- coding: utf-8 -*- src = "‪‪‪C:/Users/Aaron/Documents/pygis/Points.shp" layer = QgsVectorLayer(src,"Localities", "ogr") if ...
Aaron Brunt's user avatar
3 votes
1 answer
5k views

Autosize custom form window to its content

I've created several custom forms using Qt Designer. My problem is that when I open a form, its window size remains the same as the size of the window of the last form I opened. For example, let's say ...
Mefimefi's user avatar
  • 586
2 votes
1 answer
70 views

Strange behavior of QgsScaleComboBox

I am using a QgsScaleComboBox and it's behavior is really strange. I also have 2 buttons in my gui for adding/deleting items. Those are the methods I use for adding/deleting: Adding: def ...
Blinxen's user avatar
  • 703
3 votes
0 answers
210 views

PyQGIS expression with many inputs

I try to create some advanced expression using a QGIS plugin for education rules. I have a simple Gui : My Gui has 7 line edits for text inputs. I try to using this Expression: layer = ...
Mar's user avatar
  • 1,119
1 vote
1 answer
192 views

How to measure the response time of a layer WMS/WFS in QGIS

Is there a way in QGIS (or pyqgis) to measure and test the response time of a WMS/WFS layer?
Luca Guida's user avatar
0 votes
1 answer
561 views

Rename Attribute field in pyqgis [closed]

layer.renameAttribute(0,'xxx') Traceback (most recent call last): File "", line 1, in AttributeError: 'QgsVectorLayer' object has no attribute 'renameAttribute' Can you get me solution for this ...
Karthikeyan's user avatar
4 votes
1 answer
1k views

Make donut polygons with python in QGIS

I am having trouble in translating the geometry of donut polygons to layer. I am drawing polygons using the list of points as follows; feature.setGeometry(QgsGeometry.fromPolygon([pLine])) Here ...
raosaeedali's user avatar
2 votes
1 answer
482 views

How to show label according to attribute name?

I try to show label name according to predefined in QGIS 3.0 by using pyqgis. I used that code in QGIS 3.0 but last update broke it down. Here is my code: settings = QgsPalLayerSettings() ...
Mustafa Uçar's user avatar
1 vote
0 answers
80 views

Using Time Manager and PyQGIS? [closed]

I've just started to use the Time Manage plugin and I was wondering if how compatible it is with PyQGIS. Specifically I was wondering if it was possible to use PyQGis to set up the following features ...
Daniel Mutton's user avatar
1 vote
1 answer
281 views

Installing QGIS on Mac OS X 10.13.2 with Python 3.4

My first time installing QGIS. ReadMe says QGIS uses Python 2.7. So, before I start Do I need to remove Python 3.4 or can I install 2.7 as well?
Alan James's user avatar
3 votes
2 answers
327 views

Removing a joined layer using PyQGIS?

I have two layers that I want to remove using PyQGis as part of a larger script. The first layer I can removed using: QgsMapLayerRegistry.instance().removeMapLayer( shp.id() ) However, it seems that ...
Daniel Mutton's user avatar
1 vote
0 answers
34 views

.deleteShapeFile isn't delete cpg files [duplicate]

Following this answer. I notice that the cpg (decoding declaration) file isn't delete using .deleteShapeFile pyQgis function. Any suggestion on how to delete these files using automatic method?
user113198's user avatar
0 votes
1 answer
281 views

Connecting from QGIS to PostGIS database using OGR toolbox?

I am trying to write a script to import/append mutiple layers into an existing PostGIS database. I am trying to use the GDAL/OGR toolbox algo "Import Vector into PostGIS database (new connection)". ...
user3327567's user avatar
1 vote
1 answer
441 views

Pyqgis: How to take output from Qgs.ZonalStatistics and join by ID with point layer

What I'm trying to do: Extract median by a single polygon from multiple GeoTIFF rasters stored in a folder (Solved) Add each median value to a point shapefile (Match/join by: id column for each point ...
johlund's user avatar
  • 637
4 votes
2 answers
2k views

Export Layout as PDF in QGIS3

I am trying to export a specific layout with python in QGIS3. But I am struggling with the QgsLayoutExport class. How do you use it? How can specify which layout should be exported? This is the code I ...
Blinxen's user avatar
  • 703
2 votes
0 answers
163 views

Passing variables between QGIS plugin and a combobox in layers custom form?

I am developing a plugin that asks the user to enter in "lineEdit" boxes, names of population types, depending on the number of types that they have previously defined. Once these names are ...
Assia's user avatar
  • 21
1 vote
1 answer
257 views

Wrong Minimum Pixel value using GetStatistics function

I want to print the minimum and maximum pixel values of a raster. When I load the raster Pioneertown.row1.asc in Layers Panel in QGIS, it is showing minimum value = 'nan' and maximum value = '1' . ...
Sreeraj's user avatar
  • 729
1 vote
0 answers
93 views

Pyqgis script to join delimited text layer on KML and create graduated symbols

I need to create multiple maps from QGIS which have the same procedure and so wanted to write a script. I found little help in terms of how to join delimited text layer to a KML vector layer(of ...
zingsy's user avatar
  • 121
4 votes
1 answer
4k views

AttributeError: 'QgsVectorLayer' object has no attribute 'pendingFields'

I have been using the following Python code on QGIS 3 (2.99) to look up fields, for several months id = feature.attributes()[layer.pendingFields().lookupField('ID')] And it gives me an error today: ...
tinlyx's user avatar
  • 11.1k
1 vote
1 answer
250 views

Getting first group name in PyQGIS?

With the following code, I did not succeed to get the first group name of the tree. from qgis.core import * from qgis.gui import * from PyQt4.QtGui import * from PyQt4.QtCore import * import os #...
ennine's user avatar
  • 863
1 vote
1 answer
315 views

Access qgis.explodelines in Python (outside QGIS)

I want to access the explodelines function in Python outside of QGIS from a standalone script. import sip for api in ["QDate", "QDateTime", "QString", "QTextStream", "QTime", "QUrl", "QVariant"]: ...
freddykrueger's user avatar
4 votes
2 answers
1k views

How to re-order line layer in QGIS?

I have a line layer that seemingly consists of a single feature. I then ran QGIS's Multipart to Singleparts algorithm (same result as Extract Nodes), so then the result consists of 27 line features: ...
15Step's user avatar
  • 2,440
2 votes
3 answers
3k views

Get current zoom level from QGIS map canvas

Is there any particular way of getting the current zoom level from the map canvas through python code in QGIS environment? I want to convert coordinates of the cursor and the current zoom level into ...
raosaeedali's user avatar
2 votes
2 answers
853 views

Python: Extract median by polygon from multiple raster files

What I'm trying to do: Extract median (or 50th quantile) by a single polygon from 558 GeoTIFF rasters stored in a folder What I got so far: Using Python from within Qgis and Qgs.ZonalStatistics I've ...
johlund's user avatar
  • 637
1 vote
1 answer
1k views

Deactivate custom tool when changing layers

I have build a custom toolbar and a tool for a qgis plugin (QGIS 2.18.13) updating a working one in QGIS 1.8. I have several layers loaded, two of them being vector layers for nodes (points) and edges ...
anuf's user avatar
  • 81
1 vote
0 answers
40 views

pyqgis plugin error list has not attributes

hello I create a QGIS plugin using pyqgis and I have two buttons in my plugin window button 1(run perform_search(self) function) and button 2(run select_feature(self) function). to work button 2 ...
jessie jes's user avatar
  • 1,061
1 vote
0 answers
560 views

QGIS for Mac: Python dependencies

I am developing a QGIS plugin in QGIS 2.18.15 on macOS 10.13.2 and I am having some troubles with Python libraries dependencies. More specifically, my plugin will require to use an external Python ...
user3352382's user avatar
6 votes
2 answers
2k views

How do I get the scale of the map item in my Layout(composer) in Qgis3?

I want to get the scale of my Layout that I created. For this I thought of using the QgsLayoutItemMap class. The problem is that the scale method in QgsLayoutItemMap always returns 0.0. I know I am ...
Blinxen's user avatar
  • 703
2 votes
1 answer
385 views

PyQGIS zoom using PyQt list widget

I have created a layer filter Expression to get specific results query from my layer and I add these results in a list widget using PyQt. My Expression and my add to list widget work fine (I print ...
hellas's user avatar
  • 393
3 votes
1 answer
242 views

Apply transparency on pixels in an image with PyQGIS

I'm trying to grab the pixels that intersect with my polygon shapefile and apply transparency to them (that is, I'm trying to create a hole in my raster) For that, I get all the pixels that are in ...
Herbert NDZONDZI's user avatar
7 votes
2 answers
6k views

Environment variables for QGIS 3 plugin development on Windows

I want to start learning QGIS plugin development, and I'm trying to get set up for Python 3, PyQt5 and QGIS 3. I've installed QGIS 2.99, qt5-devel and setuptools via OSGeo4W. Now I get stuck on the ...
arjan's user avatar
  • 763
3 votes
1 answer
2k views

Getting a list of all Layouts in QGIS3

I have created 3 print layouts in QGIS3. Now I am trying to get a list of all layouts in the LayoutManager with python. This is how I am trying to do it(this code is executed in the python console of ...
Blinxen's user avatar
  • 703
4 votes
1 answer
819 views

Determine layer visibility with PyQGIS

From some other posts I found that i can determine a layers visiblity by something like #assume lyr_name the layers name to determine visibity for l = QgsMapLayerRegistry.instance().mapLayersByName(...
Eva Großmann's user avatar
8 votes
4 answers
3k views

Getting user's QGIS version using PyQGIS

I am trying to write a QGIS plugin, which should work on QGIS 2 and QGIS 3. How can I find out which QGIS version the user is using, so the right imports are made?
Blinxen's user avatar
  • 703
2 votes
1 answer
1k views

Writing a Batch File (.bat) Script to run a QGIS Python Script without opening QGIS [closed]

I have saved a python script (named as 'Task3.py'). Currently, I will open QGIS and then run this Task3.py . This python script is saved in C:\Users\Sreeraj.qgis2\processing\scripts\Task3.py . But, I ...
Sreeraj's user avatar
  • 729
2 votes
0 answers
421 views

QGIS fails to open from Python script

I'm trying to get python script to open QGIS and display a project file from a windows batch file, but it QGIS never opens. What am I doing wrong? batch file contains (I've used this with another ...
p.k's user avatar
  • 47

1
88 89
90
91 92
152