Python bindings for QGIS.

learn more… | top users | synonyms

1
vote
1answer
30 views

How to calculate the perimeter of the polygon using python programming

Is it possible to calculate the perimeter of each feature of the polygon? For calculating the area we are using: area=feature.geometry().area() is there any function to calculate the ...
2
votes
1answer
27 views

Saving a QGIS project using the API loses mapcanvas (and other) XML nodes

I'm using the following python script to open a QGIS project, modify some things, and save it under a different name: from PyQt4.QtCore import QFileInfo from qgis.core import * def main(): ...
1
vote
1answer
64 views

How to add vertex to an existing polyline programatically?

I have a Polyline and would like to add new vertex to before start point or end point or at any part of the polyline using python in qgis. How can i do that?
0
votes
1answer
18 views

With QGIS Plugins/PluginBuilder, how to prevent 2nd instance of Plugin from starting

I am using QGIS 2.6.0, with PluginBuilder 2.0.3 [checking the version, I just noticed that the 2.1.0 update is available] I am writing a plugin; it installs and runs. While running, I am able to ...
1
vote
0answers
22 views

Add button to custom standalone QGIS application

Im able to implement zoom in and zoom out functionality as described in the PyQGIS developer cookbook using a tool bar. I would like to have buttons that display above my map canvas layer and have the ...
2
votes
1answer
48 views

How to prevent users to remove qgis layer?

I need to prevent users from removing layers. In my plugin code I use the following to achieve that: QgsMapLayerRegistry.instance().layersWillBeRemoved.connect(self.dontremovefunc) def ...
1
vote
2answers
30 views

Using QgsRasterCalculator

I'm trying to make a sum of n rasters and create a new one using QgsRasterClaculator, the problem is, every time the code reaches processCalculation, it makes QGis close and create a dump file. I ...
0
votes
0answers
36 views

How to find a distance from a point to a polyline in QGIS?

Please show a sample Python code of finding a distance between a point to a polyline in QGIS. (without any plugin)
0
votes
0answers
15 views

PyQgis Diagram Automated Placement Engine

I am trying to programatically change the "Show all labels and features for all layers" option for a layer which display diagrams. This option doesn't seem to appear in QgsDiagramRendererV2 api. It ...
0
votes
0answers
14 views

Add ids to the merged features using python programming

I have written the python code that merge the features based on the area.But after merging the features it is not assigning ids to the merged feature.Can anyone tell me how to assign ids to the merged ...
1
vote
0answers
54 views

PyQGIS cookbook seems out of date

I am trying to follow the http://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/ but it seems to be out of date, for example many of the raster methods no longer work as indicated or even ...
2
votes
1answer
83 views

How to create a Qgis python script to manipulate fields with some parameters?

I'm just beginning with QGIS. I have a shape file with 10 fields field1, ..., field10, and many thousands of data. I will like to automatize the next sequence (in a python script or a model): load ...
2
votes
2answers
81 views

Programatically use Openlayers plugin layer in Print Composer

I created some PyQGIS functions to set up a print composer, modify the layout (adding maps, legend, title...) and print the result as an image file. This works fine with one or several vector layers - ...
0
votes
0answers
46 views

How to overlay Google Map in a standalone PyQgis application?

I have created a standalone PyQGIS app (within Python itself, not a plugin) with PyQt and PyQGIS API. It generates my map really well. I would like to overlay a Google Map layer as base map just like ...
0
votes
1answer
13 views

How to show QgsDebugMsg in eclipse PyDev

In the source code of QGIS, I see a lot of QgsDebugMsg line. What should I do in order to show it when debug/run my standalone application in Eclipse PyDev?
3
votes
1answer
42 views

PyQGIS: Speed up for adding features and attribute arrays?

Context: I'm writing a dynamic import tool for QGIS (2.2 to 2.5) with python. Datatype: Binary Datasets with environmental simulations from HPC which might contain millions of features and terabytes ...
2
votes
1answer
95 views

How to load a WMS layer using PyQGIS?

Although there are some posts on this matter, there is no answer in anyone of them. This is why I am asking it again. One post I found was Raster layer invalid I read information from the following ...
1
vote
1answer
39 views

Use QGIS Gui's predefined colorramps in Python console / PyQGIS

When using the QGIS Gui, there are plenty of predefined colorramps to choose from when styling a layer with e.g. categorized symbology. When using the Python console for PyQGIS scripting, this page ...
0
votes
1answer
44 views

PyQGIS setSubsetOfFields function in QGIS 2.4

I found the function setSubsetOfFields to filter fields in a layer in the PyGIS cookbook: ...
1
vote
0answers
48 views

Apply graduated symbology renderer works in Python console but not in standalone script

I use the following PyQGIS script to load a vector layer from a shapefile and apply graduated symbology to it (tried to make it as minimalistic as possible). This works well in the QGIS 2.4 Chugiak ...
3
votes
3answers
75 views

Drawing some points in QGIS 2.4 using Python

I'm new to PyQGIS so here goes: Give a new QGIS project, how can we draw some Points on the map? I tried the following but nothing showed up. Should they be placed in a Vector layer before they can ...
0
votes
1answer
35 views

Programmatically Select a CRS in QGIS 2.4 using Python

When you run the following Python code in the Python Console of QGIS 2.4, uri = "file:///C:/data.csv?type=csv&xField=lng&yField=lat&spatialIndex=no&subsetIndex=no&watchFile=no" ...
2
votes
0answers
27 views

How to make added toolbar buttons exclusive?

I've added a toolbar to the QGIS mainWindow. Also I've added some checkable buttons to the toolbar. How can i now make my checkable buttons untoggle on QGIS default toolbars' checkable buttons press ...
1
vote
1answer
44 views

Use QGIS plugins in custom standalone application [duplicate]

I am trying to create a QGIS custom standalone application. I want to add the Google Physical map from OpenLayers plugin to my application when it starts, but I cannot seem to be able to access ...
1
vote
1answer
72 views

Show feature count of layer via Python console / PyQGIS

When working with vector layers in QGIS, I can display the feature count of a layer and, if applicable, the feature count per attribute category (e.g. when using categorized or graduated styling) via ...
0
votes
1answer
44 views

Filter MapComposer legend to only show layers visible on the map

I have written a function in Python / PyQGIS (no standalone application, so copy/paste it to the Python console editor to run it) that takes a VectorLayer as argument, creates a MapRenderer object for ...
1
vote
1answer
72 views

Use PyQGIS to import CSV and draw points using different color

A CSV file contains columns latitude, longitude and color. uri = "file:///C:/data/balls.csv?type=csv&xField=longitude&yField=latitude&spatialIndex=no&subsetIndex=no&watchFile=no" ...
1
vote
0answers
28 views

Highlight the selected feature with different colors

Is it possible to change the color of a selected feature in qgis 2.2.0 Valmiera? To highlight a feature I use: aLayer.Select(feat.id()) box = vlayer.boundingBoxOfSelected() ...
0
votes
0answers
35 views

Free ebooks of QGIS [duplicate]

I am new to QGIS and python. Can any one tell me, where I can find QGIS and Pyqgis ebooks for free.
1
vote
1answer
101 views

Calculating distance between latitude and longitude by using python

I have a database of 2000 points, which is in csv format of latitude and longitude. I want to find distance between these points all at once. And also showing these points in Map by using only pyQGIS. ...
1
vote
1answer
49 views

How to load a *.qgs file in a C++ QGIS standalone app?

I'm using QGIS-2.4.0 API to develop a standalone app by C++. I saved a test.qgs file in QGIS Desktop software, in the project, there was one layer and it was visible. Then I loaded the test.qgs ...
1
vote
2answers
28 views

QGIS 2.4 crashes when symbolizing QgsComposerShape in Python with ScriptRunner

I'm attempting to use ScriptRunner to output a jpeg of a red rectangle using QGIS Composer to understand the QgsComposerShape. Everything works except QGIS crashes when the symbol is applied. The ...
0
votes
0answers
17 views

Restart plugin from PyQGIS

I'm writing a plugin for QGIS and inside the method def run(self), after the OK button of the plugin is clicked, i.e., inside # Run the dialog event loop result = self.dlg.exec_() # See if OK was ...
2
votes
0answers
58 views

Iterating between two layers using QGIS python

I will try and explain my situation as clearly as possible. I just created my first plugin that is being used to analyze between various layers and give back quantities to the user. Most of it is ...
1
vote
0answers
35 views

Error Loading Layer/Shapefile in a Standalone Python QGis Application

I tried loading a shapefile on Python using PyQgis API but to no avail. I double-checked the path to shapefile and found it to be correct. QGIS module also seems to be imported just fine. When I ...
1
vote
1answer
40 views

PyQGIS reload a QGIS plguin

I have a plugin that has a psycopg2 connection to a PostGIS database. When i close GUI with the X-Button and open it again, all the widgets are filled with the data from before. It looks like the X is ...
2
votes
2answers
48 views

Setting layer visibility in QGIS Python API

Im having a problem toggling the visibility of map layers in pyqgis (2.4). I have a simple interface, just the map canvas, no legend, and basically a radio button that toggles between two raster ...
0
votes
1answer
29 views

osm2pgsql doesn't run in a QGis plugin

I have a problem with osm2pgsql when it runs in a qgis plugin. The function i use looks like this: osm2pgsql = "osm2pgsql -s -d {databaseName} -U {databaseUser} -H {databaseHost} -E ...
0
votes
1answer
55 views

How to run and debug PyQGIS scripts in PyCharm Community Edition 3.4.1

I am working with creating plugins for QGIS 2.4.0 (Chugiak). I am curious to know how I can write the codes, and debug them in the environment I am comfortable in, i.e. PyCharm Community Edition ...
4
votes
1answer
94 views

Why are my calls to SAGA routines in QGIS not working cross platform?

The ability to write and run cross platform scripts for QGIS using python is OUTSTANDING! However, when I try to run the SAGA:MERGESHAPESLAYERS algorithm from a python script it works fine in windows ...
2
votes
1answer
54 views

Create a new layer in PyQGIS with the same attributes of another preexisting and copy some elements in it

I'm new in QGIS and I'm trying to create my first plugin. I have a layer containing lots of elements of type Point, Line and Polygon. Suppose I want to create two new layers with the polygons above ...
1
vote
1answer
39 views

Get a list of layer names using PyQGIS

I need a list containing the names of all the layers in a QGIS session. I did the task as layersNames = [] for i in self.iface.mapCanvas().layers(): layersNames.append(str(i.name())) but this ...
2
votes
0answers
29 views

Assigning Color Ramp using PyQGIS

According to the PyQGIS Cookbook, a color ramp can be assigned in the following way: rlayer.setColorShadingAlgorithm(QgsRasterLayer.ColorRampShader) lst = [ QgsColorRampShader.ColorRampItem(0, ...
1
vote
0answers
28 views

Arcpy and pyqgis on same IDE

I have question: is it possible to set up arcpy and pyqgis on the same IDE (I use Pycharm). I have some problem with running my pyqgis scripts from pycharm. When I first configure Pycharm to recognize ...
1
vote
1answer
38 views

How to programmatically create nested layer groups?

Using PyQGIS via the QGIS 2.4.0 Python console and the editor, I can create parallel groups for storing some layers with: MyFirstGroup = iface.legendInterface().addGroup('Group No. 1') MySecondGroup ...
0
votes
1answer
22 views

When does iface.mapCanvas().layers() get updated to the contents of QgsMapLayerRegistry.instance().mapLayers()?

Since the topic might be a bit cryptic, I'll try to explain where my problem is. I am currently developing a Qgis-plugin, where I am creating and adding some layers automatically, which I would like ...
1
vote
1answer
75 views

How to create a Processing script using the shortest path algorithm?

I'm currently using the Road Graph plugin to find the shortest path in a road network - however, I'd like to put this to a processing script (to be used in a model later) and the Road Graph Plugin has ...
2
votes
0answers
51 views

How to get user and password of a PostGIS layer

I wonder if it is possible to get the user and password for a PostGIS database if they are stored in the PostGis connection information. I get the connection information at the moment from the ...
2
votes
2answers
58 views

QGIS layer tree API returns only groups and not layers

I am trying to use the QGIS python API to read out the groups and layers in a QGIS (2.4) project. Here is a code snippet from my script, which is run from a shell, not from the QGIS python console! ...
2
votes
0answers
39 views

How setup python path in my ide to recognize QGIS API

I'm using Intellij with python plugin. Classpath for python contains $QGIS/apps/qgis/python but my ide not recognize eg. QgsVectorLayer. Any additional entry is required?