Python bindings for QGIS.

learn more… | top users | synonyms (1)

3
votes
1answer
88 views

Qgis Python: Find bounding box for multiple features?

I want to find the bounding box of several features selected by their attributes. Here's what I've been trying: tNumList = [8,9,10,11] selectGeom = QgsGeometry() for tNum in tNumList: request = ...
3
votes
1answer
70 views

Showing QgsAddAttrDialog in a Python plugin

I want to invoke the builtin add field dialog from my python plugin in QGIS: This is the add attribute dialog of the attribute table. It is located HERE. I expect it to return a QgsField. ...
3
votes
1answer
106 views

Get results from using GRASS algorithms with the QGIS processing tool

I am trying to write a plugin in QGIS that uses at some point a GRASS algorithm : "v.split.length", accessible by using the processing class, and here is how I am using it : ...
10
votes
0answers
220 views

PyQGIS save raster as rendered image, then use GDAL tools on it

I have tried to use the code from QGis Save Raster as Rendered Image. i is a raster layer: pipelayer = i pipeextent = pipelayer.extent() pipewidth, pipeheight = (pipelayer.width(), ...
4
votes
1answer
65 views

Troubles Updating Values of Selected Features with PyQGIS

I'm trying to modify the values of some selected features. I have written this small script, but nothing happens when I run it. Is there something that I've missed? Here is my code. lyr = ...
3
votes
0answers
94 views

Can qgis_core work with external python distribution (such as Anaconda)

I've built a python application that has its own GUI. I am trying to use qgis.core/pyQgis as map display only. Specifically, i have anaconda 2.3 and its python distribution (2.7.11). After research on ...
3
votes
1answer
111 views

Standalone python app that uses qgis.core without installing qgis

I am building a standalone python application that has its own GUI, i would like to use qgis.core/pyqgis as a map display only. But from my searches on this topic, it seems that the full QGis software ...
0
votes
0answers
31 views

How to run a function in a while loop while an QObject is activated/triggered in PyQgis

Firstly I am new to PyQgis and there might me a lot of basic errors. The aim is that everytime a new vector object is drawn its attribute should automatically update while a QAction I have created ...
1
vote
2answers
99 views

How to define outline color from polygon layer using Python?

I´m using a QGIS 2.8.3 and I want to define a style for the legend of my polygon layer. I was using this code that works perfect: str1= 'C:/Documents/Layer.shp' myVectorLayer = QgsVectorLayer(str1, ...
3
votes
2answers
100 views

How to Check if a Layer is PRESENT or ABSENT in a Project via PyQGIS?

In QGIS, what is the simplest python code (least possible) to verify if a particular layer is PRESENT or ABSENT in the Map Layers list? NOTE: The script shouldn't trip an error IF the layer is ...
1
vote
0answers
45 views

Try/Except Statement gives different Results in QGIS Console vs. QGIS Tool

I want my script to do different things depending on whether a particular layer DOES or DOES NOT exist in the Map Layers list. I thought the try: / except: statements would be the best way to achieve ...
1
vote
1answer
54 views

How to add a layer using actions in PyQGIS?

I'm learning to use the python console within QGIS. I want to add layers like iface.actionAddOgrLayer(), open projects and more by the action-function, but without any response - only the string ...
1
vote
1answer
36 views

Render QgsRasterLayer without adding to legend

I am trying to render a number of related QgsRasterLayer objects that are related to eachother (they are slippy-type tiles). Ideally I would like one item in the legend that can have its position ...
6
votes
1answer
114 views

Adding PostGIS layer from QGIS Python plugin

I try to develop a plugin to add postgis layers to qgis from a plugin as part of learning python. The code for adding a postgis layer is taken from the cookbook and work fine if I run it from the ...
1
vote
1answer
69 views

Apply symbol to each feature (Categorized symbol)

I want to apply unique symbol to each feature. i have used following code for doing that from qgis.core import * from PyQt4.QtGui import * # supply path to where is your qgis installed ...
3
votes
1answer
76 views

How to define the number of decimals when adding a new field as double to an attribute table with python in Qgis 2.1?

How to change the expression in order to define the number of decimals? layer.dataProvider().addAttributes([QgsField("fieldname", QVariant.Double)]) As I read in QGIS API Documentation: ...
2
votes
0answers
66 views

Loading a qgsproject when another one is loaded

I am loading a project with: QgsProject.instance().read(QFileInfo(path)) When i try to load another project it subtracts the layers and shows nothing. But if I try doing it again it works.
1
vote
1answer
57 views

wrapped C/C++ object of type QgsGeometry has been deleted ubuntu and mac and segmentation fault

I have a problem with a specific method in qgis 2.8, 2.12 and 2.12.1 on linux and mac (I have not idea if in windows this problem persists) The example: from qgis.core import * from qgis.utils ...
1
vote
1answer
38 views

Set a Vector input as a variable in QGIS Tool Script

In a QGIS script, how do you set a Vector input (via your tool's GUI) as a variable which can then be used in subsequent processing in your tool's script? I know how to set a map Layer as a variable, ...
5
votes
1answer
115 views

How to use third-party package in a QGIS plugin?

I'm developing a QGIS plugin and I would like to use arrow or requests packages as I'm used to manipulate dates and REST APIs. QGIS does not come with these packages (at less arrow), so when I try to ...
5
votes
0answers
51 views

See python script running while processing a task in QGIS?

Is it possible to see scripts running in Python Console - everything from tools and analysis vector to raster?
4
votes
1answer
314 views

Set selection color transparent and border color red in QGis using python

I have a layer with different informations. I want to change the selected polygon color to "Transparent". I am able to achieve that using: iface.mapCanvas().setSelectionColor( QColor("Transparent") ) ...
2
votes
1answer
63 views

Populate combobox with postgis layers

I'm new to pyqgis/python and programming in general.. and i am working on my first small project. I want to create plugin so that I can add layers from my PostGIS database to a QGIS project. I ...
1
vote
0answers
53 views

Label layout on python in QGIS

Now the only issue is that in image I am not getting the labels, I have on polygon. Please help in that too Please see above attached screenshots here I need labels – I have updated QGIS it's version ...
4
votes
1answer
73 views

Rename field QgsField is not valid

In pyQGIS i tried this code (contains also debug prints): def joinLayers(inputlayer, layer, index_field, name = "JOINED", dataProvider = "ESRI Shapefile"): a = [] b = [] outpath = ...
3
votes
1answer
68 views

Layout show label and each polygon make serrated image

I want to develop "Print lay out functionality", but in output system is giving me whole image, I want to print only selected polygon. Also it is not displaying label names on print image. Please ...
3
votes
0answers
60 views

How to show only selected features from a a layer in the QgsComposerLegend?

I have developed a custom qgis plugin. I have a button to export the map canvas in the form of image along with the legend. I came up with the following code for the legend: legend = ...
5
votes
1answer
96 views

How to set keyboard shortcuts for 'Layers' and 'Browser' panels in QGIS 2.12.1 Lyon?

I have been using the python solution presented in this answer, which has worked well from 2.6 to 2.10 for me, and still works in the LTR 2.8.4. I can't get it to work with 2.12 (and recent point ...
1
vote
0answers
36 views

Manage QGIS layer table content within a plugin?

I want to embed a layer table in a plugin but it's not only for viewing but also for editing. My current code below displays the content from PyQt4.QtCore import * from PyQt4.QtGui import * from ...
5
votes
2answers
113 views

How to create memory layer and populate fields?

Seems like a basic operation using PyQGIS but can't see what I am missing. I want to create a memory layer with the exact same features and attributes from a shapefile. I have looked several posts ...
5
votes
1answer
78 views

Batch “Save as” layers w.r.t their geometry type in QGIS?

We have 100's of dgn files. We have successfully "assigned" coordinate system to those dgn files in batch by using "on the fly" + custom CRS. Now we have to save each dgn's geometry (Point, ...
2
votes
1answer
78 views

How to get perpendicular line script to work?

I'm trying to get this script to work by @gene but I'm not sure how to load the results into QGIS. I tried to make a memory layer but not sure how to add the geometries of the point, line and the ...
0
votes
0answers
29 views

Cannot retrieve attribute information from PostGIS layer

I want to develop a simple plugin and try to get started with python in QGIS. However, I have already run into troubles just loading my data properly. From the cook book Iam using the code below ...
4
votes
1answer
103 views

Updating feature attribute in QGIS plugin?

I am writing a plugin for QGIS (v2.12). There have been quite a few similar questions on this forum, but they don't seem to work for me. my plugin does the following: get the vector layer check ...
0
votes
0answers
50 views

PostGIS and QGIS connection using queries?

I have a shapefile and a table which I import both of them to PostGIS. With pgAdminII I am able to manipulate the table, join to shapefile and calculate new fields. When I try to do that with python ...
4
votes
3answers
286 views

Change QGIS background colour using python

I would like to change the background colour of a QGIS project using python. I can change the colour using the GUI via the Project Properties dialog: However, I cannot find the equivalent setting ...
5
votes
1answer
180 views

How to replace a shapefile name in a directory using Python QGIS?

How to replace name or delete .shp file from directory using Python QGIS ? import os import processing input = "//input.shp" output = "//output_100.shp" interval = 100 ...
3
votes
1answer
70 views

How to fix Quickfinder OperationalError: table quickfinder_info already exists?

This is what I am getting when I try to search in project layers and create a .qfts file to use quickfinder on a local shapefile. An error has occured while executing Python code: Traceback ...
7
votes
2answers
133 views

Why do I get different results from PyQGIS feature.geometry().type()?

On the python console in QGIS what is the difference between the following two code snippets (activeLayer is a polygon layer): # 1) iface.activeLayer().selectedFeatures()[0].geometry().type() ...
1
vote
1answer
47 views

How to select attributes by unicode field value?

I have an attribute table in QGIS 2.10 with a string field (myfield) and when I want to make a selection based on the unique values of this field I get no selection at all. >idxmyfield = ...
1
vote
0answers
20 views

Creating menu item and adding more than 1 plugin in QGIS?

Because if I execute these lines for each plugin, I created a menu item for each plugin. I created many plugins and wish to place them in a new menu item (not traditionals)
4
votes
3answers
148 views

Quickly make server side spatial filters for WFS layers based on other layer's selected geometries in QGIS

In QGIS 2.12.1, I have a WFS layer which is huge so I don't want my users to load it entirely but only parts of it based on intersections with geometries. Today, I'm using the query builder and ...
1
vote
0answers
64 views

Can you build a login window in QGIS?

Can you build a login window before loading QGIS interface? I use QGIS 2.8 I just built message windows when loading QGIS interface, but no more.
4
votes
1answer
80 views

How to get the list of QgsPoint from a polygon Layer in pyqgis

I have a little question about how to manage the points in a layer. from qgis.core import * def run_script(iface): layer = QgsVectorLayer(layerType.Polygon+'?'+crs.psg_4326, ...
32
votes
4answers
710 views

Generating equal sized polygons along line with PyQGIS?

I would like to create polygons along a line to use them for AtlasCreator in a next step. ArcMap has a tool called Strip Map Index Features. With this tool I can choose the height and width of my ...
3
votes
1answer
74 views

PyQGIS - Densify geometries given an interval

I have question, is it possible to make python command for QGIS function "Densify geometries given an interval": input layer: Polygon.shp output layer: Densify_interval.shp interval: 50 meters ...
2
votes
0answers
75 views

heat map plugin from QGIS python console

I am trying to use the heat map plugin from the processing console. On the QGIS documentation it says the plugin uses Kernel Density Estimation. I have used the saga Kernel Density Estimation but do ...
3
votes
1answer
115 views

Using standalone pyQGIS application QgsApplication.initQgis() fails?

I'm trying to execute the following code on a windows 7 system: import qgis.core as qc qgis_path = "C:\Program Files\QGIS Lyon\apps\qgis" qc.QgsApplication.setPrefixPath(qgis_path, True) ...
2
votes
1answer
56 views

Clean way to identify color scheme in Python QGIS

When I do in the Python QGIS console QgsColorSchemeRegistry.instance().schemes(), it returns the following [<qgis._core.QgsColorScheme object at 0x7f6cc5d8ccc8>, <qgis._core.QgsColorScheme ...
1
vote
2answers
108 views

Select feature one by one not working in pyQGIS?

I have used following code for selecting the features one by one. but when i run the script it is just selecting last feature and zoom it. I want to select each feature and zoom it. def ...