All Questions
7,900 questions
9
votes
1
answer
9k
views
Saving layer as shapefile using PyQGIS
Using QGIS 3.4.4, I'm trying to save a layer as shapefile with the following code:
import os
import qgis.core
working_folder = r'C:\myFolder'
fc_Prospect = os.path.join(working_folder, Equipment.gdb|...
9
votes
1
answer
684
views
Which SAGA versions does QGIS 2.18.10 support?
Beginning with QGIS 2.18.10 the SagaAlgorithmProvider do not longer have a dictionary called supportedVersions. Previously, it looked like this:
supportedVersions = {"2.1.2": ("2.1.2", ...
9
votes
3
answers
2k
views
Alternatives to Zonal Statistics which include partial pixels (QGIS)
The task I want to complete is essentially exactly what the Zonal Statistics plugin for QGIS aims to achieve: gives statistics about the values of a raster layer in areas defined by polygons.
However,...
9
votes
1
answer
787
views
Automating QGIS project composer printing?
I have a large project which consists of around 10x QGIS project files. Each project contains a print composer with an atlas set up to generate up to 10 maps.
What is the easiest way to automate the ...
9
votes
2
answers
883
views
How do you obtain the execution times of processes in qgis?
I am working on QGIS. I need to determine how much time QGIS needed to finish a specific task. I have been unable to get execution times for the processes. What is the proper way to get processing ...
9
votes
2
answers
4k
views
Converting Lines to Polygons in QGIS produces Sliver Polygons
While trying to polygonize the polyline layer in PyQGIS using
processing.runandload("qgis:linestopolygons",explode_path,polygon_path)
command in python console, it does not create polygons ...
9
votes
2
answers
2k
views
How can I crawl directory tree and change Mxd relativePaths to true?
I have a large number of project folders where each project folder can have many subfolders. These subfolders can contain mxds, shapefiles, personal gdb's and fgdb's. In many cases the user forgot ...
9
votes
1
answer
5k
views
How to test the geometry type from a list of layers and then join it with PyQGIS 3
Summarizing my problem, I'm a beginner and I'm developing a plugin that will be able to do several spatial joins. For this, it will have to separate the spatial from the non-spatial layers and do the ...
9
votes
1
answer
3k
views
Speed of editing attributes in QGIS from a Python plugin
I'm trying to edit the value of an attribute for each feature in a layer using a QGIS Python plugin. I've found that doing this outside of editing mode is much slower than while editing (even ...
9
votes
1
answer
4k
views
Area calculation in QGIS done two different ways?
It seems that there are at least two different ways to calculate the area of a polygon in QGIS using Python:
1) area = feature.geometry().area()
2) d = QgsDistanceArea()
area_v2 = d.measurePolygon(...
9
votes
1
answer
4k
views
Relative path not working in QGIS with Google Drive?
I have a qgis file, referring to a few shp files, saved on a google drive folder which is synced across two computers using different OS, one is Mac OS X, the other Windows 8. So, the absolute path of ...
9
votes
2
answers
14k
views
Exporting layer to shapefile using PyQGIS?
I´m using python in QGIS 2.2 and struggling with an error trying this:
# create layer from text
_vlayer = QgsVectorLayer(_ur1, "raw", "delimitedtext")
works fine
but:
# export layer to shape
...
9
votes
1
answer
620
views
Programmatically select a GROUP node using PyQGIS
I have seen ways to programmatically select a current layer using QgsLayerTreeView().setCurrentLayer() but I cannot find a way to change the group selection. Does anyone have any tricks/hacks that I ...
9
votes
2
answers
2k
views
Using memory layer as input and/or output with runalg?
Can a memory layer be used as an input and/or output with runalg?
With runandload I get this to work:
processing.runandload("qgis:mergevectorlayers","memory:bufferOne", "memory:bufferTwo", r"memory:...
9
votes
1
answer
3k
views
How to load mvt tiles in QGIS
I want to load mvt tiles into QGIS through a URL service
https://abc.com:8080/buildings/{z}/{x}/{y}.mvt
But, the menu in the Vector Tile Reader plugin allows TileJSON URL.
Is there any way I can ...
9
votes
1
answer
2k
views
Automatically save python scripts in QGIS
When writing python scripts, QGIS does not save them when the user saves his main project with the ctrl+S command or with Project->Save. Besides, when leaving QGIS, the program does not warn about ...
9
votes
2
answers
1k
views
Distributing QGIS plugin which depends on certain Python packages
I developed a plugin for Qgis which depends on some Python packages. On Linux and Mac, this is not really a problem because I can easily install them with the system pip command. Windows is another ...
9
votes
1
answer
8k
views
Add layer to map in qgis3 via a python script
I'm trying convert my old plugin to QGIS3 and one part is to create a shapefile, and afterwards load it to the Layer menu like this:
from qgis.core import QgsVectorLayer, QgsProject
layer = ...
9
votes
1
answer
2k
views
How to solve issue with log messages panel in QGIS: "Not logging more than 100 request errors."?
I am using the following code in pyqgis to catch errors/warning from a WMS-layer, in order to trigger a repaint as soon as an error/warning is detected (based on previous question: How to catch WMS ...
9
votes
1
answer
1k
views
How to use third-party package in a QGIS plugin?
I'm developing a QGIS plugin and I would like to use arrow or requests packages as I'm used to manipulate dates and REST APIs.
QGIS does not come with these packages (at less arrow), so when I try to ...
9
votes
1
answer
4k
views
Calling GRASS modules in pyQGIS?
I wish to use a Grass module (v.to.db) in QGis, without the grass toolbox.
I tried with the Python console, but to no avail :
Using Sextante plugin but obviously it didn't know all the grass modules.
...
9
votes
1
answer
380
views
Expression-based labels in scripted Atlas fail to update
I try to follow Programmatically load composer from template and generate atlas using pyQgis to automate atlas print composer using pyqgis :
specific in atlas code say :
myAtlasMap = ...
9
votes
1
answer
976
views
How do I implement PyQGIS multithreading to update a progress bar
I am developing a PyQGIS plugin using python. I facing a problem during the implementation of threading in my plugin. I have written a Python script which contains a class wrapping all geo-processing ...
9
votes
0
answers
402
views
Calculating new field works inside QGIS Python console but not in standalone program [closed]
My code in the standalone program
import sys
sys.path.append("C:/OSGeo4W64/apps/qgis-ltr/python/plugins")
from qgis.core import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import ...
8
votes
4
answers
689
views
Sorting/ordering selected features by attribute in QgsVectorLayer using PyQGIS
In a standalone application, I have a layer to which I select some features. Then I need to do an iteration, and I need it to be done in the order of the value of a field/attribute (In my example ...
8
votes
3
answers
8k
views
Adding layer to group in layers panel using PyQGIS? [duplicate]
I am trying to add a group to the layer panel, then place a vector layer (vectorLayer) into this group from a python script. The code I am using is:
groupName="test group"
root = QgsProject.instance()...
8
votes
4
answers
2k
views
Iterative selection of features and export to shapefile using PyQGIS
I'm working with QGIS 3.10 A Coruña on MacOS 10.13 environment.
I have a vector polygon layer and I need to select features with a given attribute value and export them as a new shapefile. I'm a ...
8
votes
4
answers
2k
views
Saving GeoPackage with style in PyQGIS
I have a function that uses a layer already styled using another function and saves it as a .gpkg and I want to save the style in that .gpkg:
def saving_gpkg(styled_layer):
options = ...
8
votes
2
answers
2k
views
Clearing QGIS Python console with pyQGIS
I'm developing a Python script in which I use several "print" statements to view the intermediate results in Python console of QGIS. Each time after executing the program, I have to manually ...
8
votes
2
answers
9k
views
QGIS Error while executing Python function in openProject() Macro: "QgsMapLayerRegistry is not defined"
I have the following script that sets the a feature id automatically after a new feature is digitized.
I want the following function to be executed automatically when project is opened (and layers ...
8
votes
1
answer
7k
views
Applying graduated renderer in PyQGIS? [closed]
Just trying to run the following code already given in the pyqgis cookbook to create graduated colors symbology (as in example with 2 classes)
I define the source info for the shapefile but when I ...
8
votes
2
answers
1k
views
Managing layers from a specific group with PyQGIS
I have some layers loaded in QGIS, in various groups. I want, with PyQGIS, do some stuff on layers from one of theses groups, like adding geometry type to the layer name.
This way, I can do it on all ...
8
votes
2
answers
8k
views
Getting layer by name using PyQGIS 3 [duplicate]
How do I get the layer by name using PyQGIS 3?
8
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 ...
8
votes
2
answers
4k
views
Getting pixel value using PyQGIS
I want to get a pixel value fro the satellite image (Landat, GeoTIFF, 7 bands) using qgis-python.
What operators should i use? (for example in qgis's Python Console)
8
votes
2
answers
2k
views
Adding temporary output of processing algorithm to the map canvas using PyQGIS
Let's say I run a simple algorithm like this
import processing
# https://docs.qgis.org/3.16/en/docs/user_manual/processing_algs/qgis/vectoranalysis.html?highlight=count%20points%20polygon#id3
...
8
votes
3
answers
3k
views
Changing CRS of layer using PyQGIS without saving file and iterating every feature
So I have one layerA with CRS:4326 and I can change CRS saving it:
# This layer has crs:4346
layerA = QgsVectorLayer("layerA.sqlite", "layerA", "ogr")
#New crs
crs = ...
8
votes
2
answers
5k
views
Set the layers style programmatically using QGIS
I have a layer of GPS points (about 60 layers) loaded inside my .qgs file.
I want to set all their styles in the same manner using a .qml file without doing it one by one.
Can somebody illustrate ...
8
votes
2
answers
475
views
Looping with a range of integers for 'numeric' inputs in QGIS Python Console
I have been trying to run r.sun.incidout in a loop of integers (for the 'Day' option, type=integer) in QGIS Python Console. Since the 'day' parameter takes an integer number for its value, I get the ...
8
votes
2
answers
5k
views
Using PyQGIS, ArcPy, NumPy, SciPy Together in Windows Command Prompt
I ran across this slight issue when I was looking to access python installations from ArcGIS, QGIS, Anaconda (cited because SciPy & NumPy come with it), and version 2.7 vs 3. Sometimes, I find it ...
8
votes
2
answers
1k
views
Install Python library in QGIS as non-administrator
I would like to install the Python library in QGIS, but I have no administrator rights.
Unfortunately, each solution found refers to the simplest installation via osGeo4W, which requires running as an ...
8
votes
1
answer
686
views
Getting QgsVectorLayer from QgsFeatureSink
I have created a feature sink like so:
(sink, dest_id) = self.parameterAsSink(...)
And added a number of features to it. When I'm done processing, I want to post-process this layer using gdal:...
8
votes
2
answers
418
views
Highlighting snapping position in PyQGIS
I'm trying to add points on a line with QgsMapTool. I need to show snap indicator (vertex or edge) while moving the mouse on a line.
How can I do that?
Here is my code:
class uubEditTool(...
8
votes
2
answers
665
views
PyQGIS Temporal Controller current moment
I have a QGIS Project with Temporal Controller, in Python Console. How could I capture the current moment of the simulation?
I'm trying, but doesn't work
canvas = iface.mapCanvas()
temporal= canvas....
8
votes
2
answers
9k
views
Select by location in Python
I have a polygon layer and a point layer (with coordinates for each point).
The polygon layer got created using the MMQGIS plugin (Hexagonal Polygons).
I want to select all the points inside each ...
8
votes
2
answers
5k
views
How to select and zoom in features from a QGIS Python Plugin
I'm very new to Python. I'm trying to find a way to select and zoom to the features from a QGIS layer.
I've created a plugin and built a custom form. I have 3 values from the form which I need to ...
8
votes
3
answers
3k
views
How do I set layer transparency in QGIS 2.0 with Python?
I have a raster layer loaded in QGIS 2.0 and I'd like to be able to set its transparency via the Python console. I'm new to the API and have not been able to find out how to do this.
Here's what I ...
8
votes
2
answers
408
views
Iterating through fields and generating formatted string output
I want to iterate through all integer type fields in a layer and generate new "display" fields marked with a 'd' at the end of the name using the appropriate field calculator expression.
The ...
8
votes
1
answer
3k
views
Difference between iface.mapCanvas and QgsMapCanvas
I am working on a standalone PyQGIS script and I wanted to set the project extent to position on the imported layer.
First I tried with:
vlayer = QgsVectorLayer("data/layers/layer1.gpkg", &...
8
votes
1
answer
6k
views
Open .qgz files to edit file paths
I have hundreds of QGIS projects that have been built over years and many different QGIS versions. Now I need to move them to another server and I want to be able to edit the project files to show the ...