Questions tagged [pyqgis]

Python bindings for QGIS.

Filter by
Sorted by
Tagged with
0 votes
0 answers
18 views

How to get current (selected) tool from toolbars (map navigration tools & object selection panel) and change it in code [duplicate]

I'm developing a plugin for QGIS, and for further implementation there should be logic that automatically switches current tool to 'select objects', and, after selection, returns to the previous tool.
ScribeR's user avatar
0 votes
0 answers
21 views

Reverse linestrings, given attributes

I am working with street numbering and toponymy and I have an issue in hands: Given some data provided by an Institution, i.e.: points as door numbering and lines as the streets Those streets were ...
PatsonJS's user avatar
0 votes
1 answer
38 views

Correct way to specify Inputs and Outputs for QGIS processing scripts that use custom widgets?

Processing scripts do not allow parameter inputs to be changed by other parameter inputs. This can be overcome by defining a custom widget which does have the desired interactions, then using a '...
Alexei Y's user avatar
1 vote
1 answer
21 views

Generate layer preview icons

QGIS uses small image preview icons for its layers in the legend and layer tree. How can I create these for a given layer as an image object (QIcon or QImage I presume)? As I am looking for a PyQGIS ...
bugmenot123's user avatar
  • 10.2k
0 votes
0 answers
19 views

MB Tile Error in QGIS [closed]

While generating MB Tiles following error is encountered: Traceback (most recent call last): File "C:\PROGRA~1/QGIS33~1.1/apps/qgis/./python/plugins\processing\algs\qgis\TilesXYZ.py", line ...
Sabeen's user avatar
  • 1
0 votes
0 answers
33 views

How to make old Python code compatible with QGIS v3.16 [closed]

We had some Python code in a QGIS v2.18 "Action" which emailed a recipient when we clicked on the action. Now we are on QGIS v3.16 the code in the "Action" no longer works. Gives ...
sar_copp's user avatar
0 votes
0 answers
39 views

AttributeError: NoneType

I have this code I use in the QGIS Python console. I used it a few days ago and it worked, but I tried using it again and I got this error: Traceback (most recent call last): File "C:\PROGRA~1\...
Gabriel Mulero's user avatar
0 votes
0 answers
33 views

PyQGIS Push selected feature to identification results panel

I have selected feature on vector tile layer loaded from https://cdn.kadastr.live/tiles/maps/kadastr/land_polygons/{z}/{x}/{y}.pbf How do I make its attributes appear in the identification results ...
Стьопа Брич's user avatar
0 votes
1 answer
36 views

Selecting point/feature in layer using coordinates [closed]

I want to select a feature using my own coordinates. Is that possible in PyQGIS? I mean i enter my own coordinates and the program should select the feature at that specific coordinate if there's an ...
Ali Rao's user avatar
0 votes
1 answer
57 views

Python script run error QGIS

I have been using the Python console in QGIS to develop a script. However, I keep getting the below error whenever I try to execute it. This is line 43 which has the error
Alaa Torkey's user avatar
0 votes
0 answers
59 views

Fatal Exception (access violation) when executing QgsExpressionContextUtils.projectScope(QgsProject.instance()) inside a QgsFunction

QGis is randomly crashing and throwing "access violation" exceptions when I run the following line of code inside a qgsFunction: QgsExpressionContextUtils.projectScope(QgsProject.instance()) ...
Guilherme Alexsander Pereira's user avatar
1 vote
2 answers
83 views

PyQGIS VectorTileLayer feature selection by coordinates

I have vector tile layer in QGIS, loaded from https://cdn.kadastr.live/tiles/maps/kadastr/land_polygons/{z}/{x}/{y}.pbf. How to select single feature of this layer by coordinates, in PyQGIS? I am ...
Стьопа Брич's user avatar
1 vote
1 answer
56 views

Create virtual/temporary layer from a GeoDataFrame in QGIS

I'm trying to make a plugin that lets me combine the Tracks from multiple GPX files into one virtual/temporary layer in QGIS. Currently I have code that saves them as a GeoJSON layer but with a large ...
Lost Mapper's user avatar
  • 1,898
0 votes
0 answers
7 views

Install QGIS with the GRASS plugin enabled in a conda environment?

I am having issues using the GRASS plugin in QGIS in a PyQGIS script. I used miniconda on Ubuntu 20.04.6 LTS to create an env with QGIS using conda commands: conda create -n qgis_test conda activate ...
Cicatrixx's user avatar
  • 101
0 votes
1 answer
41 views

QGIS - QgsProcessingParameterFeatureSource - Filter input layer

In QGIS, I try to write a script for a custom toolbox. I'm using the processing framework logic and following official documentation. I add an input vector layer, but I can't handle it has a ...
GeoGyro's user avatar
  • 1,566
0 votes
1 answer
41 views

Building a WMS QgsRasterLayer from a QgsDataSourceUri

I have the following information for a WMS: Base-URL: http://example.com/wms CRS: EPSG:1234 Format: image/png Layers: wms-layer How can I use QgsDataSourceUri to create a WMS QgsRasterLayer from ...
bugmenot123's user avatar
  • 10.2k
0 votes
2 answers
72 views

Loop an operation in all features

I have a layer that has date and time information and I need the difference between this information in seconds, I managed to get close to this but I needed to loop for the difference between the ...
Mestrexama's user avatar
0 votes
1 answer
34 views

Create the lines at a certain angle in PyQGIS

I want to create the lines at a certain angle? How can I do it? Also The lines are coming out about 5-10 cm shorter than they should be. How can I correct this? My code: from qgis.core import ...
BrsDltV's user avatar
-1 votes
0 answers
21 views

How to represent a shape 3-dimensionally in QGIS [duplicate]

I am working on verifying terrain clearance for a runway in QGIS. I have specific elevations for each vertex on the shape. How can I make this a 3 dimensional plane? This is roughly the side view I ...
JBN's user avatar
  • 1
1 vote
1 answer
78 views

QgsMapToolEmitPoint(): argument 1 has unexpected type 'sip.wrappertype'

I have tried this code and several other similar versions and I always get this error See Writing Custom Map Tools using RectangleMapTool QgsMapToolEmitPoint.__init__(self, self.canvas) TypeError: ...
Bandit253's user avatar
1 vote
2 answers
41 views

QGIS: moving layers inside Layertree into a group crashes QGIS using python

I am trying to reorder the result of a model using python in the layer tree. For this purpose I wrote a script that takes the name and group as well as the the desired layer position in this group as ...
Riccardo's user avatar
  • 2,608
0 votes
0 answers
23 views

Using outside Python framework (ObsPy) in QGIS API (PyQGIS) [duplicate]

I would like to use ObsPy, a seismology framework for Python available at https://github.com/obspy within the QGIS Python API. I have been able to use ObsPy to plot moment tensor solutions in an ...
user230663's user avatar
0 votes
0 answers
48 views

Adding slope to lines drawn using PyQGIS

I want to add a slope to lines drawn using PyQGIS. The lines drawn with PyQGIS are currently green, but I want them to appear brown. How can I achieve this? The code I wrote: import math from qgis....
BrsDltV's user avatar
0 votes
0 answers
15 views

Custom Feature Form - Add multiple Features - Crashes when commiting

I use a custom feature form to set new features for my point layer. Beause i have to set many points i dont want to open the form new every time i set a new point. Thats why i added a function which ...
Tim_Tries_PY's user avatar
0 votes
0 answers
15 views

QGIS Flatpak installation 'ModuleNotFoundError' under Linux Mint

I'm pretty new to Linux and trying to install QGIS with some extra plugins for hydrodynamic modelling. I followed the instructions regarding the flatpak installation on qgis.org. After installing the ...
TimNmn's user avatar
  • 1
0 votes
1 answer
39 views

How to export a jpeg image with a raster layer extent in PYQGIS?

I'm struggling with this issue from weeks. I wrote this code in order to: load a raster layer (image of a port) Taking only the gray band of it load a mask to put on top of it and set it black export ...
Fabiola Borrini's user avatar
1 vote
0 answers
32 views

How to use the field calculator array_mean() function in Python console QGIS

I have a layer with USA counties; each county has a unique identified 'COUNTYNS' and a field "CO_mean_microg_m3". Some counties have this CO value as NULL, so I want to take the 6 nearest ...
Mariia Murasheva's user avatar
1 vote
1 answer
30 views

Loading S3 hosted COPC (LAZ) in QGIS 3.28.9 using Python

I am attempting to loop over dozen of https S3-hosted COPC (LAZ) files in Python for QGIS to (1) render them, and (2) write out a simple thumbnail Jpeg. Using the script below I can successfully loop ...
Trent's user avatar
  • 13
0 votes
0 answers
31 views

Batch processing layouts with several shapefiles based on master layout

I'm trying to batch some layouts based on a master layout through the python console in QGIS. Basically, what I'm trying is to generate a layout like the one below and print a *.png of the layout. I ...
Andreas Hansen's user avatar
0 votes
0 answers
31 views

Accumulated distance between points

I have this piece of code that I can make lines between points and calculate the length of the line, but now I need to calculate the accumulated distance only between the X axis, I managed to use ...
Mestrexama's user avatar
2 votes
2 answers
124 views

Calculating main_angle of polygons using PyQGIS

According to Calculating Polygon Main Angle using QGIS, it is possible to find the main_angle of a polygon by using a field expression like: main_angle($geometry) Can this function be called using ...
user35594's user avatar
  • 545
0 votes
0 answers
30 views

QPushButton : disconnecting the clicked signal

I am using QPushButton called 'add_routes_pb' I am connecting its 'clicked' signal to a slot function i.e 'Add_routes_func' which is in another class. Problem Faced: The problem which I am facing is , ...
BenStone's user avatar
  • 303
1 vote
0 answers
32 views

Handling intermediate service layer errors in Python

I have a QGIS project with a WMS (QgsRasterLayer) and a WFS (QgsVectorLayer) layer. These layers might encounter random issues, e.g. missing network access or parsing errors. How can I be notified ...
bugmenot123's user avatar
  • 10.2k
0 votes
0 answers
34 views

How to export vector layer containing symbology compatible with ArcGIS on PyQGIS

I export vector layer(.shp) with symbology file(.qml) like below code. The exported files works on QGIS, but on ArcMap (ArcGIS), qml file doesn't work. How can I extract symbology file on PyQGIS so ...
qgisWorker's user avatar
1 vote
1 answer
106 views

QGIS action Python recover id after paste

I have 3 layers: a point layer (1) with id, a polygon layers origin (3) with id_1. a polygon layer destin (2) with id, id_1 et id_p. I want to copy the polygons from layer 3 (which I select with the ...
fcka's user avatar
  • 841
1 vote
1 answer
43 views

Select several layers by name using an expression

I'm am new to using PyQGIS and this question has been answered in various forms already, however not specifically the way I need it; I have a big QGIS project with several layers with similar, but not ...
KodakAsis's user avatar
1 vote
0 answers
28 views

shortestpathpointtolayer

I am trying to use the shortestpathpointtolayer function in QGIS with Python as below. start_points = QgsProject.instance().mapLayersByName('start points layer')[0] end_points = QgsProject.instance()....
Mattias's user avatar
  • 11
0 votes
0 answers
40 views

Read Project File in QGIS Macro

One of the things I really like about ArcGIS Pro is that, when you start a new project, it prompts you to create a new .gdb associated with the project. I'm attempting to replicate this behavior in ...
slapthefrenchman's user avatar
0 votes
0 answers
19 views

QGIS version 3.32.1, after packaging independent application loading raster data could not correctly read the coordinate system

QGIS version 3.32.1, secondary development in PyCharm, after packaging independent application loading raster data could not correctly read the coordinate system。 autorsrs.py: if __name__ == '__main__'...
yang he's user avatar
3 votes
1 answer
84 views

How to authenticate to download images from https://landsatlook.usgs.gov/stac-server

I am building a QGIS plugin in Python to fetch Landsat images from this STAC server: https://landsatlook.usgs.gov/stac-server I need to be able to download the thumbnails, but cannot find how to ...
staf's user avatar
  • 294
0 votes
0 answers
35 views

QGIS processing script crashes while trying to set layer styles

So i recently tried to improve my script for automatically setting the style of vector layers from a folder filled with ".qml" files. It usually crashes around the 4th or 5th layer, and if i ...
Elfry's user avatar
  • 1
0 votes
1 answer
23 views

Update labeling expression and properties with PyQGIS

With PyQGIS API, I need to set labeling expression and text color dynamically before exporting the map to different file formats using QgsLayoutExporter. The code I use: layerTree = QgsProject....
superrache's user avatar
0 votes
1 answer
52 views

How to change output layer name when using processing algorithms in own PyQGIS script

If I execute the following example PyQGIS script, the temporary output layer is called "Remaining fields" in the layers panel which is the standard output layer name of the last executed ...
zfn's user avatar
  • 35
0 votes
0 answers
26 views

Import QWebEngineView into PyQGIS script

I'm working on a project that should interact with Google Maps API. Usually I use QWebView as a widget to load web pages. But my simple html page is not loading there. However if I load the original ...
Pavel Pereverzev's user avatar
1 vote
0 answers
17 views

Accessing model using PyQGIS

I've tried various ways to acccess my *.model3 file using PyQGIS libs as standalone script. I can access and run my model from script stored inside QGIS. processing.run('model:my_model_name', params) ...
JuniorPythonNewbie's user avatar
0 votes
1 answer
21 views

processing.run wont work with filter on layer

I have a pyqgis script in my plugin. There I like to execute a process: new = processing.run("native:splitwithlines", {'INPUT':QgsProcessingFeatureSourceDefinition('table-path-to-the-db', ...
CruiseLee's user avatar
0 votes
0 answers
27 views

PyQGIS: Remove a legend item NOT the whole layer from the project

I have a number of vector layers and, occasionally, an image basemap. I am creating a layout programatically based on this data. I have a legend but I have zero want or need for the basemap raster ...
Ingwe's user avatar
  • 179
0 votes
1 answer
51 views

Hide the "Quick Field Calculation Bar" in QGIS

I want to hide the Quick Field Calculation Bar (see image). I found this old thread: Disabling FieldCalcBar in QGIS but sadly it does'nt work in QGIS 3.28. Does anyone know what the quick field ...
Stedanko's user avatar
1 vote
1 answer
100 views

import pyarrow fails even when installed

I need to use the pyarrow package on QGIS 3 (using QGIS 3.32.2 'Lima') on Windows 11, and install it in OSGeo4W shell using pip: pip install pyarrow, which installs 13.0.0 by default as I'm writing ...
Neptune-Meister's user avatar
1 vote
2 answers
49 views

Call and Run PyQGIS script by plugin

I wrote a code that work well in console python, an example: from qgis.core import QgsProject, QgsLayerTreeGroup, QgsLayerTreeLayer, QgsLayerTree from PyQt5.QtCore import Qt, QVariant, QSettings, ...
freecma80's user avatar

1
2 3 4 5
147