Python bindings for QGIS.

learn more… | top users | synonyms (1)

2
votes
2answers
159 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
24 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
316 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
101 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: ...
2
votes
1answer
46 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
50 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
102 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
24 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
57 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
40 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
75 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
95 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
86 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 ...
9
votes
4answers
432 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
33 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
44 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
133 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
28 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
72 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
61 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
69 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
54 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
67 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
112 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
55 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
51 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
56 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
88 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
69 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
37 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() ...
4
votes
1answer
67 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 * ...
3
votes
1answer
49 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
135 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
47 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
167 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
50 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 : ...
2
votes
1answer
40 views

QImage Not Defined [closed]

I am trying to get a set of map images with a Python script in QGIS. I load the background raster and my csv vector file and then I try to get the image. When I start the example from the PyQGIS ...
2
votes
3answers
59 views

Keeping my own additional Python layer information for potential further usage in QGIS

I wrote a plugin that selectively loads simulation data to QGIS. That works fine, but the overhead to convert the data from my own format to QGIS takes a long time, as I have to generate an index and ...
7
votes
1answer
116 views

Filling fields with conditional clauses

I have four fields in my shapefile. I would like to fill only one of them (cell of attribute table) and automatically after to write one cell the others one will be filled by conditional clause. I ...
2
votes
1answer
59 views

OpenStreetMap heavily pixellated when loaded in QGIS and standalone application

I am loading an OSM street map into an application I am building. I load it as a raster layer via an XML document with the OSM GDAL data. My problem is that the map appears heavily mangled and ...
1
vote
2answers
49 views

Adding a csv layer in PyQGIS

I am trying to load a series of csv files as vectors in PyQGIS. I run this code to try to get the first one: uri='file://D:/Saved Stuff/gulags/1.40.csv?delimiter=;&yField=y&xField=x' layer = ...
1
vote
0answers
32 views

Struggling to install QGIS from source in RHEL 6.4 [closed]

I have installed QGIS from source in Ubuntu using the this link. In ubuntu I compiled qgis from source without any problem. but now I moved to RHEL 6.4, not able to run QGIS from source. The steps I ...
1
vote
0answers
18 views

Error when zooming to layer in PyQGIS application. On-the-fly transformation the issue?

I am trying to set the extent of my window to a layer on my canvas. This has worked smoothly until I started using Web Mercator maps instead of WGS84 maps. My features are getting their geolocation ...
2
votes
1answer
113 views

How do you loop through raster layers in a folder with PyQGIS?

I'm looking to apply a mask to a number of rasters in PyQGIS. (updated but still not working) import processing rstr = "/Users/rasterfilepath/" shp = "/Users/shapefile.shp" outputDir = ...
2
votes
1answer
74 views

Set label transparency in PyQGIS

I have been trying to figure out how to set the transparency of my labels and label buffers in PyQGIS for an application I am building. I am using the "setCustomProperty" class from the QGIS API. I ...
2
votes
1answer
38 views

PyQGIS - Style Features individually based on attribute value - custom renderer as option?

I am trying to colorize all features in all layers in my QGIS 2.8.2-Document based on a color-value, that is being determined for every Feature individually. I do have a QtGui.QColor instance for ...
3
votes
1answer
49 views

QFileDialog remains open after selection made

I have created a QGIS plugin to import a tab separated value file, using: filename = QFileDialog.getOpenFileName(self.dlg, "Select file to import ", path, '*.*') ...
1
vote
2answers
66 views

PyQGIS method to add multiple GDB files?

I can use the following to add multiple shapefiles to QGIS: import os, glob layers=[] shape_path = "C:\Users\Me\Desktop\Test\Shapefiles\\" for shape in glob.glob(shape_path + "*.shp"): layer = ...
0
votes
1answer
30 views

How can i display length according line angle?

I want to display length according to part 1 Image. but now its making like part 2. I am using below code. import shapefile from PIL import Image,ImageDraw, ImageFont from qgis.utils import iface ...