Python bindings for QGIS.

learn more… | top users | synonyms

11
votes
2answers
3k 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
404 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
873 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
322 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
4answers
1k 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 ...
9
votes
1answer
561 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
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 ...
8
votes
1answer
381 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
841 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
2k 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 ...
7
votes
3answers
452 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
1answer
150 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 ...
7
votes
2answers
124 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
925 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
1k 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
165 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 ...
5
votes
1answer
1k 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
1answer
400 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
969 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 ...
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
486 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
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 ...
5
votes
1answer
665 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
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 ...
5
votes
1answer
1k 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
562 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
1answer
433 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 ...
4
votes
2answers
254 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
688 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
572 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
814 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
4answers
371 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
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 ...
4
votes
2answers
359 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() ...
4
votes
2answers
327 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
1answer
332 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
344 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
309 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
724 views

How to deploy a QGIS Python Standalone Application with minimum installation size?

I am trying to create a Standalone QGis Application using python. I was able to create the nice looking shapeviewer application by following the steps here. Now I would like to deploy this in ...
4
votes
1answer
969 views

How to find all intersections and count lines arriving at each intersection?

I'm having a hard time getting off the ground with this, and am trying to move away from ArcGIS / arcpy. I have a shapefile with a network of polylines. I want to find/count all 2-way intersections, ...
4
votes
1answer
589 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
2answers
263 views

Best practice in writing automated tests for QGIS plugins

I'm looking for some best practice advice on writing automatic tests for QGIS plugins written in Python. I have written tests for Python scripts in the past using PyUnit (the unittest module), but ...
4
votes
2answers
768 views

How to use map composer in a stand-alone script?

I'm trying to follow the map rendering section from the pyqgis cookbook, but I'd like to test this as a standalone application. I can do the first part, using simple rendering, but I'm a bit stuck ...
4
votes
1answer
172 views

How to auto-start a pyQGIS thread?

having build some (two) minor plugins, it's now time for me to link a few (perl-) applications to qgis. As there is no perl-interface in qgis I thought the best way to link both worlds together is a ...
4
votes
1answer
246 views

How change border line to no pen with python console?

From Python console I load a shapefile with qgis.utils.iface.addVectorLayer. How I can remove border lines (change to no pen) in the active layer?
4
votes
1answer
455 views

How to Create a raster layer from a numpy array using pyqgis?

I am working on a plugin for Qgis to calculate spatial Kernel density maps. I have all the calculations working, all I am missing is a way to turn a Numpy Array, with density values into a multiband ...
4
votes
1answer
58 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 ...
4
votes
1answer
393 views

Using the Processing Framework in QGIS 2.0

I am writing a plugin for QGIS 2.0, and I want to use the processing framework to call some functions. When I open the pyhton console inside QGIS, I am able to call it like this: >> import ...