Python bindings for QGIS.

learn more… | top users | synonyms

3
votes
2answers
305 views

Load and display a layer using PYQGIS

I'm having a go at using pyqgis from within the QGIS python console to load a layer from SQL Server and display it. I feel like I'm part way there but I'm having a real issue getting the layer to ...
1
vote
1answer
111 views

How to call a method by BOTH a button AND a key shortcut

I have been trying to call a method by BOTH a key shortcut (as described here http://www.qgis.org/en/docs/pyqgis_developer_cookbook/snippets.html) and a button I created on the toolbar. The button ...
0
votes
0answers
28 views

What's the conversion coefficient between millimeters and QSize units in Qgis?

What is the conversion coefficient between millimeters and QSize units in Qgis ? What i have in mind is to set the paper size (via setPaperSize()), knowing the size of the composed image. That is why ...
0
votes
1answer
37 views

how to compile qgis-1.8.0 on ubuntu

i have downloaded qgis-1.8.0.tar.bz2 and I want to install it on my linux computer(12.04 LTS). How can I perform it please? I do it because I am desperate with Qgis 2.0.1 Dufour on ubuntu 12.04, ...
0
votes
1answer
70 views

How to change the default gray color of the QgsComposition background?

I'm building a map, with elements like QgsComposerMap of course, but also QgsComposerLabel, QgsComposerLegend ,etc... Each of these elements has a boolean "setBackgroundEnabled" property, to make them ...
0
votes
4answers
133 views

Why QgsMapCanvas only appear after lost focus?

I created the simple frame .UI file, compiled with pyuic4, and tried the ShapeViewer.py to load the shapefile "world_borders.shp". However, the map doesn't display at the first time. I have to click ...
0
votes
0answers
24 views

random point through raster

I've some issue in some task pls help if you can as I've not good python skills. I've a raster with values from 5 to 97 and I want a python script which can scan the raster and generate random points ...
0
votes
0answers
87 views

Add memory layer to a preexisting PostGIS table

I'm trying to append a memory layer to a preexisting PostGIS table. The DB connection is already established (in this way: How to properly establish a PostgreSQL connection using QgsCredentials) and, ...
2
votes
0answers
112 views

How to fetch openlayers layers from pyqgis? [duplicate]

My objective is to fetch maps provided by openLayers, as in openLayers_plugin, from a stand alone python script. I would like to get it superposed to my shp file. As can be read on ...
0
votes
0answers
47 views

How to get the signal when the color changes in pyQGIS?

I would like to have the signal when the color of a vector layer is changed by the user. In the doc, there is a signal that seems to fit ...
2
votes
1answer
181 views

How to write a new layer to PostgreSQL from QGIS plugin

The PyQGIS cookbook states that QgsVectorFileWriter can write vector layers to any format supported by OGR: https://www.qgis.org/en/docs/pyqgis_developer_cookbook/vector.html#writing-vector-layers ...
0
votes
0answers
43 views

How to add field to postgres layer with PyQgis?

I'm fetching a posgtres layer with PyQgis and then I'm trying to add field with this: lyr.startEditing() lyr.addAttribute(QgsField("class", QVariant.Int)) But It is not adding the field and also ...
0
votes
0answers
44 views

Add feature to csv via PyQGIS

I'm using PyQgis 2.0.1. Is it possible to add feature to csv file? I've tried to do this as it's shown in CoockBook: if caps & QgsVectorDataProvider.AddFeatures: feat = QgsFeature() ...
0
votes
2answers
82 views

How to programmatically fill a datetime field with datetime.datetime.now() function

I have been trying to programmatically fill a datetime field using values coming from datetime.datetime.now() function. #I create the temp shp using a URI URI = ...
1
vote
0answers
78 views

How to apply categorized symbols to polygon layer with PyQgis?

I'm fetching a polygon layer from postgres like this: uri = QgsDataSourceURI() uri.setConnection("localhost", "5432", "mydb", "postgres", "xxx") uri.setDataSource("public", "my_table", "geom") lyr = ...
1
vote
0answers
90 views

Install PyQGIS in virtualenv

Is it possible to install PyQGIS in virtual environment? I want to use rendering capabilities in my own application which runs using virtualenv.
0
votes
0answers
126 views

PyQGIS + PostGis: FATAL: sorry, too many clients already

I searched for questions regarding this problem and hadn't find one. I'm developing a custom application with a map canvas to show some geographic information from a PostGis database. After some ...
2
votes
1answer
71 views

How to properly establish a PostgreSQL connection using QgsCredentials

I'm trying to establish a Postgres connection using QgsCredentials as described here: How to access user credentials in database connection? The only problem is that I cannot establish a working ...
4
votes
1answer
180 views

How can I modify layer order with the QGIS python API [duplicate]

Typically, after a new_layer = addRasterLayer(...) that inserts new_layer before the active layer, I'd like to move it to the top of the table of contents. How to do it? I use an existing QGIS ...
0
votes
0answers
45 views

How to get the color of a vector layer in pyQGIS?

I have see this topic (How to change the color of a vector layer in pyQGIS?) but I'm looking for get the color not to change. How I can resolve my problem ? Thanks
3
votes
1answer
222 views

QGIS python - identify and highlight features programatically

In QGIS there is an option to select features of a selected layer using a "identify feature" tool. Then the feature get highlighted in a different color and attribute dialog is poping up. like that i ...
0
votes
0answers
118 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
2answers
180 views

How to get the file paths of the loaded layers in a QGIS plugin?

I am very new to GIS, QGIS and Python so please bear with me. I am using QGIS 2.0 and I would like to develop a QGIS plugin that would display the raster layers of the main window in order to allow ...
1
vote
2answers
880 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 ...
1
vote
1answer
156 views

How to find the polygons bordering a feature programmatically with qgis?

Is there a way to calculate the neighbors of a polygon with pyqgis for every feature? For example, the selected polygons relative to the one in the center: I found this solution, but it's a year ...
2
votes
0answers
100 views

How can i add a north arrow in QgsComposition?

I'm trying to add an svg image of north arrow in QgsComposition using this code: mapRenderer = iface.mapCanvas().mapRenderer() theComposition = QgsComposition(mapRenderer) ...
0
votes
1answer
68 views

Halt QGIS on startup

I have a custom made login form in Python, which launches on QGIS startup. But before the user has a chance to enter the credentials, the program starts normally, bypassing the form. From then on the ...
5
votes
2answers
388 views

How to write scripts that can call on both Arcpy and PyQGIS?

I have spent quite a bit of time looking for a clear answer this topic and have still been unable to really accomplish my goal of accessing PyQGIS in a stand alone script. Parts of answers have been ...
1
vote
1answer
130 views

How can I add grid lines to a print composition using pyqgis?

I'm writing a qgis plugin to create an image in the print composer of the current map. I can get the map rendered in the proper place with a frame of the right width, and I can get grid annotations ...
0
votes
1answer
45 views

How to add a vector layer in QGIS in python

Someone please can help me how to start with the library qgis ? At first, i'd like to know, by clicking in a button on my litle plugin that i created for QGIS how to add a vector layer with python ...
1
vote
1answer
38 views

How to randomly select from existing points within each polygon?

I have a polygon layer (where each feature has a class attribute), and a point layer, and there are at least 10 points within each feature of the polygon. Is there a way to randomly select only "k" ...
1
vote
1answer
68 views

PyQGIS 2.0 API problem reading attributes

Im reading some attributes from shapefile features in a loop. According to this: http://nathanw.net/2013/06/13/new-qgis-20-api/ I should be able to reference my attributes (and getting native python ...
1
vote
2answers
692 views

QGis 2.0.1 mapserver extension missing

I tried to export my Qgis projects to mapserver, using RT mapserver extension, because there is not any other extension in my version of QGis.(QGis 2.0.1 Dufour on ubuntu 12.04 LTS). After installing ...
3
votes
2answers
440 views

Rendering and Labeling Shapefile with PyQGIS

I've been running into a few problems working with the QGIS API for python. I've gotten more comfortable working in the python console in QGIS but I run into problems when I try to run the code ...
1
vote
0answers
23 views

MSHP file from SAGA tough to delete

After running a SAGA line dissolve process in QGIS, an MSHP file is created (amongst other things). Fine by me, though I'm not sure what it's used for (metadata in XML format?). Problem is that it ...
4
votes
2answers
292 views

Using Python and open source modules, how can I perform Raster Calculator functions?

I would like to perform mathematical functions similar to those you would use Raster Calculator for in ArcMap, however I'd like to do it in Python without using the Arcpy module. I have the osgeo ...
2
votes
1answer
217 views

QGIS 2.0 Plugin: Select and Identify a Single Feature

given is a layer with some nodes on it and every node has some attributes(name, id, etc...). For showing up the informations of a single node I can use the "Identify Feature Tool". Choose the tool, ...
0
votes
0answers
340 views

On install “Couldn't load SIP module.” - should I reroute Python config or download sip?

(Please note I'm still relatively new to Linux). When I run QGIS after install I get a message 'Could't load SIP module'. I've looked for help and am conflicting advice on what my next step should ...
1
vote
1answer
111 views

How to programmatically add an algorithm from external plugin to QGIS processing toolbox?

I'm writing a python plugin for QGIS and I'd like to know if it's possible to provide an interface to it from the processing toolbox. I can see how the existing algorithms are loaded into processing ...
0
votes
0answers
97 views

Missing pyexpat on QGIS 2.0.1: pyuic4 fails

I have encountered a problem when trying to develop a custom plugin for QGIS 2.0.1 (Python 2.7.5 with two additional Python installations on the same machine). When I try to compile the UI file ...
0
votes
0answers
8 views

Apply styles to the attribute window

Is there anyway of "hijacking" the attribute window for full control in Python. I would like to apply the map style to the attribute window also. If the geometry is red, the cell background of ...
2
votes
1answer
141 views

Why does writing large shapefiles crash QGIS?

I'm trying to write large shapefiles with QGIS 2.0 API, using Python, which crashes QGIS. The data is composed of simple two point lines and a data table of five columns. A thousand features or so ...
2
votes
2answers
118 views

How can I close the identify result dialog programmatically?

I am trying to close the identify result dialog which appeared when I select to identify a feature from the active layer. Does someone know how can I do it?
1
vote
1answer
473 views

QGIS 2.0 Python API: Layer vector style loaded from file, marker symbology is respected, labels are not

Im loading a QgsVectorLayer and showing it on map. I load the style i prepared with desktop QGIS 2.0.1 using the layer.loadNamedStyles(path) function in the API and it seems to work, kind of, because ...
3
votes
2answers
150 views

Is there a function to select a region of a map for further processing with Python?

I would like to select a map's region in QGIS for further processing with python console. Ideally I would like to select the region with a mouse drag (like Gimp crop function) and then e.g. analyze ...
3
votes
1answer
235 views

How to apply a color gradient to a shapefile from QGIS console?

Anyone knows how to do a color gradient from the console to a shape file in Qgis (orin Python)? Like the image below.
3
votes
1answer
43 views

How to store the CHANGES to a map database

I'm looking into providing a map amendment service for a particular map series. The service will help map owners look into the changes made to the operational features of the map, after the map was ...
0
votes
0answers
107 views

QgsMapCanvas displays layer only after i resize the window

Im medlling with a standalone PyQGis application (based on 2.0.1). I have no problems with the setup, however when i set up my layers as stated in the docs: layer = QgsVectorLayer(path, name, ...
0
votes
1answer
1k views

How to set PYTHONPATH in OS X to use PyQGIS?

I am trying to use PyQGIS in custom applications. I am on Mac OS X 10.9 with QGIS 2.0.1-Dufour. I know I have to set the the PYTHONPATH environment variable. This is the path to QGIS on OS X: ...
0
votes
2answers
276 views

Developing standalone gis applications using pyqgis

I am trying to develop a standalone application using pyqgis but I have no clue on where to start and where to write the code to make it happen so if anyone can provide me a tutorial to getting ...