All Questions
7,900 questions
0
votes
1
answer
32
views
How to set the CRS correctly PyQGIS to display points on top of OSM basemap
I want to load OSM as a background map and plot some points on top of it. And I want to use PyQGIS to write to a QGIS project file because that's the easiest way to share the data with my particular ...
0
votes
0
answers
56
views
Transforming a line in an arrow with PyQGIS
I'm working on Python Console of QGIS vers 3.36, my goal at the moment is building a plug-in. Well, I would like rendering the lines symbols as some arrows and then setting their aspect, so changing ...
1
vote
0
answers
62
views
Memory management in PyQGIS during loop
I have a issue about memory management in PyQGIS during loop.
I'm writing a code where there is a while loop.
During the operatione inside the loop that are almost the same,I noticed that the ...
1
vote
0
answers
46
views
Cross section profile of: DEM elevation data AND z-values of vector layer vertices
I want a to automate the generation of cross section profiles from elevation from DEM as well as z-values from vector layer vertices and export them as PDF.
The lower part of the images shows the plot ...
0
votes
0
answers
70
views
Export DXF from QGIS with Symbology and Fill for Points in PyQGIS
I'm trying to export multiple vector layers from QGIS to a DXF file using PyQGIS. The export mostly works, but I’m running into issues with points. Currently, points are exported as simple circles or ...
0
votes
0
answers
30
views
How to add multiple functions into the 2.5D height expression
I'm new to Python and made a relatively simple expression to base the height of the 2.5D layer buildings off of the number of stories they have and it works as intended, however I have several ...
0
votes
1
answer
49
views
QGIS programatically get selected symbology classes [closed]
In QGIS, I can select one or more layers or select one or more symbology classes within a layer.
How can I use python to find which of the symbology classes that are selected?
I have been looking ...
0
votes
1
answer
64
views
Getting a callback on layers user selects/clicks PyQGIS [duplicate]
layer = iface.activeLayer()
name = layer.name()
if name == 'zoning':
iface.messageBar().pushSuccess('Selection correct', 'Well done')
else :
iface.messageBar().pushCritical('Incorrect ...
0
votes
1
answer
73
views
Associating corresponding images with layer containing tiles [closed]
I have several layers of georeferenced tiles that I have gathered in a single layer and I am trying to assign the coordinates of the corresponding images to each tile.
A first step allowed me to ...
0
votes
1
answer
77
views
QGIS Python version 3.9.5 + NumPy 1.20.1 on Mac (Apple Silicon) - Insufficient for plugin
I've been trying to get a QGIS plugin to work and running into trouble. The plugin's developer (plugin: Qaequilibrae) has told me that the Python version (3.9.5) and especially NumPy version (1.20.1) ...
1
vote
1
answer
60
views
Data-defined override width of line vector layer using PyQGIS
I am trying to set the width of a line vector layer using the data-defined override option. I want to set the option using PyQGIS in QGIS 3.38.3.
Here is my code, but I just get: <QgsProperty: ...
0
votes
0
answers
22
views
Scripting in the QGIS console crash during iteration pandas dataframe groupby or get_group
The code (dated 28.05.2024) worked correctly every week in QGIS console until 06.08.2024, after begins to crash every week. QGIS version was updated from 3.28 to 3.34, but in September. The problem ...
0
votes
1
answer
63
views
Doing a loop in the run function of QGIS plugin
I am trying to check multiple checkboxes with a for loop in the run(self) function because it needs to be somewhat self suficient and be able to analyse hundreds of checkboxes but it only runs once ...
0
votes
0
answers
29
views
Reload unavailable layers in QGIS
I have a template project which contains a number of layers which don't exist until a model in the project has been run.
Once the model has been run the data for the layers is present but the layers ...
0
votes
1
answer
39
views
Programmatically set default color of QgsAnnotationItem
QGIS 3.36.2 with Python 3.12.3
Users draw a QgsAnnotationLineItem or QgsAnnotationPolygonItem on a QgsAnnotationLayer my script creates, once they're done and press a button, the script reads the item'...
1
vote
1
answer
89
views
Placing a label below a point in PyQGIS
I'm working on Python Console with Qgis vers. 3.36. I would place some labels below some points. I saw just in this forum other question about this issue, but I think the way how to act in this case ...
0
votes
1
answer
31
views
Merging vector layers from GML only if |layername= exists
I have a folder with different GML files and some of them have a specific |layername that I need and want to merge with other GML files that also contain that |layername using PyQGIS
I have a folder ...
1
vote
0
answers
60
views
Accessing QGIS Logs Programmatically in Plugin
I'm developing a QGIS plugin and I would like to access the QGIS log messages (the ones displayed in the Log Messages Panel) directly from my plugin code. This would help me with debugging and provide ...
1
vote
0
answers
85
views
Is there any way to change the Python version linked to QGIS? [closed]
I am developing a plugin for QGIS and as a requirement the user must install a Python package called wntr (https://github.com/USEPA/WNTR). I am doing some tests on other computers to check for errors ...
1
vote
0
answers
54
views
Why are some functions from QGIS's C++ API not available in the Python API?
I am working on a Python plugin for QGIS and want to create a new 3D map view with some specific settings. What I want to do is basically this:
canvas = Qgs3DMapCanvas()
map_settings = ...
2
votes
2
answers
83
views
Making label same color as feature using PyQGIS
I created a rule-based symbology with the following code:
symbol_10 = QgsSymbol.defaultSymbol(lyr_10.geometryType())
renderer = QgsRuleBasedRenderer(symbol_10)
# Definindo as regras: rótulo, expressão,...
1
vote
1
answer
38
views
PyQGIS Set relation strength to "composition"
Working with QGIS 3.34 (ltr) and PyQGIS, I'm trying to set up a relation between point layer and a No Geometry table.
I found out that the correct class to use is: relation.setStrength(QgsRelation....
0
votes
2
answers
107
views
Get coordinates of polyline/polygon drawn by user in QGIS
QGIS 3.36.2 with Python 3.12.3
My code creates a layer (QgsVectorLayer('Point', self.layername, "memory")) that the user can draw a single polyline or polygon on. Once they are done, they ...
0
votes
0
answers
56
views
ArcGIS Pro loads raster with spaces in file path on C: drive, but not other drives
I recently moved my GIS folder from my C: drive to a second storage drive (E:), and am having trouble loading rasters. I narrowed the issue to spaces in the file path - but I can't figure out why this ...
1
vote
0
answers
37
views
Move QgsMapCanvasItem on canvas with PyQGIS
Which is best option to move custom QgsMapCanvasItem on map canvas by mose move?
First of all i have MapTool connected to on_move method, and class with map canvas item.
class testCanvasItem(...
1
vote
0
answers
38
views
Saving several output of an algorithm in a list for former processings in QGIS with Python
I am working on a specific buffer tool for my job. I try to get 3 temporary buffer which schould be merged, saved and load in the project. But I cannot manage to save the three temporary results in a ...
3
votes
1
answer
117
views
Detecting missing credentials programmatically in QGIS Plugin
I am creating a Python plugin that loads two layers, a layer for everyone and an "admin" layer. I want to keep the admin password out of QGIS, so I plan to use a pgpass file.
So from the ...
1
vote
1
answer
68
views
How to assign tuple contents to individual variables
I have a code that creates a POLYGON. There a 5 points representing 5 x/y pairs (the last being a repeat of the first to 'close' the polygon.
I can produce it either as a shapely polygon or a standard ...
1
vote
2
answers
84
views
Extracting coordinates from shapely geometry polygon with PyQGIS
I have the following code to generate a polygon from some calculated points (x/y pairs a,b,c,d) and rotate it by a given angle (Line_Head) around a given point (Rot_Point). This works.
""&...
2
votes
1
answer
36
views
Unticking all layers in main canvas with PyQGIS [duplicate]
For a plugin, I simply want to untick all the layers in the layer tree. Was thinking of something like :
canvas_layers = QgsProject.instance().mapLayers().values()
for layer in canvas_layers:
...
3
votes
1
answer
97
views
Setting labels to be the "Blocking" type using PyQGIS
I'm trying to apply the Blocking label on a layer using PyQGIS but with no success. I also would like to be able to set the obstacle weight as well.
Here is my code so far:
from qgis.core import ...
0
votes
0
answers
61
views
Python Export not working as expected in QGIS Model Designer
I have created a snapping model using the model designer in QGIS 3.34.9. My problem is when I export this model as a Python file, it gives me the same output as the input GeoJSON.
The lines are ...
3
votes
1
answer
150
views
Rendering TIFF in classified presentation in QGIS plugin
I want to load a TIFF and classify its Rastervalues
QList < QgsColorRampShader::ColorRampItem > lst = QList<QgsColorRampShader::ColorRampItem >();
// ... filling ...
2
votes
0
answers
62
views
PyQGIS standalone application with setting dir path and ini file
I want to use PyQGIS from PyCharm to debug and test.
For this I need that my script use my qgis3.ini file to get credential. This one is in
C:\Users\guigu\AppData\Roaming\QGIS\QGIS3\profiles\default\...
3
votes
1
answer
116
views
Making interactable QgsRangeSlider with PyQGIS
In QGIS 3.36 using PyQGIS I would like to make a window with inside a range slider. I was able to show to user a window and, inside a slider, but this is not interactable: it's like an image. How can ...
4
votes
1
answer
154
views
Connecting to the mActionDigitizeWithCurve map tool toggled signal with PyQGIS
Using PyQGIS for QGIS 3.34 and 3.38, I want to connect the toggled signal of the mActionDigitizeWithCurve map tool (in the Digitizing toolbar) to a function for such function to be executed when the ...
0
votes
0
answers
49
views
Force GeoJSON files to store polygons' vertices counter clockwise with PyQGIS
GeoJSON is supposed to store polygons' outer boundaries counter clockwise and the inner rings clockwise. I do not have a preference for one or the other but QGIS is not storing the data uniformly in ...
0
votes
0
answers
43
views
PyQGIS affine transformation scaling problems
I want to create a bounding box around a selected feature and scale this bbox to a certain factor. The input feature results[f'{name_lower}'] is a valid polygon and does not produce any problems by ...
0
votes
0
answers
40
views
Can vector layers using memory data provider render QgsPalLayerSettings label?
I have a memory vector layer created from a GeoJSON feature:
feature = {
"type": "Feature",
"properties": data,
"geometry&...
1
vote
0
answers
60
views
Select features based on a list of values in a .csv file [closed]
I want to extract about 5000 features from a vector layer with over 1 million features. Each feature has a unique code in a field named "KAT". I have a .csv file that contains all the codes ...
2
votes
1
answer
156
views
Enable all snapping types in QGIS using Python
Using the toolbar GUI of QGIS (Currenly using v3.28), I can enabled multiple/all the snapping types like this:
Now that's exactly what I'm trying to do in this code: (Just setting 2 types for the ...
2
votes
1
answer
79
views
Defining not-custom graduated style to polygon layer in PyQGIS
I'm writing some scripts on the PyQGIS 3 console to build a plug-in and I would like to create a color-graduated style for my vector layer. I read Applying graduated renderer to polygon using PyQGIS, ...
0
votes
1
answer
68
views
Canvas not responding in QGIS
In QGIS 3.36.1 I have a weird situation as my QGIS canvas is irresponsive to layer on/off and preset theme visualization. It used to work well, but now it is unusable, even after restart.
Cache?
What ...
2
votes
0
answers
63
views
Projecting (distance, azimuth) point in geographic coordinates with PyQGIS [duplicate]
I have a point in WGS84 (EPSG:4326) for which I would like to calculate a projection based on an azimuth and a distance in meters.
This is basically what does QgsPoint::project but in Cartesian, so ...
1
vote
0
answers
43
views
Getting the screen position (in pixels) of feature in Print Layout with PyQGIS
I have a PyQGIS script that I'm using to generate a series of maps. These maps are individual frames that will be put together in a video. I would like to add some fancy animations associated with a ...
1
vote
0
answers
64
views
Loading parallel PostgreSQL layers with PyQGIS
I want to load a large number of PostgreSQL layers using PyQGIS.
When I load the layers using threads, it creates as many connections as there are layers. For example, if I have 38 layers, I end up ...
1
vote
0
answers
82
views
Map canvas stops working after layers are added via PyQGIS [closed]
I have created a script for automated map production using PyQGIS. One problem I encounter is that the map canvas freezes after I add layers using the following code under QGIS 3.34.6 LTR:
for ...
0
votes
1
answer
70
views
Instantiate a QgsElevationProfileWidget from Python
Is it possible to create a new Elevation Profile window from Python in QGIS 3.38?
(basically what the "Elevation Profile" view menu item does).
It is relatively easy to create a ...
2
votes
1
answer
65
views
"NameError: name 'JoinStyleRound' is not defined" error when offsetting feature of line type geometry with PyQGIS
I'm trying to offset a feature with line-type geometry, I found a suggestion to work based on the QgsGeometry.offsetCurve() method, see https://qgis.org/pyqgis/3.34/core/QgsGeometry.html#qgis.core....
1
vote
0
answers
81
views
Finding a common ancestor using QGIS
from qgis.core import QgsProject, QgsSpatialIndex, QgsFeatureRequest, QgsRenderContext
from qgis.PyQt.QtGui import QColor
from collections import Counter
trafolar_layer = QgsProject.instance()....