Python bindings for QGIS.

learn more… | top users | synonyms (1)

1
vote
2answers
58 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
79 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
42 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
37 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
27 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
80 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
26 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
58 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
53 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
42 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 ...
4
votes
1answer
83 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 ...
4
votes
0answers
41 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?
3
votes
1answer
135 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
47 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
35 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
65 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
59 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
37 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
61 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
28 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
84 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
62 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
68 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
22 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
89 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
45 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
104 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
132 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
56 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
83 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
40 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
16 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
113 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
59 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
59 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, ...
30
votes
4answers
553 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
66 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
44 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
57 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
51 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
81 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 ...
5
votes
1answer
203 views

Getting QGIS python modules to work from PyScripter in Windows 10?

Been trying lots of "solutions" from net research but nothing seems to work. I have the current versions of QGIS from OSGEO and PyScripter 2.5 Based on one of the solutions I tried... import sys ...
4
votes
1answer
82 views

Select feature one by one and save it as image

I have used following code for selecting the features and save it as image. layer = self.iface.activeLayer(); layer.setSelectedFeatures([]) count =layer.featureCount() lstChalta = [] lstFeatures = ...
2
votes
2answers
25 views

PyGIS remove QgisVertexMarker from scene

I am writing a plugin that includes interaction with the map. Therefore I use a QgsMapTool. It is possible for a user to mark a point on the map. When the user clicks a red X is drawn on the mapCanvas ...
1
vote
1answer
29 views

How to change and display the plugins icon in the menu in QGIS

I want to add multiple icons in the same file to display the plugins icons in the menu. def initGui(self): action = self.add_action( ':/plugins/Example/icons\icon1.png', ...
3
votes
1answer
114 views

PyQGIS - polygon to lines with geometry length and select features with condition

How can I make a script to convert polygon layer to explode lines ? After that I need to get geometry length for conditioned features. I have a part of code ? import processing ...
2
votes
1answer
69 views

Creating set of maps (PDF) using QGIS and Python with WMS Data

For a scientific project I am trying to create a set of PDFs in QGIS with a fix layout (in the print composer) but per PDF a) different map item attributes (extents) and b) a QR-code to identify this ...
3
votes
1answer
97 views

Split feature by line in PyQGIS

My objects are a polygon and a line. I want to split my polygon according the line. I have used reshapeGeometry and splitGeometry with no success. ReshapeGeometry returns 0. Polygon-foo foo = ...
3
votes
1answer
48 views

Unable to print anything or write anything to file in python after importing processing

I've been trying to get standalone QGIS python scripting to work, but for some reason after I import processing, I cannot print anything to the console, nor can I write anything to file. My end goal ...
1
vote
1answer
49 views

Random sample from selection

I have a selection in vector point. I would like to do random sample from it. I am using qgis to do it. Here is my selection code: ...