Questions tagged [pyqgis]

Python bindings for QGIS.

Python bindings exposing some QGIS internals, that enable the writing of scripts, tools, plugins and custom standalone applications using the QGIS libraries. Limited documentation is available through the PyQGIS Developer Cookbook and the Python API Documentation.

7576 questions
18
votes
1 answer

Writing standalone Python scripts using PyQGIS?

I've been learning how to use the Python Console in QGIS using references from qgisworkshop.org. I'm familiar with writing standalone scripts in ArcGIS and want to learn how to do the same with QGIS. For example, in ArcGIS 10 a simple standalone…
djq
  • 16,297
  • 31
  • 110
  • 182
14
votes
2 answers

Setting feature attribute by name via QGIS python api?

I try to set feature attributes by attribute name with this code pr = layer.dataProvider() pr.addAttributes([QgsField("test", QVariant.Int)]) layer.updateFields() for feature in layer.getFeatures(): attrName = 'test' feature[attrName] = 1 but in…
dmitry.v.kiselev
  • 1,666
  • 1
  • 11
  • 23
13
votes
3 answers

Modifying polygons to be more rectangular using PyQGIS

I have some buildings that were quickly digitized from an aerial image. As you can see most of the polygons are not rectangular. How can I modify the polygons to make them more rectangular? Is there some equation that can solve a rectangle from a…
GreyHippo
  • 2,180
  • 2
  • 17
  • 30
12
votes
2 answers

How to read user defined project variables using Python

I can change user defined project variables by QgsExpressionContextUtils.setProjectVariable('myvar','hello world') But how can I access/read this variable in a python script?
Karel DG
  • 121
  • 4
11
votes
3 answers

Obtaining the data of one selected feature in QGIS using Python?

Is it possible to get the data of one selected feature in QGIS using Python, and if so how? In my example I have a layer which shows some parcels for urban planning. If I now select one of the parcels I want to get the data for exactly this parcel.…
Sven
  • 822
  • 2
  • 8
  • 17
10
votes
1 answer

Why can't I import my script from the python console?

i am working with the qgis python console. I usually store all my python scripts into ~/Scripts/python I do have set the PYTHONPATH to ~/Scripts/python in my .bashrc However, I can not manage to import my sripts from the console inside QGIS. Here is…
Renaud
  • 871
  • 3
  • 9
  • 20
9
votes
1 answer

Closing QGIS project without saving using PyQGIS

My program opens a QGIS project, loads one layer, adds a point on this layer and then stops. My problem is - I don't save the project explicitly, but the added points are always saved (I have to remove them manually). The question seems to be…
Tambet Väli
  • 103
  • 5
9
votes
1 answer

Accessing iface PyQGIS API from Standalone Python script (outside QGIS environment)?

I want to call PyQGIS API from my standalone Python script, outside QGIS environment. I can not, as 'iface' is not available. I have done necessary import / initialization : from qgis.core import * from qgis.gui import * # supply path to where…
Krisanu Roy
  • 103
  • 1
  • 4
9
votes
2 answers

Exporting layer to shapefile using PyQGIS?

I´m using python in QGIS 2.2 and struggling with an error trying this: # create layer from text _vlayer = QgsVectorLayer(_ur1, "raw", "delimitedtext") works fine but: # export layer to shape _writer =…
dlg_
  • 323
  • 2
  • 3
  • 11
8
votes
2 answers

Accessing internal QGIS clipboard in PyQGIS

How can one access the internal QGIS clipboard (defined in C++ qgsclipboard) via Python/PyQGIS? I've tried QgsApplication.clipboard() and QApplication.clipboard, both of which return a PyQt5 QClipboard object rather than a QgsClipboard. I'd love…
Houska
  • 7,976
  • 19
  • 48
8
votes
1 answer

Threading with timer in PyQGIS?

I am trying to implement a method for performing a task at regular intervals in QGIS. This is to be triggered by a timer (currently 'threading.Timer', although it could be something else) and should utilise a thread separate from the GUI as well as…
wotnot
  • 419
  • 3
  • 12
7
votes
1 answer

Running Python script on opening QGIS project?

I have a .csv file containing financial data which is generated on a regular basis outside QGIS. Then I want to create a PyQGIS script that will add the .csv file as a layer in my project. (The idea here is I want to have the up-to-date financial…
Windros Dulanya
  • 101
  • 1
  • 2
7
votes
2 answers

Generating grid in PyQGIS without GUI?

Is there a QGIS Python binding for generating a grid programmatically without using the GUI?
7
votes
1 answer

Use PyQGIS to load Value Map against attribute

Value Maps can be added to attributes via the loading of a CSV file, as described in the docs: https://docs.qgis.org/3.28/en/docs/user_manual/working_with_vector/vector_properties.html#edit-widgets It is possible to add a CSV (or any format) Value…
Tom Brennan
  • 4,787
  • 6
  • 26
7
votes
2 answers

What's a provider in PyQGIS and how many types of providers exist?

What's a provider in PyQGIS and how many types of providers exist? I am really not sure what a provider does. There is an example below from PyQGIS cookbook where a provider is used to load a QgsVectorLayer. #get the path to the shapefile e.g.…
Casian Pavel
  • 193
  • 6
1
2 3
35 36