Questions tagged [pyqgis]

Python bindings for QGIS.

Filter by
Sorted by
Tagged with
20
votes
3answers
14k views

Problem with import qgis.core when writing a stand-alone PyQGIS script

I am trying to write a stand alone python script in windows 7 that uses qgis.core and various other qgis libraries. I have found an old question on this subject here: Writing standalone Python ...
53
votes
13answers
19k views

Seeking QGIS tutorials and web resources?

I wish to familiarize myself with the capabilities of QGIS up to and beyond QGIS version 3.0. Can you recommend some good web resources and tutorials that would show me QGIS' capabilities? I am ...
28
votes
2answers
7k views

Using QGIS3 Processing algorithms from standalone PyQGIS scripts (outside of GUI)

I'm writing a script which must work outside of QGIS GUI. I call some API functions from qgis.core but I'd like to use the processing plugin. I'm able to import processing with sys.path.append() but ...
18
votes
3answers
5k views

Import error for qgis.core when running OSGeo4w shell script

I've been trying, along with this post, to run a script in OSGeo4w Shell, outside of QGIS. But I get the following error: ImportError: No module named qgis.core I have also read the following ...
20
votes
3answers
14k views

Programatically check for mouse click in PyQGIS?

I want to know how to check for a mouse click in QGIS. I am trying to write a python plugin and want to provide functionality similar to the "Select Single Feature" tool that already exists in QGIS. ...
17
votes
2answers
12k views

Accessing `processing` with Python?

I want to access the explode lines function in Python outside of QGIS from a standalone script. What module do I have to load in order to use it? How can I access processing? from qgis.core import ...
18
votes
5answers
26k views

Installing 3rd party python libraries for QGIS on Windows

How can I use 3rd party libraries on QGIS plugins on Windows? I've developed a plugin that uses rasterio and numpy for a customer, but he's having problems installing rasterio and numpy. Actually ...
23
votes
1answer
5k views

Accessing QGIS plugins in Python?

Is there a way to access QGIS plugins in Python? I'd like to write a script to do some geoprocessing, and I'd like to use the clip, regular points and convex hull tools in fTools, as well as the ...
4
votes
1answer
2k views

Failed to create memory layers in QGIS application on Linux

I have written a python class which reads properties of map layers from an XML file and creates appropriate memory layers. I have developed and tested this code with QGIS 2.8.2 on a Windows 7 machine (...
4
votes
2answers
2k views

Why does QGIS 3.2 “native:extractvertices” algorithm not work properly in standalone script?

I execute standalone python code (almost identical to the code in the accepted answer): The output file does not contain data, and I get this error message: Warning 6: Normalized/laundered field ...
38
votes
3answers
33k views

How to run a simple python script for QGIS from outside (e.g. Sublime Text)?

I would like to run a few small and simple python scripts for QGIS (Mac) from "outside" of QGIS. With outside I mean in this context, either the normal os command line (terminal.app) or even better, ...
33
votes
1answer
7k views

Drawing perpendicular lines in PyQGIS?

I have a situation like this: What I need to do is to connect each point to every line that is at most, let's say 200 m, away from the point. In other words, I need to draw a perpendicular line from ...
7
votes
4answers
5k views

Iterating over layers and export them as PNG images with PyQGIS in a standalone script?

I would like to export specific layers as a png from a QGIS .qgs map. From the table of contents the script would first export the "boundary, climits, and Div1_Irrig_1956_0" layers as one png. The ...
10
votes
2answers
6k views

Programmatically load composer from template and generate atlas using PyQGIS

I am trying to build a plugin to load a print composer from file, generate an atlas and export to image. So far I have been successful in loading the template and exporting it to image. I have been ...
17
votes
1answer
13k views

Writing standalone Python scripts using PyQGIS?

I've been learning how to use the Python Console in QGIS using references from qgisworkshop.org. I'm familiar with writing standalone scripts in ArcGIS and want to learn how to do the same with QGIS. ...
13
votes
2answers
3k views

Calling interpolation plugin from Python console of QGIS

I would like to call the QGIS interpolation plugin function (TIN method) (Raster->Interpolate) from python console. I can't find the corresponding function within QGIS API or within the ...
8
votes
3answers
10k views

Loading raster layer using PyQGIS?

I need to load a raster file from the provided file path. I wish to use it further in the Raster Calculator. I wrote a function which converts string (I assume it is a file path) to a raster object. ...
15
votes
3answers
3k views

Parallelising GIS operations in PyQGIS?

A common requirement in GIS is to apply a processing tool to a number of files or apply a process for a number of features in one file to another file. Much of these operations are embarrassingly ...
21
votes
3answers
21k views

How to create a new empty vector layer programmatically?

I am new to python and QGIS. I have looked at a few tutorials of python scripts for QGIS. All of them create new vector and raster layers with some existing data source. eg. shapefile or geotiff or ...
5
votes
1answer
7k views

Finding nearest line to point in QGIS? [duplicate]

Given a point and few lines, how should I go about finding the nearest line to the point? I am aware of Finding nearest line to point using ArcGIS Desktop (ArcObjects/ArcPy)?, but that is in ArcGIS ...
8
votes
3answers
10k views

Exporting several files at same time in QGIS?

I have a lot of .TAB files open in QGIS and I want to save them to .SHP so I can work with them in ArcMap. Is there a way to save/export all these files at the same time or do I really have to "save ...
11
votes
4answers
9k views

Save Print/Map QGIS composer view as PNG/PDF using Python (without changing anything in visible layout)?

I have a QGIS composer/print view opened with all elements adjusted as I wish. Now I need to print/save/export this as a PNG or PDF file from Python console/Python script. I do not want to change ...
5
votes
3answers
5k views

Refreshing MapCanvas while PyQGIS-script is running

I try to write a PyQGIS script similar to this: Use of python console to prepare offline map from WMS (tile downloader). Basically there are two loops to pan the mapCanvas, refresh the mapCanvas and ...
17
votes
4answers
12k views

Buffering in pyQGIS?

I'm looking for some examples to do simple python scripts in QGIS. How would I do a buffer analysis on a dataset? I can't seem to find much in the manual and QGIS python that quite matches the Esri ...
30
votes
1answer
18k views

QGIS 3 Plugin folder location

I am searching for default location for QGIS 3 Plugin folder I checked here but could not find : C:\Program Files\QGIS 3.0\apps\qgis\python\plugins C:\Users\Abhijit.qgis2 (cannot locate .qgis3, ...
10
votes
1answer
5k views

Using in-memory vector layer with QGIS processing / SEXTANTE

I'm trying to run the qgis:clip algorithm from console, but am getting an error when using an in-memory layer as the overlay parameter. Is this to be expected, or am I doing something wrong? Code: ...
6
votes
2answers
3k views

Applying catgorized symbol to each feature using PyQGIS

I want to apply unique symbol to each feature. i have used following code for doing that from qgis.core import * from PyQt4.QtGui import * # supply path to where is your qgis installed QgsApplication....
18
votes
1answer
7k views

Writing a python processing script with QGIS 3.0

Following the update to QGIS 3.0, it has become very difficult to find any information concerning the writing of processing scripts in QGIS 3.0. @Underdark (see here ) has provided a basis for the ...
8
votes
1answer
5k views

How to evaluate raster calculator expressions from the console?

How can I execute from the console an expression that should be used with the raster calculator? I'm searching for something like this: qgis.someRasterCalcClass.evaluate("boh@1 + boh@2", "outputfile....
11
votes
3answers
6k views

How to load memory output from QGIS processing?

Many processing algorithms have an option to save output as memory. If ran from toolbox, this works fine, because you can tick the "Open output file after running algorithm" box. Looking at the ...
25
votes
2answers
12k views

Is QgsMapLayerRegistry removed in QGIS3?

Is QgsMapLayerRegistry going to be availabe in pyqgis with QGIS3 When I typed it into the QGIS python console (2.99), python seems to recognize it because it auto-completes qgis.core....
10
votes
5answers
5k views

Calculating Image boundary / footprint of satellite images using open source tools?

I need to create the polygon outlines of several single layer raster images, not the extent/bounding box, but the area without the nodata values, as shown here: Creating shapefile showing footprints ...
9
votes
3answers
19k views

Change Shapefile data source encoding?

I tried to change the only the shapefile datasource encoding through properties and also How to encode shapefiles from LATIN1 to UTF-8? but it doesn't change it. Without saving the QGIS project can'...
7
votes
4answers
4k views

How to move layers in the Layer Order Panel using PyQGIS?

Related to the following question but looking for a PyQGIS method: QGIS Layer Order Panel - add layers at top of layer order The following is a simple setup containing a group with three layers. ...
6
votes
1answer
2k views

Is it possible to programmatically add calculated fields?

In the Memory provider described in PyQGIS Cookbook or in question How to create a new empty vector layer programmatically? I can see how to create a vector layer programmatically using standard ...
5
votes
2answers
3k views

Add layer to a QGIS group using Python

I am trying to add new layers into a specific group which I can get to work if I know the index, but how can I get Python to find the index of a group so it can load the new layer into the group ...
8
votes
2answers
5k views

How to automatically reload raster layers if source is changed in QGIS?

How to automatically reloaded raster layer if source is changed? (The path is the same but inside source file are changes) I use: qgis.utils.iface.mapCanvas().refresh() but layer not refresh. # #...
4
votes
1answer
2k views

Adding WMS layer in QGIS standalone Python script [closed]

How do I add a WMS layer on a map, in a standalone Python script with QGIS 2.4? The methodology explained at the bottom of the official QGIS documentation page seems to be outdated and does not work:...
17
votes
1answer
22k views

Getting layer by name in PyQGIS?

I have a plugin which finds buffer for list of cities, provided the distance. The state and city names are taken from the attribute table and gets filtered accordingly. What I want is My plugin should ...
12
votes
2answers
14k views

How to change the value of an attribute using QgsFeature in PyQGIS?

I would like to update one attribute of a feature. However, I don't know to update it using the feature object. I have to use data provider to update it. layers = QgsMapLayerRegistry.instance()....
8
votes
1answer
2k views

What is the purpose of some functions and files in QGIS Python plugins?

I'm just trying to understand the architecture of a QGIS Plugin created with the QGIS Plugin Builder, as well as the workflow and the linkage among generated files. If possible, I'd prefer a diagram. ...
3
votes
3answers
7k views

Can vector layer get start point and end point of line using PyQGIS?

I want to make a buffer on the start or end point of the line and not the line itself. Is there some thing in QGIS python plugin development that can get me the points?
7
votes
1answer
671 views

Launching Processing tool User Interface using PyQGIS

I am trying to launch the UI of a processing algorithm using Python script but I cannot find a simple way for it (aside double clicking on it in the process toolbox of course). The plugin is a water ...
6
votes
3answers
8k views

How can I specify the CRS of a raster layer in pyqgis?

I manipulating netcdf raster data from the QGIS python console. The metadata of my netcdf file does not provide the Reference system. However I know it is 'EPSG:4326' I am writing a python script to ...
11
votes
2answers
9k views

Getting list of layer names using PyQGIS?

I need a list containing the names of all the layers in a QGIS session. I did the task as layersNames = [] for i in self.iface.mapCanvas().layers(): layersNames.append(str(i.name())) but this has ...
7
votes
1answer
3k views

Setting selection color transparent and border color red using PyQGIS?

I have a layer with different informations. I want to change the selected polygon color to "Transparent". I am able to achieve that using: iface.mapCanvas().setSelectionColor( QColor("Transparent") ) ...
7
votes
2answers
779 views

Odd behavior in a QGIS plugin: my function is triggered twice

I have a plugin with a function (triggered by a button) that selects a specific layer by name, then shows its attribute table. When I close the plugin and open it again, the attribute table pops up ...
4
votes
3answers
4k views

Join table field with shapefile programatically (via PyQgis)?

The following is currently unsuccessful at fulfilling a table field join to a point shapefile in Qgis. All instances of the join object will print the proper values, and no error is flagged when ...
4
votes
4answers
3k views

Installing QGIS on Ubuntu 14.04?

Following the QGIS installation guide I have tried both UbuntuGIS and QGIS stable, but both fail with the error message: The following packages have unmet dependencies: python-qgis : Depends: python-...
8
votes
1answer
3k views

Using processing.runalg in QGIS 3

I try to create a common extent for rasters in QGIS 2.99. Here is my script: import processing processing.runalg("script:unifyextentandresolution", "/qgis_data/rasters/Image2.tif; ...

1
2 3 4 5
20