Questions tagged [pyqgis]

Python bindings for QGIS.

Filter by
Sorted by
Tagged with
35
votes
3answers
11k views

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

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

Importing qgis.core when writing standalone PyQGIS script

I am trying to write a standalone Python script in windows 7 that uses qgis.core and various other qgis libraries. I have found an old question on this subject at Writing standalone Python scripts ...
23
votes
6answers
35k 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 ...
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 ...
6
votes
1answer
3k views

Layer is not valid error in my standalone PyQGIS script/app

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 (...
24
votes
3answers
15k 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. ...
19
votes
2answers
15k 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 ...
26
votes
1answer
6k 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 ...
33
votes
1answer
8k 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 ...
6
votes
2answers
3k 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 ...
40
votes
3answers
38k views

Running simple Python script for QGIS from outside

I would like to run a few small and simple Python scripts for QGIS (Mac) from "outside" of QGIS (e.g. Sublime Text). With outside I mean in this context, either the normal os command line (...
16
votes
3answers
20k views

Changing the value of 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()....
13
votes
3answers
5k 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 ...
32
votes
2answers
16k views

Was QgsMapLayerRegistry being removed in QGIS 3?

Is QgsMapLayerRegistry going to be availabe in PyQGIS with QGIS 3? When I typed it into the QGIS python console (2.99), python seems to recognize it because it auto-completes qgis.core....
13
votes
2answers
4k 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 ...
10
votes
4answers
8k 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 ...
11
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 ...
18
votes
1answer
14k 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. ...
15
votes
4answers
10k 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 ...
15
votes
1answer
3k views

Making layer or group private/hidden/invisible in Layers Panel of QGIS

I have a number of layers in the Layers Panel inside a group but I don't want them shown (there's quite a lot so it looks untidy). These layers are also joined to several others. Is it possible to ...
15
votes
3answers
1k views

How to determine neighbouring tile ids in QGIS?

I was asked in a recent training course if QGIS could automatically calculate the next/previous and above/below page numbers for a map book created using the atlas generator. I managed to work out a ...
10
votes
3answers
13k views

Loading raster layer in a standalone PyQGIS script

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. ...
10
votes
2answers
5k views

Applying categorized 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....
17
votes
3answers
4k 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 ...
24
votes
3answers
24k 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 ...
23
votes
3answers
41k views

Reading attribute values using PyQGIS

What is the way to get the information contained in the attribute table, say in column 2, row 2 using PyQGIS?
28
votes
1answer
32k 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 ...
8
votes
1answer
8k 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 ...
10
votes
4answers
16k 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
1answer
5k 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; ...
9
votes
3answers
6k 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 ...
19
votes
1answer
8k 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....
15
votes
3answers
8k 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 ...
17
votes
4answers
14k 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 ...
9
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. ...
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: ...
9
votes
3answers
26k 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'...
5
votes
3answers
5k views

Joining table field with shapefile using 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
1answer
2k views

Adding multiple plugins to custom menu in QGIS

I am new to Python and QGIS and attempting to create some plugins to replicate in-house tools used in other GIS programs. I have added a custom menu using Python and added the plugin to the menu using ...
16
votes
2answers
13k views

Getting list of layer names using PyQGIS [duplicate]

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 ...
34
votes
5answers
24k views

Iterating over map layers using Python in QGIS

I'm having trouble figuring out how to iterate over map layers. I can access the currently highlighted layer in the table of contents via iface.activeLayer() but I want my code to operate on all ...
17
votes
3answers
25k views

Selecting features using an expression with PyQGIS

How can I select features with PyQGIS using an expression? I tried to use an QgsExpression but the select method doesn't take it: exp = QgsExpression("'ogc_fid' = 482") cLayer = canvas.currentLayer()...
39
votes
1answer
28k 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, ...
11
votes
5answers
7k 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 ...
11
votes
2answers
6k 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. # #...
3
votes
3answers
9k 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?
18
votes
2answers
3k views

Releasing PyQGIS file locks?

I was wondering what triggers the release of file locks in pyQGIS? I am trying to delete a few data sources (used temporarily) by calling QgsVectorFileWriter.deleteShapeFile, but I have to quit QGIS ...
10
votes
4answers
6k 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
3k 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 ...

1
2 3 4 5
26