Python bindings for QGIS.

learn more… | top users | synonyms (1)

0
votes
0answers
16 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
20 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. ...
2
votes
0answers
73 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") QgsMapLayerRegistry.instance()....
3
votes
0answers
83 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 ...
3
votes
0answers
52 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
53 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/" ...
2
votes
1answer
36 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 = np.array(src_ds....
2
votes
0answers
63 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
51 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) legend....
2
votes
1answer
99 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 ...
1
vote
0answers
60 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 ...
3
votes
1answer
87 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 ...
1
vote
1answer
73 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 (...
4
votes
2answers
74 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 ...
2
votes
1answer
112 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 ...
4
votes
1answer
159 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 ...
2
votes
1answer
64 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
67 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
47 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 layer.loadSldStyle("...
3
votes
2answers
84 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 = myLayer.getFeatures(...
2
votes
1answer
49 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 ...
2
votes
1answer
63 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 if-...
2
votes
1answer
63 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 ...
1
vote
0answers
36 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
69 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 ...
1
vote
1answer
41 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 ...
2
votes
1answer
40 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 ...
3
votes
0answers
74 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
209 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
0answers
28 views

how to generate a raster with its spatial reference from an array(or matrix) by using pyqgis

I used arcgis to generate rasters from txt files by a certain python api,but i am not familiar with qgis,and now i need generate some rasters from txt files by using pyqgis.The resulting rasters ...
1
vote
1answer
78 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 ...
4
votes
1answer
105 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?
1
vote
1answer
110 views

pyqgis: Add GeoJSON as editable Layer

following GeoJSON should be added to QGIS as an editable Layer: {"type":"MultiPolygon","coordinates":[[[[540776.621887207,5912792.64251709],[540773.4404907227,5912798.570678711],[540774.3524780273,...
7
votes
1answer
122 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? ...
1
vote
0answers
26 views

python handling case in address (lowercase,uppercase) [closed]

I'm working on a python QGIS plugin that takes address info from specific parcels and lists it. The data is in various cases and I'm having a hard time figuring out how to handle it. My data looks ...
1
vote
0answers
91 views

QPyNullVariant not recognized outside of QGIS

So here is a weird one. I'm getting an error about an operation involving a QPyNullVariant: TypeError: unsupported operand type(s) for *: 'QPyNullVariant' and 'float' So I wanted to put a check ...
3
votes
1answer
244 views

PyQGIS couldn't import processing with standalone script

I have read post on that problem (How can I access `processing` with Python?). The problem is even with a sys.path.append it couldn't import processing. It's very frustrated. Here the code I used: #!/...
2
votes
1answer
87 views

PyQGIS: Change attribute value doesn't work, results in NULL

I am writing a QGIS plugin, which at one point attempts to change several attribute values on a layer. However, in the end no changes are made. If I punch similar code into the built-in Python Console,...
4
votes
1answer
72 views

Merging Features

I want to merge features of a vector layer into one single feature using the python console. Somewhere I found the following solution. However it does not seem to work for me. When I execute the ...
3
votes
1answer
120 views

Qgis Python: Find bounding box for multiple features?

I want to find the bounding box of several features selected by their attributes. Here's what I've been trying: tNumList = [8,9,10,11] selectGeom = QgsGeometry() for tNum in tNumList: request = ...
3
votes
1answer
71 views

Showing QgsAddAttrDialog in a Python plugin

I want to invoke the builtin add field dialog from my python plugin in QGIS: This is the add attribute dialog of the attribute table. It is located HERE. I expect it to return a QgsField. ...
3
votes
1answer
149 views

Get results from using GRASS algorithms with the QGIS processing tool

I am trying to write a plugin in QGIS that uses at some point a GRASS algorithm : "v.split.length", accessible by using the processing class, and here is how I am using it : processing.runalg("grass:...
10
votes
0answers
297 views

PyQGIS save raster as rendered image, then use GDAL tools on it

I have tried to use the code from QGis Save Raster as Rendered Image. i is a raster layer: pipelayer = i pipeextent = pipelayer.extent() pipewidth, pipeheight = (pipelayer.width(), ...
5
votes
1answer
78 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....
3
votes
0answers
133 views

Can qgis_core work with external python distribution (such as Anaconda)

I've built a python application that has its own GUI. I am trying to use qgis.core/pyQgis as map display only. Specifically, i have anaconda 2.3 and its python distribution (2.7.11). After research on ...
3
votes
1answer
131 views

Standalone python app that uses qgis.core without installing qgis

I am building a standalone python application that has its own GUI, i would like to use qgis.core/pyqgis as a map display only. But from my searches on this topic, it seems that the full QGis software ...
0
votes
0answers
35 views

How to run a function in a while loop while an QObject is activated/triggered in PyQgis

Firstly I am new to PyQgis and there might me a lot of basic errors. The aim is that everytime a new vector object is drawn its attribute should automatically update while a QAction I have created ...
2
votes
2answers
166 views

How to define outline color from polygon layer using Python?

I´m using a QGIS 2.8.3 and I want to define a style for the legend of my polygon layer. I was using this code that works perfect: str1= 'C:/Documents/Layer.shp' myVectorLayer = QgsVectorLayer(str1, '...
3
votes
2answers
167 views

How to Check if a Layer is PRESENT or ABSENT in a Project via PyQGIS?

In QGIS, what is the simplest python code (least possible) to verify if a particular layer is PRESENT or ABSENT in the Map Layers list? NOTE: The script shouldn't trip an error IF the layer is ABSENT....
1
vote
0answers
51 views

Try/Except Statement gives different Results in QGIS Console vs. QGIS Tool

I want my script to do different things depending on whether a particular layer DOES or DOES NOT exist in the Map Layers list. I thought the try: / except: statements would be the best way to achieve ...