Python bindings for QGIS.

learn more… | top users | synonyms (1)

0
votes
0answers
4 views

Save Vector layer and update .qgs project file (pyQGIS)

need help to solve the following use case: QGIS started with new project (no layers) New layer is created programmaticaly and data is populated: vl = QgsVectorLayer("Point", "temporary_points", ...
0
votes
0answers
7 views

Labels not displaying when rendering to image with pyQGIS

I'm using the simple example in the pyQGIS cookbook http://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/composer.html I'm able to manipulate the features in my layer using Python, but the ...
1
vote
2answers
33 views

How to programmatically close a QMessagebox without clicking ok or X? [on hold]

So part of my script in PyQGIS is this: QMessageBox.warning(None,"Warning","bla bla bla") The box apperas just fine but i want it to close after a few seconds so i am looking for something like ...
0
votes
0answers
9 views

Zoom Extent several QGSVector layers with Labels (python)

I have the following case: Project constists of three layers: Open Layers plugin with Google streets QGSVector layer with Point features and Label enabled QGSVector layer with Polyline features and ...
1
vote
0answers
31 views

How to stop a PyQGIS script that has an infinite loop, using the keyboard?

So i wrote a script that does what i want over and over again using a "while True:" in a certain time interval (every 5 seconds using time.sleep(5)). So far so good BUT when i want to stop it i just ...
1
vote
1answer
30 views

Use raster memory layer from QGIS processing result

I want to apply subsequent QGIS raster processing algorithms in a python script. I want to use memory layers for intermediate calculation results since I am only interested in the end result. As ...
2
votes
1answer
43 views

How to change the edit widget for fields in a layer with PyQGIS?

Is possible change the edit widget with PyQGIS? I have made an extension that loads a PostGIS layer and I want to edit the date fields with the date widget by default without any change in the ...
0
votes
0answers
27 views

How to reload a raster file from the python shell

I do this in the QGIS python shell: # get the raster file (and data) of the active layer canvas = qgis.utils.iface.mapCanvas() rLayer = canvas.currentLayer() rLayerPath = ...
2
votes
1answer
34 views

Why this Python script only works once on QGIS?

So i have this script to change the color of some specific features(lines) using categories in a vector layer. When i import the script the console in the first time through the console it works just ...
2
votes
1answer
49 views

PyQGIS load dxf file as a vector layer

Can somebody help me with loading a dxf file as a vector layer with PyQGIS? Is QgsDataSourceURI an option? I've tried it with this code, but it didn't work. fitxer="/tmp/prova.dxf" uri = ...
1
vote
1answer
22 views

QGIS get the X and Y of a raster file by click

I have a raster file (Geotiff) and try to write a plugin that can change the value of one cell in a raster (== array cell). I know how to get a QGIS point but how can I get the array index from on ...
1
vote
1answer
18 views

How to change the color of a specific feature(s) with a PyQGIS script

First of all im a big noob so don't hate. So image that the lines that i have drawn is simple pipeline network, represented by some simple lines in a vector layer. Now the question is, how can i ...
2
votes
1answer
17 views

Odd behavior in a QGIS plugin: my function is triggered twice

I have a plugin with a function (triggered by a button) that selects a specific layer by name, then shows its attribute table. When I close the plugin and open it again, the attribute table pops up ...
1
vote
1answer
20 views

PyQGIS plugin debugging from Eclipse

having trouble with debuging QyPython plugins from Eclipse: - Win 7 x64 - QGIS 2.7 - Eclipse Luna with PyDev installed Tried to debug using Remote Debugger ...
7
votes
2answers
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 ...
0
votes
0answers
15 views

Creating Convex hull and finding buffer in QGIS

I have a layer and features are selected using Select Features by freehand tool and for that selected features, convex hull was done and for that convex hull i am trying to find buffer and write it in ...
1
vote
1answer
26 views

Buffer for features selected in the mapcanvas and writing to csv file

I have some features selected by using "Select Features by Freehand" tool in QGIS and try to find the buffer for those selected features alone and write the city and state names within in the buffer ...
1
vote
1answer
28 views

How to select from selection with PyQGIS?

The expression box has a handy "select from selection" button. Is there a way to emulate this with python? I have the basic expressions down, but can't find a way to do this.
1
vote
1answer
25 views

How to do a buffer operation for a polygon drawn by the user using python in QGIS

I have a polygon drawn on the map canvas.Say the polygon would be drawn by using "Measure Area" tool in qgis.Now, I want to do buffer for certain distance around that polygon.I can see the below ...
2
votes
3answers
2k views

How can I fix “ImportError: No module named qgis.core”?

First of all, I'm using Python 2.7.3, QGIS 1.8 (Lisboa) on Windows 7 pro 64 bits. Now let's go to the actual question: I have written some code (Python) that works well within the QGIS built in ...
1
vote
2answers
1k views

QGis 2.0.1 mapserver extension missing

I tried to export my Qgis projects to mapserver, using RT mapserver extension, because there is not any other extension in my version of QGis.(QGis 2.0.1 Dufour on ubuntu 12.04 LTS). After installing ...
2
votes
1answer
177 views

How can I add grid lines to a print composition using pyqgis?

I'm writing a qgis plugin to create an image in the print composer of the current map. I can get the map rendered in the proper place with a frame of the right width, and I can get grid annotations ...
-3
votes
1answer
21 views

Warning message needed when there is no specific layer instead of python error

In my plugin, when I click a button it will call the findTheCityNames function which is attached below and get features if there is a particular layer. What I want is if there is no specific layer in ...
1
vote
1answer
43 views

How to get a layer by name in PyQGIS?

I have a plugin which finds buffer for list of cities, provided the distance. The state and city names are taken from the attribute table and gets filtered accordingly. What I want is My plugin should ...
3
votes
1answer
1k views

legend groups and layer position/order qgis 1.8

I'm tring to programmatically create layer sequence also using groups. Simple python code: layer = QgsVectorLayer("004cp000.shp", "004cp000", "ogr") QgsMapLayerRegistry.instance().addMapLayer(layer) ...
-1
votes
1answer
30 views

Global name canvas is not defined

I am just trying to print the layer name using python in my QGIS plugin by following code. allLayers = canvas.layers() for i in allLayers: print i.name() It is saying an error: Global name canvas ...
-4
votes
0answers
28 views

Error in clicking browse button in my plugin [closed]

I have a browse button in my UI in my plugin and when in click it, it throws an error which is attached. Also code is attached for reference. def __init__(self, iface): """Constructor. ...
5
votes
1answer
405 views

QGis Zonal Statistics Plugin NoData included in Calculations

I have been trying to use the QGIS zonal statistics plugin. My raster has a nodata value of -99999 and all other values are positive. After computing the mean zonal statistics there are a number of ...
5
votes
2answers
584 views

Load and display a layer from SQL Server using PyQGIS

I'm having a go at using pyqgis from within the QGIS python console to load a layer from SQL Server and display it. I feel like I'm part way there but I'm having a real issue getting the layer to ...
1
vote
0answers
17 views

Vector Layer Symbology Export?

When programmatically creating / saving a QgsVectorLayer - implementation of the ExportSymbology functionality does not seem to exhibit the implied effects. Does such a command not indicate that the ...
0
votes
1answer
33 views

Cannot rename output file using standalone script for QGIS

I would like to rename all output files after my script has finished processing them by adding "(A)" after their file name (eg. Layer.shp -> Layer (A).shp). I received an answer from this post on the ...
0
votes
0answers
25 views

How to select the buffer region in map canvas in my plugin using python

I am developing a plugin which finds buffer by getting state name, city name and distance given by the user. The plugin works fine and writes the cities that matches the distance in a CSV file. What i ...
1
vote
1answer
43 views

How to add label to QgsVectorLayer by Python

my goal is to define label programmaticly for the case similar for the figure below: But didn't find any guidance how to do so using Python. I have a feeling it could be done using QgsLabel but ...
4
votes
2answers
1k views

Setting the extent for a QGIS map using python

I am writing a stand-alone application in Python/QGIS that simply creates maps. I want to load vector/raster layers, set symbology, set extent At the moment, that is all! Currently I am just using ...
1
vote
1answer
47 views

Download file from network using PyQGIS 2.x

I have a python plugin targeting QGIS 1.8 that uses QgsNetworkAccessManager and QNetworkRequest to issue a GetCapabilities request to WMS servers. With 1.8 everything was working fine. Now we are ...
1
vote
1answer
20 views

Error while trying to replace a opened csv file with the newone in my plugin

My plugin does some basic geoprocessing functionalities and write the output as csv file. What i want is when i open some already writed output csv file in a writable mode and try to replace the same ...
3
votes
2answers
47 views

How to define layer's CRS and avoid the CRS dialog in PyQGIS?

There is an existing Shapefile, which I want to add. At the moment my code looks like: self.iface.addVectorLayer(self.shpFilePath, "Track", "ogr") It works fine, but i want to define the crs ...
1
vote
1answer
45 views

How to add multiple attributes to a newly created feature with PyQGIS

I am creating a form for updating the attribute values of the newly created feature. But when i am updating the values only one attribute field is getting updated. So if i want to update the multiple ...
1
vote
1answer
62 views

How to export only certain column from selected feature to csv file in QGIS using python code

I have selected features in QGIS, I want to export only two columns from the selected features to a csv file automatically using python code. I have tried the following code: layer = ...
2
votes
1answer
37 views

Does mapCanvas().refresh() not work in QGIS 2.6?

Before I used the function qgis.utils.iface.mapCanvas().refresh() to reload the map canvas after for example a layer color was changed from a plugin. But this is not working with QGIS 2.6 for me. ...
0
votes
0answers
22 views

Error in finding buffer

I am trying to find a buffer for city provided a state, distance and filepath to write as csv. What i am facing is that the name which i selected in the city combo box alone gets writed in the csv ...
1
vote
1answer
27 views

Removing the duplicate values in QCombo Box

In my plugin, there is a combo box which lists city names for a particular state. FOr example, if i chose a particular state and city will be some 20 names in the dropdown. But the first name alone ...
2
votes
2answers
162 views

How to set the color of a feature depending on attributes with PyQGIS?

I'm trying to set the color of a vectorlayer feature depending on the feature attributes with PyQGIS. How do you acces the attributes of a vectorlayer feature?
2
votes
1answer
45 views

Adding new menu item to QGIS Desktop app

I need to add new menu item to the top level menu of QGIS Desktop (2.7.0); I.e. it shall be on same level as "Project", "Edit", "View", "Layer" etc. As far as I know there is pretty nice way how hide ...
2
votes
1answer
51 views

Layer properties dialog in my QGIS plugin

I am developing a plugin which should display some information like geometry of the layer, feature count etc. Now those are currently displayed in QMessageBox.information. I want it to be displayed ...
2
votes
1answer
39 views

Issues with PyQGIS while running a QgsZonalStatistics script

I have experienced a very bizarre issue with my PyQgis code. I simply want to load a raster and a vector layer to do zonal statistics, the first part works perfectly but for the zonal statistic I have ...
0
votes
1answer
45 views

How to trigger a QGIS action when a plugin button is clicked?

I tried calling the select free hand tool by below snippet of code. iface.actionSelectFreehand().trigger() I dnt have any idea how to call this when i am pressing a button in GUI. my gui is ...
2
votes
1answer
118 views

Accessing CRS info with pyqgis in a standalone application

I'm currently having trouble accessing and defining CRS information in a standalone application. I've read the API documentation and have tried it in the python console in QGIS 2.2.0. The python ...
1
vote
0answers
26 views

How to change the attribute values of the feature using the custom feature form

When i am using the following command it opens the feature form with all the fields: qgis.utils.iface.openFeatureForm(qgis.utils.iface.activeLayer(), f) But i want to open a feature form with the ...
1
vote
3answers
100 views

How to efficiently access the features returned by QgsSpatialIndex?

The PyQGIS Cookbook explains how to set up the spatial index but it only explains half of its usage: create spatial index — the following code creates an empty index index = QgsSpatialIndex() ...