Questions tagged [pyqgis]

Python bindings for QGIS.

Filter by
Sorted by
Tagged with
42
votes
5answers
3k views

Generating equal sized polygons along line with PyQGIS

I would like to create polygons along a line to use them for AtlasCreator in a next step. ArcMap has a tool called Strip Map Index Features. With this tool I can choose the height and width of my ...
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 (...
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, ...
36
votes
6answers
4k views

Development of a plugin which depends on an external Python library

I'm developing a Python plugin, the target is integrating into QGIS the functionalities of a PyPI Python library called 'elevation'. Is there an OS independent way of installing external Python ...
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() ...
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 ...
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 ...
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....
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 ...
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 ...
24
votes
5answers
17k 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?
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 ...
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. ...
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?
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 ...
23
votes
2answers
1k views

Can qgis_core work with external python distribution (such as Anaconda)?

I've built a python application that has its own GUI. I am trying to use qgis.core/PyQGIS as map display only. Specifically, I have anaconda 2.3 and its python distribution (2.7.11). After research ...
22
votes
5answers
4k views

Writing automated tests for QGIS plugins

I'm looking for advice on writing automatic tests for QGIS plugins written in Python. I have written tests for Python scripts in the past using PyUnit (the unittest module), but have never done so for ...
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 ...
19
votes
4answers
508 views

Python literature relevant to QGIS

Python for ArcGIS is a book that I have been looking at. Does anyone know if this would be applicable in QGIS? I am not looking to write application/plugins, simply get better at understanding ...
19
votes
6answers
14k views

Defining layer CRS and avoiding CRS dialog in PyQGIS?

There is an existing Shapefile, which I want to add. At the moment my code looks like: self.iface.addVectorLayer(self.shpFilePath, "Track", "ogr") It works fine, but i want to define the crs within ...
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 ...
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 ...
18
votes
3answers
7k views

Getting layer extent in PyQGIS?

I'm trying to write a processing script using grass r.neighbors algorithm for rasters. When you use the Gui for this algorithm, you can leave the GRASS layer extent field blanc to use the minimal ...
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 ...
18
votes
3answers
15k views

"Select by Attribute" in QGIS using python?

Is there a way to use the function "Select by Attribute" in QGIS using a python command? In my plugin the user should enter a value via a GUI and this value should be used in a function which selects ...
18
votes
4answers
16k views

Filter features based on their attributes using Python

How to get features by their attributes (similar to 'IQueryFilter' in ArcObjects) in QGIS using Python? Instead of getting all features and filter it manually, is there any option to use where clause ...
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. ...
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 ...
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()...
17
votes
1answer
5k views

Is it possible to show our custom message in QGIS Status bar using python?

Is there any way to show our custom message in Qgis Status bar using python? Just like in arcgis IApplication.statusbar.message(0) = "Please wait..." like that is there any option to show progressbar ...
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 ...
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 ...
16
votes
9answers
17k views

QGIS plugin: Problems importing resources (resources_rc) file - plugin doesn't load - PATH problems?

I'm building qgis plugin and I can't find solution for this error. File "/usr/lib/python2.7/dist-packages/qgis/utils.py", line 478, in _import mod = _builtin_import(name, globals, locals, ...
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 ...
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()....
16
votes
1answer
3k views

How to copy the color styling to a color column in a layer's attribute table?

I have a polygon layer in QGIS that I have applied a random color style to each polygon. Under Layer Properties -> Style I selected a Categorized style and then generated a random color ramp. I added ...
16
votes
6answers
3k views

PyCharm 2019 is not working with QGIS anymore

Since the update to PyCharm 2019 I am unable to load the QGIS Python modules. I can not use auto completion either. I already deleted the cache (by invalidating the cache in PyCharm and also by ...
15
votes
3answers
8k views

How to zoom to a selected feature with pyQGIS

I want to create a function that selects a feature and zooms to it (similar in QGIS). Therefore there is following function: QgsMapLayerRegistry.instance().addMapLayer(self.vlayer) def zoomTo(self): ...
15
votes
2answers
12k views

Creating sectors for telecom towers

I work in the Mobile networks industry and i took up a task to create a plugin for QGIS using c++/python that does the following: step 1: Create points corresponding to each mobile tower based on Lat/...
15
votes
2answers
4k views

Creating Virtual Layer programmatically in QGIS

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' ...
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 ...
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 ...
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
3answers
2k views

Controlling rule-based labelling using PyQGIS?

Following on from this question: How to turn on/off all labels of all layers in QGIS, OP mentioned in his comment that he uses rule-based labels. I tried searching online as to how these types of ...
15
votes
1answer
887 views

Showing startup-messages on QGIS splashscreen

During the startup of QGIS, there are status messages shown in the lower part of the splashscreen like "restoring loaded plugins". I am using a startup.py feature from which I would like to inform ...
15
votes
1answer
1k views

How to apply changes in QSettings immediately?

With PyQGIS, you can change various settings such as making the groups in the Layers Panel (or table of contents) bold: from PyQt4.QtCore import QSettings QSettings().setValue("/Qgis/legendGroupsBold"...
14
votes
2answers
5k views

Duplicating layer in memory using pyqgis?

I have a layer in QGIS, and I want to duplicate it through a plugin so I can use the copy of it as I want, without modifying the original. Of course layer2 = layer1 will not work, because everything ...
14
votes
2answers
14k views

Getting the output layer reference returned by Processing tool

After running Processing algorithm ending up with a layer by runalg or runandload in QGIS2, run or runAndLoadResults in QGIS 3, these methods return a result which is mostly a dictionary like {'OUTPUT'...
14
votes
5answers
2k views

How to snap a road network to a hexagonal grid in QGIS?

I'm trying to use QGIS 2.14 to snap a road network to a hexagonal grid, but I'm getting strange artifacts. I've created a hex grid with MMQGIS, cells are approx 20 x 23 m. I've buffered the road ...

1
2 3 4 5
127