Python bindings for QGIS.

learn more… | top users | synonyms (1)

4
votes
2answers
31 views

Retrieve available PostGIS connections in PyQGIS

Can I retrieve the available connections to PostGIS databases in PyQGIS? I would like to provide a list of available db-connections, and subsequently a list of tables within the ui of my plugin. I ...
3
votes
1answer
49 views

Problem Editing a Vector Layer QGIS

I have a vector layer which I need to load and edit (add several attribute columns). I am doing this without opening QGIS, so within a python script. I have the following piece of code for the layer ...
2
votes
2answers
24 views

PyGIS remove QgisVertexMarker from scene

I am writing a plugin that includes interaction with the map. Therefore I use a QgsMapTool. It is possible for a user to mark a point on the map. When the user clicks a red X is drawn on the mapCanvas ...
2
votes
0answers
45 views

Create a layer, edit and save. Where are my features?

I created a layer (e.g. point) in QGIS with QgsVectorLayer from memory: mem_layer = QgsVectorLayer("point?crs=epsg:32630&field=id:string","TempFile","memory") ...
2
votes
1answer
34 views

Extracting zeros from numpy array and creating a new raster

The following code reads in several .tif files from an input folder, converts them to numpy arrays and adds them together. All input files are binary: inputFolder = "/home/usr/Desktop/BufferFolder/" ...
0
votes
0answers
10 views

Id allocation of QgsFeature objects

I noticed a strange behavior when creating a new QgsFeature object and adding it to a layer, inside a QGIS plugin. Let me first briefly explain the structure of my plugin: I have a main function that ...
2
votes
0answers
8 views

PyQgis - How to update a spatial index?

I am trying to speed up a QGIS plugin I wrote by adding a spatial index to a vector layer. The aim of my plugin is to simplify a line network by merging some of its features, based on some criteria. ...
3
votes
0answers
35 views

How to create a shapefile having Voronoi diagrams from the shapefile of an existing region?

I have a shape file of a region and I want to generate random sub regions of that shape file using Voronoi class of scipy.spatial package of python. But I am a newbie to GIS. I found out about Voronoi ...
1
vote
1answer
49 views

How to add diagrams to a layer in a PyQGIS standalone application?

In my standalone application, I show different layers based on queries into a canvas. Now I want to add a layer with charts over by the values of an attribute. Is it possible in a standalone ...
3
votes
0answers
33 views

QgsSpatialIndex partial or complete overlap

I'm working on adding some functonality to a QGIS plugin. It currently uses a QgsSpatialIndex to efficiently compute whether the features of a vector layer intersect (potentially millions) of ...
2
votes
1answer
29 views

Importing Several Raster Layers, Doing Manipulations and Exporting The Newly Saved Rasters

I have the following code: src_ds = gdal.Open("/home/usr/Desktop/RasterFolder/Name.tif") if src_ds is None: print 'Unable to open %s' % src_filename sys.exit(1) myarray = ...
1
vote
0answers
10 views

module object has no attribute classFactory

I asked this question several days ago on the QGIS developer list but didn't get any love. I'm hoping someone can help me resolve this error. I have a custom repo and a custom plugin that I'm ...
4
votes
1answer
39 views

How to toggle group visibility in QGIS using Python?

I've tried this, but it doesn't work out. root = QgsProject.instance().layerTreeRoot() group1 = root.insertGroup(0, "PGB") legend = i.legendInterface() legend.isGroupVisible(group1) ...
2
votes
1answer
42 views

QGIS - PYQGIS Import gpx as vector layer

I'm trying to use the python console to import some gpx files as vector layers. When I do it manually I have to choose which layers to add, my options are: I've tried various versions of the code ...
2
votes
1answer
282 views

How to programmatically set a rule-based renderer in QGIS?

These days im in a process of developing a plugin , which highlights/change color of set of features in a vector layer depending on some calculation. i found nice article about QGIS – Rule based ...
1
vote
1answer
277 views

How to calculate zonal statistics from multi-band raster for each polygon using python?

I want to calculate the zonal statastics from multi band raster for a polygon layer. When I am using this snippet of code: vectorlayer=qgis.utils.iface.mapCanvas().layer(0) rasterfile = ...
3
votes
1answer
42 views

azimuth and distance from various functions in qgis

I am comparing the various ways of calculating distance and azimuth between two points with Qgis. I am struggling with the various results and their interpretation. I need to calculate a loxodromic ...
3
votes
1answer
86 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 ...
3
votes
2answers
71 views

Trying to use LIKE in an expression in pyQgis

I want to select elements from a layer. The field I use is a string/character field. My code is as follows: expr = QgsExpression(ur'"myField" = \'valueILookFor\'') it = ...
1
vote
0answers
41 views

Cannot import name QtTest running unittests for QGIS plugin

I have the following imports in my unittest code: from PyQt4.QtCore import * from PyQt4.QtGui import * from PyQt4 import QtCore, QtGui, QtTest When I run my unit test from the command line I get ...
1
vote
1answer
38 views

QGIS Zonal Stats Plugin - Python Console - compute one specific statistic

I think this is more of a syntax problem that I have here. But I am absolutely not able to figure it out. On a different Linux machine I got the following working: zoneStat = QgsZonalStatistics ...
3
votes
1answer
59 views

Layout show label and each polygon make serrated image

I want to develop "Print lay out functionality", but in output system is giving me whole image, I want to print only selected polygon. Also it is not displaying label names on print image. Please ...
1
vote
0answers
35 views

Label layout on python in QGIS

Now the only issue is that in image I am not getting the labels, I have on polygon. Please help in that too Please see above attached screenshots here I need labels – I have updated QGIS it's version ...
3
votes
1answer
295 views

Import error when utilizing QGIS's Python Init function

Based on the answer to Referencing Qt UIs external to plugin with python. I'm trying to utilize the "Layer Properties / Fields / Python Init function" to execute a file (test_file.py) that is located ...
4
votes
2answers
54 views

performance problem with PyQGIS: manipulating attributes

I have selected a vector layer with attributes slope and area. I want to combine all the features with slope 0 to 5, 5 to 10, ... , 85 to 90. The original features are to be discarded, and new ...
5
votes
3answers
632 views

How to define layer's CRS and avoid the CRS dialog in PyQGIS?

There is an existing Shapefile, which I want to add. At the moment my code looks like: self.iface.addVectorLayer(self.shpFilePath, "Track", "ogr") It works fine, but i want to define the crs ...
2
votes
2answers
182 views

Writing PyQGIS Output to Shapefile

I'm trying to find the closest point on a line to another point as in this post. However when I try to write the result as a shapefile I get an error: TypeError: ...
2
votes
1answer
52 views

How to display different layers with different CRS in one canvas in a standalone application?

I am a freshman of the pyqgis. Now I load the raster and vector data in the standalone application. The two data are same area, but in my canvas, they are at different places. I want to know how to ...
2
votes
1answer
31 views

iface.addVectorLayer on a gml file causes “Select vector layers to add” dialog (pyqgis)

I am trying to load a directory full of zipped GML files (*.gz) into QGIS using pyqgis' iface.addVectorLayer(), but as the GML file contains multiple separate vector layers (Area, Text, Symbol, Point ...
2
votes
1answer
98 views

Huge file size after averaging two rasters

After I average two raster files (singleband gray, initial size ~700MB each) through QgsRasterCalculator() with formula "Raster1@1/2 + Raster2@1/2" the size of the resulting file is 2.9GB. Is there ...
2
votes
1answer
40 views

Working Windows Standalone .EXE From QGIS Python Script Using PyInstaller?

Has anyone been able to create a working standalone Windows .EXE file from a QGIS Python Script Using PyInstaller?
2
votes
1answer
48 views

How to create azimuth raster layer by pyqgis?

I want to create an azimuth raster layer base of single point shapefile, for this I write below code that create a memory point layer that each point in memory layer is center of each pixel and have a ...
5
votes
2answers
294 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. ...
2
votes
1answer
43 views

Why is QgsFeatureIterator returning bad data?

This is a spin-off of another question I asked previously, but it has grown in scope and deserves its own thread. While iterating over a vector layer (shapefile) I included the following ...
2
votes
1answer
26 views

How to use a SLD file from the QGIS console?

How to apply a SLD file to a layer in QGIS from the QGIS console? I tried this but it didn't work: # selecting the layer layer = iface.activeLayer() # Apply SLD on the layer ...
2
votes
1answer
29 views

pyqgis - Editing a feature - Is it possible to set a listener?

is it possible to set a listener that is fired when a feature is edited? What I imagine is this: A geometry is edited (e.g. cut operation) then a listener is fired. This event gives me back the ...
1
vote
0answers
31 views

How to iterate through attribute visibility with PyQGIS?

I have a point shapefile with a timestamp that I would like to turn off and turn back on 1 by 1 with a new element of the attribute table appearing every second
2
votes
1answer
45 views

IPython plugin not loading in QGIS 2.12

I am trying to run the IPython console plugin in QGIS 2.12 After installing the plugin there is this error: You need to install IPython 3.1.0 (and then restart QGIS) before running this ...
6
votes
1answer
75 views

Calling PyQGIS functions from external editors (Linux)

Is it possible to integrate external Python editors (such as KDevelop) with QGIS, so that it would be possible to run functions in qgis.core, qgis.utils etc. outside of the QGIS Python Console? ...
4
votes
2answers
4k views

How to perform SQL queries and get results from QGIS python console?

I'm writing a python script using QGIS API. I have to get results from postgres database table. The table has geometry field and other non-geometry fields. I want to perform SQL queries on ...
3
votes
1answer
351 views

QGIS' Join Attributes by Location not working from Python script

I have a shapefile with points, and a shapefile with polygons. I want to sum the attribute value of all points that are within a certain polygon, and I'd like to do this for each polygon in my ...
1
vote
1answer
31 views

rendering a single band raster - new maxvalue

I have a downloaded raster file, singlebandgray, and want to redefine it's maximum value to a higher integer value. Via the QGIS desktop it works smoothly by hand via the Properties. Via Python I was ...
30
votes
4answers
553 views

Generating equal sized polygons along line with PyQGIS?

I would like to create polygons along a line to use them for AtlasCreator in a next step. ArcMap has a tool called Strip Map Index Features. With this tool I can choose the height and width of my ...
2
votes
2answers
100 views

In QGIS plugin, How do I determine when layer visibility is turned ON or OFF (changed)

I need to update a vector layer's data when the visibility is turned back on. My update does not occur when the visibility is off. To what signal do I need to connect to catch the visibility change? ...
2
votes
1answer
39 views

Actions undertaken in QGIS somewhere stored as Python code in a history file?

For practioners that are not willing to study all the methods for each class, it would be helpful if every action that was made within the QGIS interface can be looked up afterwards in a history file ...
2
votes
3answers
385 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 ...
3
votes
0answers
56 views

Python script to automate saving satellite images for different combinations of lat longs

PS. : This is my first try at a GIS application. Please forgive if my question is pedantic. I would like to get a series of satellite images all at the same scale centered around different points on ...
5
votes
2answers
106 views

Field Editor with Python: select by attribute & open table (QGIS)

I want to search on number values (>, = etc.) within a column and open table for the selected ones. It's an easy task within field calculator, but I want to see how it's build up with the python ...
1
vote
1answer
55 views

How to set conditional imports for a PyQGis script running inner or outer of QGIS?

Related to Cannot run standalone QGIS script I try to detect if my script is run from a QGIS instance (through the plugin) or from a standard python console. This detection will enable conditional ...
-2
votes
0answers
28 views

Generate equal sized polygons along a line with PyQGIS [duplicate]

One month ago I asked a question about how to generate equal sized polygons along a line in QGIS, which seems to be also interesting to a bunch of people aside from me (20 upvotes and more than 400 ...