Questions tagged [pyqgis]

Python bindings for QGIS.

Filter by
Sorted by
Tagged with
41 votes
3 answers
16k views

Using QGIS 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() ...
vidlb's user avatar
  • 699
22 votes
3 answers
21k 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 ...
user24956's user avatar
  • 409
9 votes
1 answer
4k 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 (...
Detlev's user avatar
  • 4,608
25 votes
6 answers
43k 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 ...
George Silva's user avatar
  • 6,298
19 votes
3 answers
6k 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 ...
Joseph's user avatar
  • 75.6k
20 votes
2 answers
19k views

Accessing QGIS processing with PyQGIS

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 * ...
ustroetz's user avatar
  • 7,974
27 votes
1 answer
7k 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 ...
mattwigway's user avatar
25 votes
3 answers
16k 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 ...
robert's user avatar
  • 375
6 votes
2 answers
4k 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 ...
Comrade Che's user avatar
  • 7,051
34 votes
1 answer
9k 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 ...
PeterBorook's user avatar
16 votes
3 answers
26k views

Changing value of attribute of QgsFeature using 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 a data provider to update it. layers = QgsMapLayerRegistry.instance()....
wannik's user avatar
  • 525
14 votes
3 answers
7k views

Adding layer to group using PyQGIS

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 ...
Seth Loader's user avatar
40 votes
3 answers
44k 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 (...
Benedikt Groß's user avatar
35 votes
2 answers
20k 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....
tinlyx's user avatar
  • 11.1k
12 votes
4 answers
9k views

Iterating over layers and exporting them as PNG images with PyQGIS in standalone script

How do I 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 ...
brgionta's user avatar
  • 507
15 votes
3 answers
2k views

Determining 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 ...
Ian Turton's user avatar
  • 81.1k
14 votes
2 answers
5k 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 ...
Vincent D.'s user avatar
32 votes
1 answer
43k 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 ...
User123's user avatar
  • 2,976
12 votes
2 answers
7k 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....
Keyur Parmar's user avatar
10 votes
3 answers
16k 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. ...
matandked's user avatar
  • 681
6 votes
3 answers
6k 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 ...
Katalpa's user avatar
  • 871
29 votes
3 answers
28k views

Creating new empty vector layer with PyQGIS

I have looked at a few tutorials on Python scripts for QGIS. All of them create new vector and raster layers with some existing data source e.g. shapefile or GeoTIFF or PostGIS database table. Is it ...
Theuns Heydenrych's user avatar
27 votes
3 answers
56k 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?
user16018's user avatar
  • 289
19 votes
3 answers
4k views

Releasing PyQGIS file locks [closed]

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 before I can do ...
user avatar
18 votes
1 answer
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. ...
djq's user avatar
  • 16.3k
17 votes
1 answer
4k 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 ...
Joseph's user avatar
  • 75.6k
15 votes
4 answers
11k 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 ...
matandked's user avatar
  • 681
15 votes
2 answers
16k views

Getting the output layer reference returned by Processing tool

After running Processing algorithm ending up with a layer by run or runAndLoadResults in QGIS 3, these methods return a result which is mostly a dictionary like {'OUTPUT': 'file_path'} etc. So, after ...
Kadir Şahbaz's user avatar
12 votes
4 answers
22k 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 "...
Frida's user avatar
  • 175
11 votes
2 answers
7k views

Loading composer from template and generating 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 ...
Matt's user avatar
  • 2,706
27 votes
5 answers
24k views

Getting path of project or layer file in PyQGIS

I am generating new raster files from vector layers on a project. I would like to save them in the same directory as the project or layer files. How do I find this path using PyQGIS?
fccoelho's user avatar
  • 1,227
20 votes
3 answers
33k views

Selecting features using 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....
ustroetz's user avatar
  • 7,974
17 votes
4 answers
17k 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 ...
GIS Danny's user avatar
  • 733
17 votes
3 answers
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 ...
Mr Purple's user avatar
  • 1,451
16 votes
2 answers
20k 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 ...
jgpallero's user avatar
  • 749
13 votes
5 answers
9k 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 ...
spib's user avatar
  • 483
11 votes
1 answer
6k 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; ...
Mustafa Uçar's user avatar
11 votes
3 answers
7k 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 ...
EikeMike's user avatar
  • 1,171
9 votes
2 answers
9k views

Transforming single QgsGeometry object from one CRS to another using PyQGIS

I have a polyline layer with roads in WGS84 that covers several UTM zones. For every road I need to place a set of points at different distances (in metres). To do so I want to reproject each road to ...
SS_Rebelious's user avatar
  • 5,601
9 votes
4 answers
9k views

Finding nearest line to point in QGIS? [closed]

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 ...
PeterBorook's user avatar
19 votes
1 answer
9k 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 ...
Kantan's user avatar
  • 1,917
17 votes
3 answers
9k 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 ...
user avatar
16 votes
2 answers
5k views

Creating Virtual Layer with PyQGIS

Is it possible to create a Virtual Layer through a Python script? For example, I have a layer 'road', and I would like to perform the SQL query: SELECT * FROM road WHERE type = 'Expressway' Will this ...
Cy T's user avatar
  • 687
11 votes
3 answers
11k views

Setting layer visibility with PyQGIS

Im having a problem toggling the visibility of map layers in PyQGIS (2.4). I have a simple interface, just the map canvas, no legend, and a radio button that toggles between two raster layers. Layers ...
U2ros's user avatar
  • 5,117
10 votes
1 answer
6k 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: ...
user avatar
10 votes
1 answer
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. ...
User123's user avatar
  • 2,976
9 votes
3 answers
33k 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'...
Muhammad Faizan Khan's user avatar
9 votes
1 answer
5k views

Evaluating raster calculator expressions from 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....
diegogb's user avatar
  • 623
6 votes
1 answer
3k 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 ...
Nicola's user avatar
  • 183
6 votes
1 answer
4k views

Getting coordinates of point on mouse click using PyQGIS

I want to get x/y coordinates of a point on mouse click for a point and need to use those coordinates to evaluate other values as per other modules already define. How can I get x/y coordinates on ...
sudhanshud's user avatar

1
2 3 4 5
30