Python bindings for QGIS.

learn more… | top users | synonyms (1)

1
vote
1answer
26 views

QGIS Python variable not updating after new features are inserted

I have the following script that sets the a feature id automatically after a new feature is digitized. I added the function inside the project's Macro section inside openProject() function: The ...
1
vote
1answer
12 views

Overriding method of qgis object does not work

I try to reimplement the renderDiagram() method from QgsHistogramDiagram to add some labels directly to the diagram (using the position argument). So far, I tried to set up my own class to override ...
1
vote
0answers
17 views

How to refresh MapCanvas while PyQGIS-script is running?

I try to write a PyQGIS script similar to this: Use of python console to prepare offline map from WMS (tile downloader). Basically there are two loops to pan the mapCanvas, refresh the mapCanvas and ...
2
votes
1answer
24 views

How can I add a second Toolbar Button and Dialog to a QGIS plugin built with Plugin Builder?

I want to create a toolbar with 2 buttons, each button opening a different form. The steps I followed are: Created a plugin using Plugin builder Created a toolbar with 2 buttons by doing the ...
1
vote
0answers
14 views

How to add fields to postgis layer loaded in qgis using python

I have loaded a layer from Postgis in qgis and I am adding the fields to the layer using the follo code snippet: canvas = qgis.utils.iface.mapCanvas() aLayer = canvas.currentLayer() field_name = ...
3
votes
1answer
24 views

QGIS python getting number of new features to be stored in layers

I mean, how could I get the number of features that have been created in a given layer and that are pending to be saved in the layer when "Toggle editing" or "Saving layer edits"?
2
votes
1answer
18 views

Problem using processing.runandload(…)

I'm writing a QGIS plugin using PyQGIS and I have a weird problem. When executing following line of code: processing.runandload("qgis:createpointsalonglines", r"Clipped", 1, 1, 0, r"memory:nodes") ...
1
vote
1answer
17 views

QgsMapCanvas object is not callable (Ubuntu with, Eclipse, Python & QGIS 2.0)

I'm basically borrowing the code for picking up a coordinate from a mouse click from this answer : How to programatically check for a mouse click in QGIS However in a stand alone application I do ...
2
votes
1answer
16 views

QGIS Error while executing Python function in openProject() Macro: “QgsMapLayerRegistry is not defined”

I have the following script that sets the a feature id automatically after a new feature is digitized. I want the following function to be executed automatically when project is opened (and layers ...
3
votes
2answers
112 views

Removing layers with zero features from QGIS

I have more than 100 layers loaded in map canvas. Some layers don't have any feature. I would like to delete all layer with zero feature count. Is it possible to get a script which can delete all ...
1
vote
1answer
32 views

How is it possible to programmatically export current view as georeferenced image with QGis?

I found the this to export the current view as image. The following code works and was accepted as answer. c = iface.activeComposers()[0].composition() image = c.printPageAsRaster(0) ...
1
vote
0answers
18 views

How to rollback the committed changes in the Vector Layer in qgis

I selected few features in the vector layer and updated the field. But I want to rollback the changes committed to the vector layer. How can I do that in QGIS? I have used used the following coed: ...
3
votes
0answers
53 views

How to integrate python-docx with QGIS

I have installed the newest QGIS and downloaded python-docx from this link python-docx . I haven't installed separately a different version of python. Is it possible to integrate this package of ...
3
votes
1answer
334 views

Import error when utilizing QGIS's Python Init function

Based on the answer to Referencing Qt UIs external to plugin with python. I'm trying to utilize the "Layer Properties / Fields / Python Init function" to execute a file (test_file.py) that is located ...
0
votes
0answers
31 views

Is it possible to create an .ui file from .py file? [on hold]

By applying the following pyuic4 -o filename.py filename.ui from an *.ui file I take the corresponding *.py file. Is there a way to do the oposite?
2
votes
1answer
58 views

“unexpected indent” in the script

I'm using a QGIS 2.8 in windows 10. I have 2 scripts that are working separately but when I write both in just one script, it doesn't work. The 1st script is to load one raster to QGIs with a defined ...
3
votes
2answers
46 views

Distance Matrix of two datasets

I have two datasets of the same adresses, one geocoded with Google, the other with Nominatim. Now I want to compare address1 of dataset1 with address1 of dataset2, then address2 of dataset2 with ...
3
votes
1answer
24 views

Add Values to New Column in Attributes Table using Python Console in QGIS

I've added a new column to my table called "STRNAME" using: path = "/Users/shapefiles/roads/" metro_roads = QgsMapLayerRegistry.instance().mapLayersByName('Metro_roads')[0] ...
1
vote
0answers
28 views

Setting icon for the submenu items in QGIS

I had added a new menu item as well as submenu item using the below code. I had succeeded in setting icon for all the submenus(HeatMapAnalysis,Buffer and Intersect.) But i cant able to set icon for ...
1
vote
0answers
24 views

How to automatically run some scripts for QGIS python console by defining the python macros checkbox

I'm working with QGIS 2.8 in windows 10. I've defined the python macros checkbox to QGIS start and simultaneously run a script that has the same path from my "QGIS.qgs" file. In the Project>Project ...
2
votes
2answers
1k views

How can I create a vector layer in PyQGIS from a table without geom column?

In QGIS I've got a Spatialite database containing tables without a geometry column. With the QGIS GUI it is perfectly possible to add such a table as a 'Spatialite vector layer'. But how to do this in ...
3
votes
1answer
70 views

Script that runs automatically from the QGIS Python Console when QGIS starts, using schedule tasks on Windows 10

I'm working with QGIS 2.8 and windows 10. Is it possible that after open QGIS using the schedule tasks from windows 10, I could open the python console and run a script within QGIS programmatically. ...
2
votes
1answer
24 views

Triggerring HeatMap Plugin using Python

I am trying to access heatmap plugin from Raster -> HeatMap -> HeatMap using PyQGIS.If my custom button is clicked, the heatmap plugin dialog box should opens.I know the heatmap is a c++ plugin.Is it ...
0
votes
1answer
180 views

How to connect mouseclick to map canvas in QGIS?

How to connect mouse click to map canvas in QGIS using python script? I have two lines of code to connect mouse click to map canvas: button.clicked.connect(self.onClicked) ...
1
vote
0answers
227 views

qgis python app how to add edit feature button? [closed]

I'd like to develop a QGIS Python app for plotting points and editing the attributes. I've started with the tutorials here: http://blog.qgis.org/?q=node/59 and read the cookbook ...
4
votes
0answers
26 views

Using QgsNewVectorLayerDialog

I am using QgsNewVectorLayerDialog for taking user input for creating a new shape file. When the user clicks OK i am reading the inputs selected by the user using the following code. dlg = ...
2
votes
0answers
18 views

Plug-in reloader

There's something i don't understand in the behaviour of the "plugin reloader" plugin : When an error occur in the test of a plugin "plugin reloader" reloads a new instance of my plugin (the one with ...
4
votes
1answer
22 views

How can I optimize layer filtering using setSubsetString or QgsFeatureRequest().setFilterFids(my_indexes)

i'm developping a plugin (under QGis 2.8.1) for traffic assignment where I want to show the results of my simulation at each time step. Right now I'm using Time Manager plugin but it gets very slow ...
5
votes
1answer
51 views

How can I print the text of help(some_method_class) in my QGIS plugin?

I'm developing a QGIS plugin to search classes and classes methods of QGIS. The dir equivalent option it was answered in: How can I access to elements in dir(some_class) of PyQGIS without a ...
3
votes
3answers
51 views

How to add all “.dat” files (raster) into QGIS, in a defined directory and defined legend (style), using python code

I'm using a QGIS 2.8.3 in Windows 10. I've added just one raster ("dat" file) to the QGIS, with a defined legend, using the following code. If I wanted to add all the "dat" files into a directory how ...
4
votes
2answers
68 views

How to populate QTableWidget via plugin?

I am attempting to populate a QTableWidget by adding rows, this is done by the user clicking on the add button: I have the following code to try and insert rows but nothing is happening: def ...
4
votes
1answer
45 views

How to insert a variable into a tool script

I am a bit new when it comes to Python programming. I'm trying to run the GRASS r.sun plugin tool to calculate the global irradiance for my chosen area for the whole year. The problem is that r.sun ...
2
votes
1answer
59 views

Customising QGIS Map Composer?

I am using QGIS for map making , I am adding multiple vector and raster layers and then finally for map making I am moving to the map composer. When I am exporting the map from Map composer , I want ...
1
vote
1answer
44 views

QGIS processing framework Python loading shapefile

I would like to write a Python script in the QGIS processing framework allowing the download of files from specific addresses. Instead of starting my script with: vectorLyr = vector I would like to ...
7
votes
1answer
85 views

How to index large VRT files in QGIS?

I have a large number of small tiles merged into a single VRT. The rasters are only viewed at large scale, so only a few of them are visible at the same time. The map refresh in qgis is slowing down ...
2
votes
1answer
193 views

Pyqgis: “a.geometry().intersects(b.geometry())” wouldn't find any intersections but should. Why?

I am teaching myself pyqgis and try to find those polygons in one layer that intersect with polygons in another layer. It seems very trivial, and on GIS.SE are several similar questions that are ...
3
votes
0answers
43 views

Create and save composer with Python

With Qgis 2.8 I need to create some composers based ona template, and save them using Python. I've found how to load a template in a composition, but I do not find how to save this composition in the ...
1
vote
2answers
487 views

QGIS from console: raster algebra

I'm newbie to programming in pyqgis. I need to perform a simple "GeoTiff * A" type of calculation(where A is a constant), but I am struggling to do so. I tried ...
6
votes
1answer
2k views

How to evaluate raster calculator expressions from the console?

How can I execute from the console an expression that should be used with the raster calculator? I'm searching for something like this: qgis.someRasterCalcClass.evaluate("boh@1 + boh@2", ...
2
votes
1answer
27 views

Create a layer in PyQgis with the same CRS as another

I want to create a layer which use the same CRS as another layer I already have in the project. The idea is to avoid the CRS dialog. I tried the things in this link: How to define layer's CRS and ...
2
votes
1answer
423 views

How to calculate zonal statistics from multi-band raster for each polygon using python?

I want to calculate the zonal statastics from multi band raster for a polygon layer. When I am using this snippet of code: vectorlayer=qgis.utils.iface.mapCanvas().layer(0) rasterfile = ...
4
votes
1answer
86 views

Bold and Italic layer labels with Python in QGIS

I'm trying to apply some labeling properties to a layer using Python. Everything went fine, except the way I tried to apply the Bold and Italic settings. Here is a part of the code: ...
3
votes
1answer
41 views

Accessing Command line options passed to QGIS exe

I am using QGIS 2.8, I am passing the raster image along with the qgis-bin.exe from the command prompt. Is there a way to access the name of the raster being passed along the exe in my plugin?
2
votes
1answer
27 views

How to connect QgsMapLayerComboBox to QgsDataDefinedButton

in Qt Designer there is the possibility to use directly QGIS custom widgets. In the UI I added a QgsMapLayerComboBox (to get the layers added in the legend) and a QgsDataDefinedButton. What I would ...
3
votes
0answers
18 views

loop distance point pyQgis

I have a .shp of lines where I'm able to calculate the sum of segments length but i'm trying to put a point at a given distance in meters. The probleme is it put me a point at every segments.. If i ...
1
vote
0answers
23 views

Layer style is not rendered properly using PyQGIS

I'm trying to render a layer with the given .qml style into .png image using a standalone PyQGIS application. The issue is that not all the layers of the symbology are rendered, e.g. a polygon with ...
2
votes
1answer
190 views

How to remove a layer and its legend in a standalone pyqgis application?

In continuity in my question How to add a legend to a canvas in a standalone PyQGIS application? > In every addition of a new layer in my standalone application, the legend lengthens and becomes ...
3
votes
1answer
36 views

Get QgsField alias in QGIS Python

In QGIS Python, how to get alias of field. In class QgsField, i can not find method to do this. lay = iface.activeLayer() provider = lay.dataProvider() fields = provider.getFields() for field in ...
2
votes
1answer
62 views

Create different print composers from different layers added to QGIS

I'm using QGIS 2.8.3 with windows 10. I want to know if it's possible and how to create, using python code, from each layer (in the table of content) a print composer to each one of them. Any ...
4
votes
1answer
79 views

How to write Python code with QList class

I need to write an interpolation script for QGIS. I want use TINInterpolation method from Interpolation plugin. I found class in API documentation but I don't know how to write QList object with ...