Python bindings for QGIS.

learn more… | top users | synonyms (1)

1
vote
1answer
29 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
94 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
58 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
0answers
73 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
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
38 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
45 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
21 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
126 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
320 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
207 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
36 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
28 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
398 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
170 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
63 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
77 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
129 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
29 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
63 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
51 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
117 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
170 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 ...
1
vote
1answer
154 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
68 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
50 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
105 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
520 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
46 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
48 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
199 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 ...
0
votes
0answers
33 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 = ...
2
votes
2answers
115 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
82 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
98 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
64 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
107 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 ...
2
votes
1answer
153 views

Export a QGIS print composer file (.qpt) as PDF from the command line

I have a workflow where my R script produces csv's and shapefiles. Those csv's and shapefiles then serve as layers in a QGIS project. Every time the R script is run, it overwrites the previous data, ...
1
vote
0answers
75 views

How to use QGIS ComboManager inside my plugin?

Could someone provide some detailed instructions (for very new beginners!!) on how to integrate combomanager in another plugin? What I have tried (maybe wrong way of doing it!!...): First I ...
1
vote
1answer
62 views

How to get a list of all objects contained in my different QGis layers

I would like to know how we could do in QGis to get a list of object contained in my different opened layers: We have n .SHP files or PostgreSQL Views (they all contain at least an "object type" ...
3
votes
0answers
66 views

How are costs returned by the pyQGIS implementation of Dijkstra calculated?

How are the costs returned by pyQGIS implementation of Dijkstra (QgsGraphAnalyzer.dijkstra) calculated? As far as I know, these costs correspond to the distance from the starting node to each of the ...
2
votes
1answer
143 views

How to get the extent of a group of Raster layers and zoom to it with PyQGIS?

I want to find a way to zoom to a group within the QgsLayerTreeView. The group only contains QgsRasterLayer. The indirect approach would be to create a QgsRectangle and serve it to the ...
1
vote
0answers
110 views

How to import netcdf in qgis

I have been trying to impot netcdf files following this guide online http://www.ggiuliani.ch/download/netcdf_qgis_GG.pdf into qgis 2.10 with no success. ALthough the file is imported, the dimensions ...
1
vote
2answers
45 views

Hide unselected features with pyqgis

In the context of QGIS/PyQGIS, I would like to hide the unselected features after performing, for example, a simple selection. feature = layer.getFeatures().next() ...
5
votes
1answer
102 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 * ...
4
votes
1answer
76 views

Remove layers in memory QGIS python

I have a plugin with my own map canvas and I create a button in order to remove all the layers visible or opened in map canvas. I use this lines: QgsMapLayerRegistry.instance().removeAllMapLayers() ...
4
votes
2answers
167 views

How to build QgsExpressions in python?

How can I build a feature request expression using variable inside expression? For example values = [1, 2, 3] for j in range( y ): it = vl.getFeatures( QgsFeatureRequest().setFilterExpression ( ...
3
votes
1answer
59 views

Setting QgsExpression for QgsPalLayerSettings in QGIS

How do you apply a QgsExpression to a Label ? I can do it in QGIS with this simple expression concat('N:' ,round(Value,0),'\n','Yield:' ,round(Value 2,0)) N: 65 Yield: 40 How do I do it in ...
2
votes
2answers
181 views

Set predefined scales in PyQGIS for standalone application

I am trying to figure out how to set the zoom scales to match those meant for OpenStreetMaps and Google Maps, etc., as I am using OSM for a basemap. I've looked all over the internet and can't seem to ...
2
votes
0answers
56 views

Getting number of rendered features per range with PyQGIS?

I would like to know how many features are rendered in my QgsGraduatedSymbolRendererV2 per range. I need to know also the exact range (lower and upper value). I know how to get each range : ...