Python bindings for QGIS.

learn more… | top users | synonyms (1)

1
vote
1answer
68 views

How to define a point by coordinates in QGIS (Plugin)

I am developing a QGIS plugin and got currently stuck at setting the geometry of a feature based on coordinates. I retrieve coordinates through an SQL query, create a feature and try to set the ...
2
votes
1answer
58 views

How to sort layers within groups with Python?

After running a longer script (Qgis Console), all I want to do is sort the layers within my groups; since some of them are buffers and the 'biggest' buffer is now on top. I've tried stuff based on: ...
0
votes
0answers
37 views

Work values of a table in QGIS!

I have a table associated to a shapefile with the number of people who live in different villages and the corresponding city. I want to define a new shapefile with points located in the centroide of ...
3
votes
1answer
53 views

QGIS standalone application for map rendering: bad extent

I made a simple standalone QGIS app for rendering a set of layers and export it as a PDF file. When i use iface.mapCanvas().mapRenderer() (inside QGIS console) for rendering, my output is OK. If i ...
1
vote
1answer
31 views

How do I get the feature id after featureAdded signal (PyQGIS)?

I'm trying to make an edit form in QGIS (Python code) ,and i want after feature drawing to get the id, and the feature to be selected. Do you have any ideas to do that? Tried so far: ...
1
vote
0answers
26 views

QgsFeatureRequest with expression on joined fields in pyqgis

I have a shape layer in a QGIS 2.8 project with fields A and B joined to a Oracle database layer with field C. I am writing a plugin to search the shape for fields A, B, and C. I am doing this with ...
0
votes
1answer
70 views

Python code to import OSM data in QGIS

I am trying to automize the workflow: import osm data and select by a special tag. I have to do this steps a lot of time with different parameters and updated data. A Solution could be a python ...
3
votes
1answer
120 views

Script to save lots of shapefiles into different CRS in QGIS

I have a lot of shapefiles that I need to save in a different CRS... is it possible to automate this process with a script in QGIS?
2
votes
1answer
76 views

Calculate area of all polygons in a shape file and save it in attribute column “Area” in a python script using QGIS

I have a shape file with about 2000 polygons. I am using QGIS and I need to write a standalone python script which opens the shape file and calculates the area of all polygons separately and outputs ...
4
votes
1answer
104 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 ...
4
votes
2answers
90 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 ...
0
votes
0answers
14 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
15 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
62 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") ...
3
votes
0answers
65 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
45 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
47 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 = ...
2
votes
0answers
44 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
47 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
69 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
53 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
69 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
63 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
69 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
110 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 ...
3
votes
1answer
119 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
59 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
50 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
40 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 ...
3
votes
2answers
83 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 = ...
2
votes
1answer
42 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
58 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
59 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
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
57 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
37 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
67 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
165 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
24 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
64 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
77 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
83 views

pyqgis: Add GeoJSON as editable Layer

following GeoJSON should be added to QGIS as an editable Layer: ...
6
votes
1answer
103 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
25 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
64 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
166 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
60 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 ...
4
votes
1answer
58 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 ...