Python bindings for QGIS.

learn more… | top users | synonyms (1)

5
votes
2answers
3k views

Problem loading vector layer (pyQGIS)

I've installed the qgis on ubuntu 12.04 following the instructions on http://hub.qgis.org/projects/quantum-gis/wiki/Download. I am trying to test the Python API and try to do the follwoing from qgis....
5
votes
2answers
221 views

How to find disconnected islands in a road network layer, using QGIS

I have a road network layer that can't route from one side of the layer to the other. Topologically, there is no connectivity between the start and end nodes, probably due to missing links. This ...
5
votes
2answers
819 views

How to add a legend to a canvas in a standalone PyQGIS application?

I am trying to develop a standalone PyQGIS application. The map display does not pose any problems, but I do not know how to add a legend to the canvas.
5
votes
3answers
2k views

How can I define the layer CRS for a memory layer in pyqgis?

How can I define the CRS for a memory layer from the QGIS project settings? vpoi = QgsVectorLayer("Point", "vectpoi", "memory") feature = QgsFeature() feature.setGeometry(QgsGeometry....
5
votes
1answer
1k views

Get extents of vector shape features in python

i am just wondering if it is possible to iterate through vector features and return the extent per feature without clipping the vector shape? The code looks like this and comes from the PyQgis-...
5
votes
1answer
172 views

Automating QGIS project composer printing?

I have a large project which consists of around 10x QGIS project files. Each project contains a print composer with an atlas set up to generate up to 10 maps. What is the easiest way to automate the ...
5
votes
1answer
252 views

Do I have to publish own QGIS plugins?

If I develop QGIS plugins for my company do I have to make them available to others? I use QT-Designer and think that it also depends on the question how you develop your plugins, right? For example: ...
5
votes
1answer
5k views

PyQgis question: How to change or set active layer?

Developing a qgis plugin, I found that if no layer is selected in the Layers panel I can iterate over all layers and do anything to them, but "activate" them. Could someone give me a hint please? ...
5
votes
1answer
125 views

Understanding background to Single Hash (#) Vs. Double (##) in QGIS Python Scripting?

First of all I understand the double hash (##) is used to define the Inputs / Outputs in a script's GUI. If there's more to it than that please let me know. In all other Python coding I've done ...
5
votes
1answer
506 views

Programmatically grouping multiple layers into separate groups using QGIS?

I'm trying to group a large number of layers together based on a common portion of name string. They are a mix of polygons and points. I would like to create individual groups by using part of the ...
5
votes
4answers
2k views

How do I rename Shapefiles in QGIS?

I have a huge list of layers in a project that are named in a foreign language. I want to translate and add the English title to the name. When I right click on a layer and choose Properties -> ...
5
votes
2answers
1k views

How to add a layer group using pyQGIS?

Good morning, I would like to know how I can create a new group in the layer manager using python code, someone could help me?
5
votes
1answer
2k views

How can I create a new layer from the currrent selection?

Is it possible to create a duplicate layer, only displaying the selection from the layer you are duplicating in QuantumGIS? Simular to ArcGIS -> Create Layer from Selected Features. I looked at "How ...
5
votes
1answer
100 views

Keep UI Settings for a QGIS plugin

I'm writing a plugin that interacts with external software (hydrological models). One of the dialogs has a lot of entries (parameters to pass to the hydrological software). Once the user has set up ...
5
votes
2answers
139 views

QGIS python processing.runalg Clip returns None

I'm writing a script in pyQGIS, which would emulate measurement of a line by "walking" along it with a compass with constant length. I have a problem with the Clip algorythm from processing module, ...
5
votes
2answers
107 views

Why can't I multiply values from column named 'length' using field calculator via PyQGIS?

I want part of my plugin to multiple value of length and add it to table.Basing on this question: How to use QGIS field calculator in python? , I made script that works fine for some filed: I can ...
5
votes
1answer
80 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 = qgis.utils....
5
votes
1answer
2k views

How to merge shape files with attributes from a python script in QGIS?

I have some shape files. They are all the same kind of shape and all have the same attributes. If I wanted to merge them manually the "Vector/Data management tools/merge shape files to one" works ...
5
votes
1answer
412 views

Can one expose variables to the Python console from a plugin in QGIS?

I have a QGIS plugin that performs a long-running operation, eventually producing and loading new shapefiles into QGIS. (I have this as a plugin rather than just a function that can be called from the ...
5
votes
3answers
567 views

How to iterate over selected layers?

In QGis by pressing shift or ctrl keys a user can select multiple layers in toc. How can a python script iterate over selected layers? I'd expect a iface.selectedLayers() but I can find only iface....
5
votes
1answer
78 views

Load WMS with PyQGIS

I have installed QGIS server on Ubuntu 14.04 which serves WMS. Connection uses https and basic auth. URL is https://my.awesome.url:8090/cgi-bin/project1/qgis_mapserv.fcgi I can connect with QGIS and ...
5
votes
1answer
168 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 ...
5
votes
2answers
150 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
273 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 processing.runalg("qgis:...
5
votes
1answer
275 views

How to use qgis:selectbylocation in PyQGIS?

I am trying to use the processing toolbox to perform a spatial query (points in polygon). I am not sure how to use the tool and I keep getting Error: Wrong number of parameters. Here is my script: ...
5
votes
1answer
322 views

Extent problem in PyQgis

I'm trying to set the extent of a square feature to the canvas, that works in QGIS, but when I print the canvas into a PDF, it always gives me some empty area, below is the screenshot of QGIS canvas ...
5
votes
2answers
3k 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 ...
5
votes
1answer
500 views

Can I use QGIS plugins in PyQGIS as a stand alone script without iface?

Can I use a qgis plugin especially (openlayers plugin) in stand alone pyqgis script? I don't find examples, just code using iface but that cannot used in stand alone script.
5
votes
1answer
1k views

clip geometries in postgis table if they are inside a polygon

I have polygons defined in KML files just like this one, which I can easily parse. Example: <Polygon><outerBoundaryIs><LinearRing><coordinates> -91.463940,40.372660,0 -91....
5
votes
2answers
370 views

What's the most efficient way to load feature attributes into a numpy array?

I am currently working on an add-on that relies on the user choosing fields of tables (that can be from shapefiles, csv or dbf) that are open in QGIS and then making computations with such data. ...
5
votes
1answer
1k views

QgsMapRenderer to export current extent using PyQGIS

I am trying to accomplish PyQGIS simple map rendering via the QGIS 2.0 Python console, but end up with only a blank image. I've followed instructions of this link. My objective is to export a simple ...
5
votes
1answer
2k views

How to deploy a QGIS Python Standalone Application with minimum installation size?

I am trying to create a Standalone QGis Application using python. I was able to create the nice looking shapeviewer application by following the steps here. Now I would like to deploy this in ...
5
votes
1answer
1k views

How to Create a raster layer from a numpy array using pyqgis?

I am working on a plugin for Qgis to calculate spatial Kernel density maps. I have all the calculations working, all I am missing is a way to turn a Numpy Array, with density values into a multiband ...
5
votes
1answer
2k views

How to find all intersections and count lines arriving at each intersection?

I'm having a hard time getting off the ground with this, and am trying to move away from ArcGIS / arcpy. I have a shapefile with a network of polylines. I want to find/count all 2-way intersections, ...
5
votes
1answer
111 views

How to define border colour for rule-based style using PyQGIS?

I use the following to create a Rule-based style for a given layer which includes defining a label, expression and colour fill: from PyQt4.QtGui import QColor layer = qgis.utils.iface.activeLayer() ...
5
votes
1answer
61 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 ...
5
votes
1answer
93 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, Linestring,...
5
votes
1answer
615 views

How change border line to no pen with python console?

From Python console I load a shapefile with qgis.utils.iface.addVectorLayer. How I can remove border lines (change to no pen) in the active layer?
5
votes
1answer
3k views

How can I Setup Python to recognize QGIS

I want to use QGIS and work with Python out of the console, but I'm having troubles letting the system recognize the paths of some DLLs. Since I couldn't find a good answer on the web, I wonder if I ...
5
votes
1answer
385 views

Can I add entries to the layerlist context menu?

I am implementing a python based plugin for use with QGIS 1.8. Most of it's user interface is contained within a QDockWidget but there are some layer specific controls I would like to append to the ...
5
votes
1answer
1k views

How to get pixel size/cell size of raster layer?

After much searching, I've still not been able to figure out how to perform what seems like a simple function: I'd like to get the pixel size/cell size of a raster layer using PyQgis. Is there any ...
5
votes
1answer
117 views

Create a temporary intermediate layer in a processing script

My algorithm needs a temporary layer in a QGIS processing script. I can use regular pyqgis api to create a temporary layer but want to know if there is a preferred and processing-specific way of doing ...
5
votes
1answer
451 views

How to open QGIS attribute table in form view using Python?

I've got a plugin where I load some layers. After the last layer loaded, I show the attribute table. However, I would like to select the form view and not the table view (see image). How can I do ...
5
votes
2answers
972 views

Load and display a layer from SQL Server 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 ...
5
votes
1answer
820 views

Using the Processing Framework in QGIS 2.0

I am writing a plugin for QGIS 2.0, and I want to use the processing framework to call some functions. When I open the pyhton console inside QGIS, I am able to call it like this: >> import ...
5
votes
1answer
676 views

QGis Zonal Statistics Plugin NoData included in Calculations

I have been trying to use the QGIS zonal statistics plugin. My raster has a nodata value of -99999 and all other values are positive. After computing the mean zonal statistics there are a number of ...
5
votes
1answer
69 views

Sending a https request from a QGIS plugin using urllib2

I'm developing a QGIS plugin that needs to send https request to an API. I have to use urllib2 (see below if you want to know why I don't just use the requests package) The first request I need to ...
5
votes
0answers
62 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?
5
votes
1answer
152 views

Map on canvas renders after image saving

I'm a beginner to Qgis and Python; i need a script (don't need it to be a plugin) to get maps of selected features from a layer satisfying certain conditions; Here is my code: from qgis.gui import * ...
5
votes
0answers
685 views

How to stop a PyQGIS script that has an infinite loop, using the keyboard?

So i wrote a script that does what i want over and over again using a "while True:" in a certain time interval (every 5 seconds using time.sleep(5)). So far so good BUT when i want to stop it i just ...