Python bindings for QGIS.

learn more… | top users | synonyms

3
votes
1answer
53 views

Why must I write `geometryType() == 3` for point and polygon shapefiles?

I am asking this question based on the result I received from this earlier post. The following script only works if I set geometryType() == 3 as that is what is being printed out in the Python console ...
1
vote
0answers
18 views

Using processing using other output (result from another algorithm) as input

I have a problem. I am developing a standalone app in python and I need to use processing algorithms. I was able to use one algorithm without erros but I need to run other processing algorithm which ...
2
votes
1answer
24 views

QGIS toolbars source code

I can see the source code of the core QGIS plugins from the repository in github. But is there any repository of source codes for QGIS toolbars also?
2
votes
1answer
72 views

Run processing toolbox outside QGIS in standalone app

I am developing a standalone app in Python, using QGIS libraries including processing algorithms. I am developing in Linux environment and I put the libraries in a folder. Also I put the processing ...
2
votes
0answers
32 views

Efficiently generate Voronoi layers in qgis via Python

The following python commands both appear to function when called in qgis 2.6 to generate Voronoi diagrams: processing.runalg("qgis:voronoipolygons", pointLayer, 1, None) ...
5
votes
2answers
35 views

Start QGIS with virtualenv Python

is there any means of telling QGIS to use a different Python installation than the default, system-wide one? E.g. use some virtualenv Python /myvirtualenv/bin/python instead of /usr/bin/python? ...
2
votes
2answers
76 views

How to customize the QGIS default GUI using Python?

Is it possible to hide/remove/customize the default UI of QGIS from a Python plugin? I want to add my own menus and toolbars and remove some included by default in QGIS. If it's possible, which ...
3
votes
1answer
119 views

How to prevent users from removing QGIS layers?

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 ...
2
votes
1answer
139 views

Problem with import qgis.core when writing a stand-alone PyQGIS script

I am trying to write a stand alone python script in windows 7 that uses qgis.core and various other qgis libraries. I have found an old question on this subject here: How to write standalone Python ...
1
vote
0answers
95 views

Pyqgis 2.2 : How to allow editing on layer and features [on hold]

I'm writing a pyqgis plugin with qgis 2.2 I succeeded in accessing and displaying vector data (geometries & attributes). Now I would like to allow editing for all my layers and all features ...
1
vote
1answer
31 views

PyQGIS: feature added signal throws an error message

For my PyQGIS plugin 2.2, I try to: def logFeatureAdded(self,layerId,addfeatures): message = str(layerId) + " has features added: " for feature in addedFeatures: message += str( ...
3
votes
2answers
32 views

Send signal when attributes modified - QGIS 2.6

For a QGIS 2.6 python plugin, I am trying to send a signal when an attribute value is changed (values for an existing feature are updated or added and the attribute form dialog is accepted). This ...
1
vote
0answers
22 views

Custom QGIS 2.6 map tool - mouse click and release issue

I have create a custom map tool for QGIS 2.6, implementing a canvasReleaseEvent and canvasPressEvent. I can't though get the signals to work on one single mouseclick (I have to click twice). My map ...
1
vote
1answer
19 views

If statement using QgsRasterCalculator

So in the sequence of my previous question (Can't use Raster Calculator with two different rasters), I am stuck again in my project. With my source rasters, I created 3 different outputs using ...
1
vote
1answer
20 views

Why use QgsFeatureRequest() when iterating?

I am unclear on why one should use QgsFeatureRequest() when iterating over a file’s features. Let’s say I would like to print out all IDs in my currently active dataset. Now, most examples will ...
1
vote
1answer
63 views

How to select and zoom in features from a QGIS Python Plugin

I'm very new to Python. I'm trying to find a way to select and zoom to the features from a QGIS layer. I've created a plugin and built a custom form. I have 3 values from the form which I need to ...
2
votes
1answer
116 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 ...
7
votes
2answers
550 views

How to write scripts that can call on both Arcpy and PyQGIS?

I have spent quite a bit of time looking for a clear answer this topic and have still been unable to really accomplish my goal of accessing PyQGIS in a stand alone script. Parts of answers have been ...
0
votes
1answer
25 views

User Interface file compilation using OSGeo4W shell during qgis plugin creation

I am trying to build a plugin in Qgis2.6 using plugin builder. And as a part of the same, I tried compiling the .ui and .qrc file using OSGeo4W shell. It is showing an error during compilation in ...
2
votes
0answers
29 views

How to select the features by freehand in qgis using python programming

I have one polygon layer with 10 features. when i draw a line by free hand on the polygon layer it has to select the features. But when i am using qgis.utils.iface.actionSelectFreehand().trigger() ...
5
votes
2answers
531 views

Load and display a layer 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 ...
6
votes
2answers
269 views

How to load a raster layer at the top of the QGIS ToC?

The following code inserts my new_layer just above the active layer in the QGIS ToC. new_layer = iface.addRasterLayer(...) Instead, I'd like my new_layer to be inserted at the top of the QGIS ToC. ...
1
vote
1answer
37 views

How to create a text file containing layer names in QGIS?

My QGIS ToC contains layer groups and some layers that do not belong to any group. I would like to create a text file containing the name of those layers that do not belong to any group. Is there an ...
1
vote
1answer
25 views

QGIS 2.6 : Programmatically setting key value pairs for ValueMap widget

Using QGIS 2.6 and Python 2.7 on Windows 7, I am trying to programmatically insert key value pairs into a ValueMap widget via a csv file. Issue is that some of the values are properly inserted and ...
2
votes
0answers
34 views

How do the architecture in qgis plugin creation is linked with eachother using plugin builder?

I am just trying to understand how the architecture or the workflow is linked each other while QGIS Plugin creation using plugin builder. It would be better for me to understand if anyone explains ...
3
votes
2answers
680 views

How to debug 'Layer is not valid error' from Python plugin?

I'm trying to understand what goes wrong with a QGIS python plugin. Basically I'm trying to render a series of POINT. The query works fine, at least giving it by hand from inside PostGIS DB: "SELECT ...
1
vote
1answer
73 views

How to add fields to shapefile from standalone script?

When I run the following script via OSGEO4W64 Shell, I receive the following error when trying to run the qgis:fieldcalculator algorithm: 'NoneType' object has no attribute 'mapCanvas' I read ...
2
votes
0answers
26 views

QgsRubberBand with holes

I tried to create a QgsRubberBand object with holes, but failed: rb = QgsRubberBand(iface.mapCanvas(),True) geom = QgsGeometry.fromWkt("POLYGON((0 0,4 0,4 3,0 3,0 0),(1 1,3 1,3 2,1 2,1 1))") ...
6
votes
1answer
69 views

Why the order of imports matters in a standalone PyQGIS processing script?

I've come across a weird issue while running standalone PyQGIS processing scripts. The order of imports in the script affects its normal execution. You can reproduce the problem by opening a Python ...
3
votes
1answer
998 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) ...
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
0answers
20 views

Error while creating QGIS plugin

I tried developing a python plugin in QGIS2.6 following the instructions in the link http://anitagraser.com/2014/04/26/getting-started-writing-qgis-2-x-plugins/.When I launch the plugin in QGIS after ...
1
vote
1answer
54 views

Load the raster image which is in TIF format using QGIS API

I am quite new inthe field of GIS. I am interested in is to load the raster image which is in TIF format using QGIS API I have followed the steps given the in the follwing link to load shape file ...
1
vote
1answer
22 views

How to select features using an expression with pyqgis?

How can I select features with pyqgis using an expression? I tried to use an QgsExpression but the select method doesn't take it: exp = QgsExpression("'ogc_fid' = 482") cLayer = ...
1
vote
1answer
28 views

How to zoom to selected feature with QGIS Python Console

I want to select a feature by ID and zoom to it. I tried the following but the canvas doesn't change. Any ideas? canvas = qgis.utils.iface.mapCanvas() cLayer = canvas.currentLayer() cLayer.select(51) ...
0
votes
2answers
43 views

Is there scripts of QGIS core plugins available anywhere?

Is there anywhere I can see the scripts of the Qgis core plugins.
4
votes
3answers
2k views

How can I specify the CRS of a raster layer in pyqgis?

I manipulating netcdf raster data from the QGIS python console. The metadata of my netcdf file does not provide the Reference system. However I know it is 'EPSG:4326' I am writing a python script to ...
1
vote
2answers
25 views

How can I disable logs being created in standalone python script?

When I run the following script in QGIS 2.6.1, it produces a folder called 'processing', which contains a log, in the directory it reads files from. And since the script reads files from several ...
2
votes
0answers
47 views

How to modify current QGIS canvas from python script?

I want to zoom into the current active QGIS canvas from a standalone python script. I tried the following but it doesn't impact the current QGIS canvas: import qgis.utils canvas = ...
2
votes
1answer
162 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
36 views

How to add a column/feature with PyQGIS 2.x?

I'm using PyQgis 2.2 and I'm creating a plugin. I want to add one feature/column to a shapefile. But I get error.. I've tried to do this as it's shown in Cookbook: if caps & ...
2
votes
1answer
48 views

How to get shapefile extent from standalone script?

I am trying to obtain the extent of a polygon in a shapefile. I am running a standalone script which will create a grid based on the extent of the polygon. I have tried 2 methods: one from the ...
2
votes
2answers
176 views

Save a layer for each unique value using Python in QGIS

I have a map, in which each region is defined as an attribute of the map (I can select each region from the attribute table). I am trying to create new layers each one containing only 1 region using ...
3
votes
1answer
53 views

Removing a vector layer from QGIS [duplicate]

Considering my program is generating a shapefile that has to be added to the "Layers" tab in QGIS interface. However, once the utility of the layer is completed, I need to remove the layer in the ...
3
votes
1answer
52 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 ...
3
votes
0answers
14 views

Error writing buffered memory layer to shapefile in QGIS

I have created a memory polygon layerin my QGIS plugin. Then I added a buffer based on a point. I can see the ploygon layer in the map canvas and I can save it to a shapefile from the main GUI. But ...
2
votes
2answers
148 views

pyqgis: AttributeError: 'QgsRasterLayer' object has no attribute 'drawingStyle'

qgis gurus. I have a question about pyqgis and hopefully I can get some advise here. I am following http://www.qgis.org/en/docs/pyqgis_developer_cookbook/intro.html. In python console after a raster ...
2
votes
2answers
89 views

IdentifyFeature() use via PyQGIS?

Intent is to have two variables (QgsVectorLayer and feature.id() within said layer) as input for the Identify feature map tool in Qgis (2.6). Wondering if a feature can be selected programmatically ...
2
votes
3answers
89 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(): ...
5
votes
3answers
1k views

How do I get the path of a project, or layer file in PyQGIS?

I am generating new raster files from vector layers on a project. I would like to save them in the same directory as the project or layer files. How do I find this path using PyQGIS?