All Questions
7,900 questions
48
votes
1
answer
42k
views
What is the default plugin folder location in QGIS 3?
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, ...
43
votes
5
answers
4k
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 ...
42
votes
3
answers
17k
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() ...
41
votes
7
answers
6k
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 ...
40
votes
3
answers
47k
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
5
answers
28k
views
Iterating over map layers using PyQGIS
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 ...
36
votes
3
answers
21k
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....
34
votes
1
answer
10k
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 ...
33
votes
1
answer
47k
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 ...
31
votes
3
answers
29k
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 ...
29
votes
4
answers
59k
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?
27
votes
5
answers
25k
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?
27
votes
1
answer
8k
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 ...
26
votes
6
answers
46k
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, ...
25
votes
3
answers
17k
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 ...
25
votes
1
answer
1k
views
Unit testing for QGIS 3 plugins
There is a nice resource on unit testing for QGIS. There is also a post on this, Writing automated tests for QGIS plugins, which requires the use of docker and relies on QGIS 2 plugin - QGIS Tester.
...
23
votes
5
answers
5k
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 ...
23
votes
3
answers
22k
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
2
answers
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).
It seems that ...
21
votes
6
answers
17k
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 ...
20
votes
3
answers
35k
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....
20
votes
3
answers
12k
views
Getting layer extent using 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 ...
20
votes
2
answers
20k
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 *
...
19
votes
3
answers
9k
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 ...
19
votes
4
answers
523
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
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 ...
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 ...
19
votes
3
answers
4k
views
Releasing PyQGIS file locks
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 ...
19
votes
2
answers
3k
views
Concatenating export path in Google Earth Engine
My goal is to store different exports from Earth Engine projects in separate subfolders of a main GEE_export folder on my Google Drive. I'm using Export.image.toDrive:
Export.image.toDrive({
...
18
votes
4
answers
30k
views
Saving project with data source path as relative in QGIS?
Is there an option in QGIS to save the project with the data source being a relative path?
I don't see the option here. QGIS Wroclaw1.7.3
18
votes
2
answers
6k
views
Difference between QgsPoint, QgsPointXY and QgsGeometry.fromPointXY() in PyQGIS
I am using PyQGIS. What is the difference between:
QgsGeometry.fromPointXY(QgsPointXY(x, y))
QgsPointXY(x, y)
QgsPoint(x, y)
When I print these three options, I get:
print(QgsGeometry.fromPointXY(...
18
votes
3
answers
5k
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 ...
18
votes
3
answers
17k
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
4
answers
19k
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
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.
...
17
votes
11
answers
19k
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, ...
17
votes
2
answers
22k
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 ...
17
votes
3
answers
28k
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()....
17
votes
3
answers
11k
views
Zooming to selected feature using 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):
...
17
votes
1
answer
6k
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
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 ...
17
votes
1
answer
5k
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 ...
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 ...
17
votes
1
answer
8k
views
Loading style (*.qml file) to layer via PyQGIS
Is there any way to load a *.qml file to layer and set a style to it in Python (PyQGIS)?
Can I 'get into' this file in console?
I want to review it.
16
votes
2
answers
8k
views
Rename layers with PyQGIS script
Just discovered QGIS and really impressed! I've not formal GIS training so rely on Google to figure stuff out.
I'm using the SHP files made available by the Canadian Government as part of their ...
16
votes
4
answers
11k
views
Adding layer to GeoPackage using PyQGIS
How to add layers (vector or raster to an existing GeoPackage)?
While loading an existing layer of a GeoPackage is quite trivial:
from qgis.utils import iface
path = '/home/matteo/geopackage.gpkg|...
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 ...
16
votes
5
answers
3k
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 ...
16
votes
1
answer
7k
views
How to apply a filter to multiple vector layers in QGIS?
I am trying to apply an attribute filter to multiple layers in QGIS at once. The filter is to be applied to .osm data brought in through PostGIS to QGIS.
I have tried selecting multiple layers -> ...
16
votes
6
answers
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 ...