Python bindings for QGIS.

learn more… | top users | synonyms

12
votes
2answers
4k views

How to create a new empty vector layer programmatically?

I am new to python and QGIS. I have looked at a few tutorials of python scripts for QGIS. All of them create new vector and raster layers with some existing data source. eg. shapefile or geotiff or ...
11
votes
1answer
428 views

How to create text labels with background boxes?

I'm trying to create some custom labels for point features in a QGIS point vector layer, and I want to write a python plugin to do it. We need our labels to be presented with color tinted rectangles ...
10
votes
1answer
1k views

How to draw perpendicular lines in QGIS?

I have a situation like this: What I need to do is to connect each point to every line that is at most, let's say 200 m, away from the point. In other words, I need to draw a perpendicular line ...
10
votes
4answers
2k views

How to buffer in pyQGIS?

I'm looking for some examples to do simple python scripts in QGIS. How would I do a buffer analysis on a dataset? I can't seem to find much in the manual and QGIS python that quite matches the Esri ...
10
votes
1answer
974 views

Is there a way to access QGIS plugins in Python?

Is there a way to access QGIS plugins in Python? I'd like to write a script to do some geoprocessing, and I'd like to use the clip, regular points and convex hull tools in fTools, as well as the Road ...
10
votes
1answer
365 views

PyQGIS file lock release

I was wondering what triggers the release of file locks in pyQGIS? I am trying to delete a few data sources (used temporarily) by calling QgsVectorFileWriter.deleteShapeFile, but I have to quit QGIS ...
9
votes
1answer
690 views

Is it possible to show our custom message in QGIS Status bar using python?

Is there any way to show our custom message in Qgis Status bar using python? Just like in arcgis "IApplication.statusbar.message(0) = "Please wait..." like that is there any option to show ...
9
votes
1answer
2k views

When iterating over a vector layer with pyqgis, how do I check whether a feature is selected?

While iterating over a vector layer using the following code (summerized from the example in the pyqgis cookbook), is there a way to check whether a feature is selected? provider = ...
8
votes
1answer
158 views

How to save python session in QGIS?

After running a lot of scripts in QGIS' python console, I have more than 10 dictionaries and lists, and I need these for further analysis. Is there a way to save python session, with all these ...
8
votes
1answer
450 views

How to address the new “Task-Completed” QgsMessageBar in Python?

I am really amazed what huge steps the QGIS development has taken in the last months. The new iconset, the improved Print composer and many more changes to be seen in QGIS 2.0 are really awesome! ...
8
votes
1answer
944 views

How to add a toolbar via python?

Through tutorials I learned how to add a toolbutton to the plugins-toolbar via python. Now I wonder how to add a complete toolbar with toolbarbuttons via python. Can anybody give some example-code? ...
8
votes
4answers
1k views

How to run sextante algorithms outside of qgis python console?

I'm kind of stuck trying to figure out the way to run sextante from a standalone python from OSGeo4W distribution. The reason I want to do this is that I got tired entering parameters in the dialog ...
8
votes
1answer
3k views

How do I maintain a resposive GUI using QThread with PyQGIS

I have been developing some batch processing tools as python plugins for QGIS 1.8. I have found that while my tools are running the GUI becomes non-responsive. The general wisdom is that the work ...
8
votes
1answer
151 views

QGIS - Calling interpolation extension from python console

I would like to call the QGIS interpolation extension function (TIN method) (Raster->Interpolate) from python console. I can't find the corresponding function within QGIS API or within the ...
7
votes
3answers
567 views

What are QGIS Arcpy Equivalent Functions for Update/Delete Row/Field?

I am trying to reprogram some scripts from arcpy to qgis (1.8 or 2.0) and there are some simple functions that I want to be able to redo but unfortunately documentation in qgis is lacking in certain ...
7
votes
2answers
128 views

How do you obtain the execution times of processes in qgis?

I am working on QGIS. I need to determine how much time QGIS needed to finish a specific task. I have been unable to get execution times for the processes. What is the proper way to get processing ...
7
votes
2answers
1k views

Split a feature when intersecting with a feature of another layer using PyQGIS/Python?

I have a buffer layer (green polygon) which I want to split to two polygons whenever it crosses a barrier (blue line). I have been trying to use "splitGeometry" method, but I just can't get it to ...
7
votes
4answers
2k views

How to get features based on their attributes using Python?

How to Get features by their attributes (similar to Iqueryfilter in arcobjects) in Qgis using python? Instead of getting all features and filter it manually, is there any option to use whereclause to ...
7
votes
1answer
171 views

Unable to load .gpx file from Python Console

I'm trying to create a plugin which will extract the gpx files and load them onto the active layer window in QGIS. While I'm able to load it using the QGIS GUI from Layer>New Vector Layer, I'm not ...
6
votes
1answer
1k views

How to transform a selected multipart feature into singlepart features while editing in QGIS?

There are several questions and respective answers for how to make a multipart features Layer into a singlepart features one using QGIS: How to break a single polygon into multiple polys? How to ...
6
votes
1answer
1k views

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 ...
6
votes
1answer
2k views

How can I programatically create and add features to a memory layer in QGIS 1.9?

I had a working plugin in QGIS 1.8 which read data from an MSAccess database and added it to a series of memory layers. There is some processing involved in the interim so I don't think simply using ...
6
votes
1answer
542 views

How to call GRASS modules in pyQGIS?

I wish to use a Grass module (v.to.db) in QGis, without the grass toolbox. I tried with the Python console, but to no avail : Using Sextante plugin but obviously it didn't know all the grass ...
6
votes
2answers
465 views

How to write scripts that can call on both Arcpy and PyQGIS?

I have spent quite a bit of time looking for a clear answer this topic and have still been unable to really accomplish my goal of accessing PyQGIS in a stand alone script. Parts of answers have been ...
5
votes
1answer
535 views

How to programmatically associate a layer with a custom UI?

I know it is possible to associate a layer with a custom UI for editing feature attributes using the QGIS interface. But is this possible with Python? This link shows how to achieve the result ...
5
votes
1answer
2k views

How can i obtain the data of one selected feature in QGIS using python?

I have a problem / question regarding python and QGIS. Is it, and yes how, possible to get the data of one selected feature in QGIS using python? In my example I have a layer which shows some parcels ...
5
votes
2answers
1k views

Standalone applications using QGIS and environment variables

I've tried going through IRC to see if people can help me out with this, but the medium seems a little clumsy for making any answers clear, so I'm going to try this instead. I would like to program a ...
5
votes
2answers
521 views

How can I define the layer CRS for a memory layer in pyqgis

how can I define the CRS for a memory layer from the qgis project settings vpoi = QgsVectorLayer("Point", "vectpoi", "memory") feature = QgsFeature() ...
5
votes
2answers
1k views

How do I use QGIS python console to iterate through simple layer queries and png outputs?

I'm really new to QGIS coding and I'm having a hard time finding (especially) the api classes/functions to carry out actions of the Query Builder window. I'm basically trying to do this: Iterate ...
5
votes
1answer
527 views

How do I allow users to select features with the mouse?

I am using PyQGis API to create a custom application. How do I allow users to select features with the mouse? Is there a mapTool for this? Surely with a product as powerful as QGis there must be. ...
5
votes
1answer
882 views

Speed of editing attributes in QGIS from a Python plugin

I'm trying to edit the value of an attribute for each feature in a layer using a QGIS Python plugin. I've found that doing this outside of editing mode is much slower than while editing (even ...
5
votes
1answer
128 views

QGIS Processing Progress

I have been developing a python plugin that uses Processing algorithm for raster calculations. I want to support the gui with progress bar. How can i connect Processing job to progress bar? I found ...
5
votes
1answer
2k views

How can I Setup Python to recognize QGIS

I want to use QGIS and work with Python out of the console, but I'm having troubles letting the system recognize the paths of some DLLs. Since I couldn't find a good answer on the web, I wonder if I ...
5
votes
1answer
656 views

How to get pixel size/cell size of raster layer?

After much searching, I've still not been able to figure out how to perform what seems like a simple function: I'd like to get the pixel size/cell size of a raster layer using PyQgis. Is there any ...
5
votes
0answers
375 views

PyQGIS CRS on the fly reprojetion

As a first step of a pyqgis plugin I'm trying to import several shape files at once. To get them aligned, using the GUI, I'd enable on the fly reprojections and set the project crs to WGS84. I'd then ...
4
votes
2answers
334 views

Using Python and open source modules, how can I perform Raster Calculator functions?

I would like to perform mathematical functions similar to those you would use Raster Calculator for in ArcMap, however I'd like to do it in Python without using the Arcpy module. I have the osgeo ...
4
votes
2answers
792 views

How to automatically reloaded raster layer if source is changed in QGIS?

How to automatically reloaded raster layer if source is changed? (The path is the same but inside source file are changes) I use: qgis.utils.iface.mapCanvas().refresh() but layer not refresh. # ...
4
votes
3answers
713 views

How to find the polygon inside which a point lies?

I have a layer with polygonal features. Each feature has attributes and values. I also have a list of co-ordinates and I would like to know which feature (or polygon) the co-ordinates lie in. Could ...
4
votes
2answers
872 views

How to show a message box in QGIS?

I am starting to develop a plugin for Qgis using python, which i am very new at, and would like to view some results of variables by displaying a message in QGIS. How can I do this?
4
votes
2answers
1k views

How do I get the path of a project, or layer file in PyQGIS?

I am generating new raster files from vector layers on a project. I would like to save them in the same directory as the project or layer files. How do I find this path using PyQGIS?
4
votes
2answers
859 views

How to get field names in pyqgis 2.0

I am trying to change an plugin from QGIS 1.8 to 2.0. In the 1.8 version I create a table of the field names like this: layer = vlayer provider = layer.dataProvider() feat = QGSFeatrue() allAttrs = ...
4
votes
4answers
407 views

How to display a “Save As” dialog for raster files?

I'm writing a QGIS plugin in python. I need to show a "Save as" dialog window in order to allow the user to select the path of the output raster file. Do I need to create a QFileDialog and manually ...
4
votes
3answers
380 views

How do I specify the position, style and units of the ScaleBar in pyqgis?

I would like to add a scale bar to my composition using the python console and then export it to a raster image. I am following the MapRendering tutorial with the "output using map composer " approach ...
4
votes
2answers
683 views

How can I add OpenLayers layer from the python console?

I am new to the python console. How can I add a layer from the OpenLayers plugin from the python console? Thank you
4
votes
1answer
586 views

How to merge shape files with attributes from a python script in QGIS?

I have some shape files. They are all the same kind of shape and all have the same attributes. If I wanted to merge them manually the "Vector/Data management tools/merge shape files to one" works ...
4
votes
2answers
408 views

How do I set layer transparency in QGIS 2.0 with Python?

I have a raster layer loaded in QGIS and I'd like to be able to set its transparency via the Python console. I'm new to the API and have not been able to find out how to do this. Any help would be ...
4
votes
1answer
391 views

How can I create a new layer from the currrent selection?

Is it possible to create a duplicate layer, only displaying the selection from the layer you are duplicating in QuantumGIS? Simular to ArcGIS -> Create Layer from Selected Features. I looked at "How ...
4
votes
1answer
824 views

QGIS Zoom from python console

What are the commands to apply all types of zoom (full, on selected layer, etc.) in python console? I'm searching both on pyqgis cookbook and API documentantion, but I'm not finding anything ...
4
votes
1answer
307 views

Can I use QGIS plugins in PyQGIS as a stand alone script without iface?

Can I use a qgis plugin especially (openlayers plugin) in stand alone pyqgis script? I don't find examples, just code using iface but that cannot used in stand alone script.
4
votes
1answer
312 views

“Couldn't load PyQGIS” Error running QGIS on Ubuntu 14.04

I have installed QGis on Ubuntu 14.04 from the QGis stable repository; it went fine with no errors reported. But when I launch QGis I get this huge window with the following message: Couldn't load ...