Python bindings for QGIS.

learn more… | top users | synonyms (1)

1
vote
1answer
172 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
40 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
89 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
107 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
145 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 = iface....
1
vote
1answer
378 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
110 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
48 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 ...
2
votes
1answer
94 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
134 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
127 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
93 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
173 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 ...
2
votes
1answer
37 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
219 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
65 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 ...
7
votes
1answer
97 views

How to index large VRT files in QGIS?

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
44 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
41 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
81 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
25 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
201 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
441 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
284 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
39 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
39 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
547 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 = r"D:\...
5
votes
1answer
273 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: ...
3
votes
1answer
115 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!
3
votes
1answer
105 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
155 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...
1
vote
0answers
40 views

Pass information in external command line software from a python plugin file

it would be quite difficult to explain, I'll do my best.. I'm writing a plugin for QGIS (with the plugin builder, so the folder structure is straightforward). This plugin calls other software (that ...
1
vote
2answers
73 views

Why does openFeatureForm crash QGIS?

I'm working on a Qgis plugin with python, I'm creating a feature and I show a feature form to edit the attributes. But after the openFeatureForm function call the program crash and close line = ...
1
vote
0answers
60 views

If field is empty in attribute table, programatically populate subsequent field with that data [closed]

I have a CSV communicating directly with a series of points and lines. The CSV is a bit problematic, however. The hardware that provides the data only provides location data every few rows. That is, ...
2
votes
2answers
158 views

Is there a call in pyqgis that clips a layer similarly to the Geoprocessing Tool?

I've loaded two shape files using pyqgis like so: data_layer = QgsVectorLayer("lines.shp", "highways", "ogr") clip_layer = QgsVectorLayer("polygon.shp", "highways", "ogr") As the names of the ...
2
votes
0answers
227 views

Combining custom QWidgets with ui file generated from QGIS plugin builder?

I am having a hard time figuring out how I can include several QWidgets (created in individual scripts) into the QT Designer ui file generated from a QGIS plugin builder. These are custom widgets I ...
2
votes
1answer
326 views

Pyqgis: “a.geometry().intersects(b.geometry())” wouldn't find any intersections but should. Why?

I am teaching myself pyqgis and try to find those polygons in one layer that intersect with polygons in another layer. It seems very trivial, and on GIS.SE are several similar questions that are ...
2
votes
1answer
89 views

Setting Instance of MULTIPLE LAYERS using “mapLayersByName” in QGIS Python Scripting?

I'm currently using "mapLayersByName" successfully to set one active layer at a time as follows... vl = QgsMapLayerRegistry.instance().mapLayersByName('My_Layer')[0] iface.setActiveLayer(vl) Can ...
0
votes
1answer
55 views

Copying Multiple Selections (by Attribute) to One Output Shapefile using QGIS Python scripting?

INTRODUCTION The code below makes a selection and then saves to an 'Output' file (shapefile?) each time through the "FINAL ITERATION LOOP". Each 'Output' file will contain all selected civic address ...
5
votes
1answer
124 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 ...
9
votes
4answers
584 views

How to reproject 500 CSV files efficiently and easily using QGIS?

I know, my question is similar to some old ones on this site. I've a lot of CSV files (geo coordinates) to import to qgis (and then to convert them), and the usual way is not the best way to do it (...
1
vote
1answer
79 views

Qgis: QgsLogMessage.logMessage to output message in a specific tab

I am writing a Qgis plugin. I would like the plugin to write log message in a specific tab, in the Log Messages window. I tried: QgsMessageLog.logMessage("File "+ii.source()+": all pixels set to no ...
3
votes
1answer
54 views

GDAL VRT files get corrupted by reading

In my stand-alone QGIS app I am using vrt files of DTED rasters. All vrt files are build with the same Python code and have the same structure, codepage etc. I use them for display only. <...
4
votes
2answers
272 views

Iterate an intersect between polylines and polygons in QGIS using Python script

I have a shapefile made up of 127 separate polygons that represent different districts. Overlaid on this layer is a polyline layer of 2800 streets, some which are completely bound by the polygons and ...
1
vote
0answers
47 views

Add Field to PostGIS Layer in pyqgis

I'm having trouble adding a field to a PostGIS table using pyqgis. Here's my code: from PyQt4.QtCore import QVariant from qgis.core import * inLayer = iface.activeLayer() provider = inLayer....
2
votes
2answers
140 views

Seg Faults and Instantiation Errors while running PyQGIS on OS X

I'm having issues getting off the ground with running PyQGIS on my OS X. I'm frankly very confused as some errors occur sporadically while executing the same code. When I try the following: ...
3
votes
2answers
123 views

Print values from Tables in QGIS Console

I want to know how to get the QGIS Console to print out actual values pertaining to a Layer's attribute table (e.g. field names, feature values, etc.). So far using the "print" command all I'm able ...
1
vote
1answer
184 views

How to change the active layer in QGIS Console?

I want my script to perform actions on a particular layer. Online advice I've found so far suggests using the iface method "setActiveLayer()". Makes sense based on the name alone. Scenario: In ...
3
votes
1answer
73 views

Finding Points in Polygons with Matching ID's?

I'm fairly new to using PyQgis, so sorry if this question is basic. I'm working with two vector layers: (layer 1) A series of polygons, each with an ID field specifying what geographic district the ...
2
votes
2answers
154 views

How to add temporary PostGIS table to canvas?

I'm working with PostGIS database. I would like to create temporary table with geometry and add it as a layer to QGIS. There is no problem with regular tables, but I can't figure out how to add ...