Python bindings for QGIS.

learn more… | top users | synonyms (1)

4
votes
1answer
84 views

Drawing polygon in qgs map canvas

I want to make a custom application which includes an option just like the "Select Features by Polygon" feature in the qgis. I am able to draw the polygon using following code: self.rb = ...
1
vote
1answer
39 views

PyQT: QFileDialog keeps on opening window after clicking on cancel or ok

I use to write QGis plugins, which is based on PyQT. I use to create QButtons and connect their click to a function that itself calls a QFileDialog. For example: def doOpenFile(self): fname ...
1
vote
0answers
49 views

How to change default symbol in Categorized symbol renderer (python console) or use different icons as vector layer symbols?

I have a point shapefile in QGIS 2.10 and I want to display one of its fields attributes based on its unique values (I always know that it has 4 unique values and their values so I do not care for the ...
6
votes
2answers
154 views

Skeletonize vectors in QGIS/Python

I am trying to find a tool to create a skeleton of a large vector dataset using QGIS and its bundle. It should be directly programmatically callable through Python or commandline (QGIS, GRASS, OGR ...
0
votes
0answers
38 views

Memory issue? qgis python processing does not complete

I have a simple process to make some edits to all the contour files in a directory. It runs fine on the test of 100 odd files but in a directory with about 500 it stops after about 120 files. Is ...
1
vote
1answer
31 views

store function attribute of class in QGIS plugin

I'm pretty new to python and pyqgis so the question will be pretty trivial.. I'm writing a plugin and in one script I have a class and some internal functions.. .... class ...
0
votes
1answer
36 views

Spatialite function to generate a blob from a geometry

Using QGIS Python API, I want to avoid updating geometry with an UPDATE sql command. Why? I'm using a QSqlRelationalTableModel (see model-view programming if curious) and there are built-in editing ...
2
votes
1answer
34 views

Open CSV with native QGIS Widget

I am writing a plugin that offers to open a CSV. I know the local path to the CSV but I don't know if it contains spatial data nor which name the X and Y could have. The best way I can think of, is ...
2
votes
1answer
39 views

QGsComposerLabel set text

I am building a composition with map, legend... I want to add a paragraph (text) to the composition but the text only recognize one word. What I am doing wrong? Code: text = ...
1
vote
1answer
33 views

setHeaderData not working in a QgsAttributeTableModel?

I want to display the content from a layer in a new view I have so far a code like below (you should have 2 columns at least, then, just try in the QGIS Python console replacing mylayer_id) from ...
2
votes
3answers
73 views

Running PyQGIS script in Windows

I'm not able to run the following PyQGIS script in Windows (it worked perfectly in OS X): import sys import os from qgis.core import * import qgis.utils from qgis.analysis import * app = ...
1
vote
1answer
44 views

How can a gui be visible till all the work is done? (QGIS plugin, python)

I have made a gui in QTDesigner for QGIS2.10 (as a dialog). When I press the ok button (if result == QtGui.QFileDialog.Accepted:) everything works just fine but the gui is disappeared. How can the gui ...
5
votes
1answer
89 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 ...
1
vote
0answers
40 views

Creating spatial layer from MS SQL Server table?

I have a table in MSSQL that I am trying to use to create a spatial layer from using the QgsVectorLayer function to load the table as a layer, and then using Fiona to create a shapefile but I am ...
0
votes
0answers
33 views

GDAL error in QGIS application displaying VRT files

I am working with a standalone app build with QGIS 2.8.1 on a CentOs7 machine. I got a new DTED data set which raises errors "somewhere" in the app. The app doesn't read the .dt? files directly, but ...
4
votes
1answer
98 views

Converting Python script for QGIS?

I am still a novice in python, but I have the long term goal to create a plugin one day. The first step to this plugin is a test with QGIS python scripts to convert an Access mdb into sqlite db and ...
1
vote
2answers
78 views

QGIS 2.10 Unable to add features to a memory layer

I'm trying to add features to a memory layer. This is the layer creation : memlayer=QgsVectorLayer("{zr_typegeom}?crs=epsg:4326".format(zr_typegeom = typegeom), "memlayer", "memory") ...
1
vote
0answers
32 views

qgis modeler - use input filename in output filename

I need to use the input filename in the output filename in a qgis model. I have spent a couple of hours trying to find a solution but can't. If the input is contourXY.tab and I want output to be ...
1
vote
1answer
88 views

Change attributes values?

i want to change attributes values in a memory layer. I already asked a similar question but i'm re-stuck on the problem and don't find any solution to this basic need. Here is what i'm doing so far ...
1
vote
1answer
71 views

Pretty table python module with variable number of rows [closed]

Is there a way to produce a table in a txt file using pretty table python module, using an i variable for the row count for the case I do not know the number of rows from the begining? For example I ...
0
votes
0answers
19 views

How to Query the WFS layer with points(coordinates from mouse click) to get the xml data in QGIS using python

I am using the following syntax to load the WFS layer: uri = "link to download the WFS layer" layer = QgsVectorLayer(uri, "WFS_Layer", "WFS") QgsMapLayerRegistry.instance().addMapLayer(layer) But i ...
0
votes
0answers
42 views

QGIS 2.8/.10/…crashes when I run, into PyQGis Console, a script within “exit command” of any GUI designed with the same pyQgis script code…Why?

I use QGis 2.8 or 2.10. I open Console PyQGis, so I can write Python specific code that I can design any GUI, as a simple Window Form. After I wrote this code I run this script created and it's ok ...
1
vote
1answer
46 views

Applying single-band color map from file using pyQGIS?

I am importing a number of rasters using the python console in QGIS 2.8. I would like to color them all using the same color map, which I have saved to a file. I would like to do this using python so ...
1
vote
2answers
91 views

Python script for select by attribute function for QGIS

The following is of course working, selects these features of my_layer that have attribute 1 for my_field2 and appends the corresponding attributes of my_field1 in my_list: my_layer = ...
1
vote
1answer
91 views

How to run Refactor Fields algorithm in Python console?

I noticed that the Processing algorithm, Refactor Fields has a fields mapping parameter. I don't think I've come across this and definitely not used it before from the Python Console. It provides an ...
2
votes
2answers
46 views

Pyqgis load QML style from plugin

I need to apply a .qml style to a layer on my map as part of a Python plugin. I gather that this can be done via QgsMapLayer.loadNamedStyle(). The problem I have is that my .qml file is stored within ...
1
vote
0answers
42 views

Check for whole number in case statement

In an elevation file I want to find all the 5m contours and mark a column up as major. This has to be done in QGIS in the field calculator or modeler. I want to do something like the following based ...
1
vote
1answer
66 views

Use table manager in modeler in qgis

I need to reorder the fields in a tab file from within QGIS modeler. Table Manager plugin allows this but I can't seem to find a way to do this in modeler. It needs to be run on thousands of files. ...
2
votes
1answer
56 views

Adding multiple plugins to custom menu in QGIS

I am new to Python and QGIS and attempting to create some plugins to replicate in-house tools used in other GIS programs. I have added a custom menu using Python and added the plugin to the menu using ...
3
votes
1answer
66 views

How to merge layers into a single QgsVectorLayer?

I have a set of different layers (and their respective shapefiles) with information of electric lines. All the layers have the same Fields in their Attribute Tables, but contain information about ...
3
votes
2answers
58 views

Joining points to nearest line using pyQGIS?

I followed this suggestion to join points to nearest lines in QGIS. While most points get attached there are instances of points, often in close proximity to a line, that do not get connected (see ...
1
vote
0answers
69 views

python script in QGis - help using gdal.Polygonize

I want to create a very simple script in python that polygonizes a raster. Based on python cookbook + forums search I wrote the following code #import des modules from osgeo import gdal, ogr from ...
1
vote
1answer
25 views

Get values from metatada.txt

Is there a built in function in PyQGIS to import the values from a plugin's metadata.txt? I am developing a plugin and want to show the version corresponding to the value from metadata.txt. Is there ...
2
votes
1answer
55 views

Using processing.runalg in python script

I'm trying to run the following python script: from qgis.core import * import sys import os import qgis.utils from qgis.analysis import * app = QgsApplication([],True,"") # supply path to where is ...
3
votes
0answers
47 views

PyQgis: Print Composer using input from several Spatialite-tables

How can I create PDFs out of QGIS using the Print Composer Templates that include a lot of text (from a text-template) and within the text several information comes out of my spatiallite-database. A ...
6
votes
0answers
58 views

QGIS: large .vrt indexing

I have a large number of small tiles merged into a single VRT. The rasters are only viewed at large scale, so only a few of them are visible at the same time. The map refresh in qgis is slowing down ...
1
vote
0answers
43 views

Getting started with PyQGIS [duplicate]

I'm trying to write a standalone python script to run some things I've already been able to run in the Python console. However, I'm having trouble running even the most simple application. I tried ...
3
votes
1answer
34 views

Initialising QgsFeature with predefined field names using PyQGIS?

I need to create function that assembles QgsFeature from scratch: takes id, dictionary of attributes, and geometry as input. The issue is that feature that is being created doesn't belong to any layer ...
1
vote
0answers
26 views

WMS layer throws “IReadBlock failed at X offset 0, Y offset 1” error. Possible XML issues

I am working with a few WMS layers to try and see which one would work best with an application I'm developing out of QGIS 2.8. I need the CRS to be in EPSG 4326 but, as many of you know, most webmaps ...
1
vote
0answers
20 views

Should I set the projection if the data has already been projected?

I need to plot some data which was produced on a native grid with a lambert conformal conic projection. I need to create a geotiff (using python and gdal) and was wondering how to go about and do ...
1
vote
0answers
76 views

how to set the geotransform using GDAL in python

I am trying to create an image from a numpy array and georefenrece it so that I can import it into qgis. I have the latitude and longitude in degrees for the top left corner of the array as well as ...
4
votes
1answer
197 views

Calculate line lengths with Python in QGIS

I found this article which describes the "QGIS GUI way" for calculating the line lengths. http://www.qgistutorials.com/en/docs/calculating_line_lengths.html How can I calculate the length of one line ...
2
votes
2answers
156 views

Running PyQGIS script directly (without using interface)?

I wrote the following script, which runs fine from the QGIS python console (it loads two shapefiles, intersects them, and then finds the areas of the new regions): import qgis.utils import qgis.core ...
0
votes
0answers
34 views

How to create raster with origin in degrees and dx dy in metres

I need to create a raster from array. In gdal if i understand correctly i need to specify the top left lat lon for the SetGeoTransform((originX, pixelWidth, 0, originY, 0, pixelHeight)) however the ...
1
vote
0answers
23 views

Projected Coordinate System issue using GDAL and qgis when defining x and y

I have a numpy array which I would like to save as GeoTiff using GDAL in python. The array was created using the following PCS in mind: +proj=lcc +lat_1=48 +lat_2=48 +lat_0=48 +lon_0=0 +x_0=0 ...
8
votes
3answers
310 views

Performing a Spatial Query in a loop in PyQGIS

What I am trying to do: loop through a point shapefile and select each point that falls into a polygon. The following code is inspired by a spatial query example I found in a book: mitte_path = ...
5
votes
1answer
95 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: ...
2
votes
1answer
45 views

Add area column using PyQGIS

I'm trying to compute the areas of the new layer I created by intersecting two layers. How can I write a script that does something equivalent to clicking Export/Add geometry columns? Thanks!
2
votes
1answer
48 views

pyqgis standalone script fails to execute clip algorithm

A previous question has established how to invoke QGIS's clip algorithm at the python console. I have done so and demonstrated that the method works satisfactorily on my data. I would instead like to ...
7
votes
1answer
101 views

Assign shortcut to a script?

Is it possible to assign a keyboard shortcut to a (custom or not...) script of the Processing Toolbox in QGIS? Haven't found any information about it...