Questions tagged [pyqgis-3]

Python bindings for QGIS 3.

Filter by
Sorted by
Tagged with
1 vote
0 answers
20 views

Using PyQGIS to replicate my PostGIS result of placing radial lines over polygons

As shown in this photo I have some polygons. I want to make a grid over these polygons (lets say the squares of the grid are 100x100) and over each square I want to place radial lines going through ...
user avatar
  • 75
1 vote
1 answer
54 views

Using PyQGIS to buffer the width different than the height of a rectangle

So I have a polygon in QGIS (3.18) and it will always be a rectangle (I create it using minimum bounding geometry, oriented rectangle) I want to buffer the width out using some math to get the total ...
user avatar
  • 75
2 votes
0 answers
25 views

Running the method of QGIS plugin on a seperate thread

I am working on a QGIS plugin. The plugin has a main class running all the operations. I was trying to add a progress window in it. The window should load when a button is clicked running a method ...
user avatar
0 votes
1 answer
15 views

How to create 3D polygon layer in QGIS 3 or convert 2D layer to 3D similar to PostGIS function ST_Force3d()

Right now I'm creating a polygon layer like this: self.poly = QgsVectorLayer("Polygon", "target_polygons", "memory") Is there something I need to do to make this 3D? ...
user avatar
  • 75
0 votes
1 answer
15 views

pyqgis 3 zoom to selected polygon without zooming in so far

My plugin has arrow button that I can use to click through the features of a layer and it will jump to that feature. For a Point layer this works great, the user can zoom to the amount they like and ...
user avatar
  • 75
2 votes
1 answer
49 views

Setting direction to clockwise using PyQGIS

I am looking for a way to change the direction of the pie charts of a layer from counter-clockwise to clockwise in QGIS 3. I looked in the docs but I don´t seem to find a way to do this. Does anybody ...
user avatar
3 votes
1 answer
38 views

QGIS layer styling, "symbology" - automate delete and reclassify

My QGIS projects always have around 20 layers that need to be Categorized by a certain value every day. Right now, I need to manually hit the "delete" and "classify" buttons. Fine ...
user avatar
1 vote
1 answer
26 views

Pyqgis 3 adding polygon vector layer in code and triggering iface.actionAddFeature().trigger() will give me polygons but they cannot be selected

Code to add polygon layer when a button is pressed in my plugin: # Add polygon layer self.poly_layer = QgsVectorLayer("Polygon", "target_polygons", "memory&...
user avatar
  • 75
3 votes
1 answer
27 views

triggering add feature action in polygon layer using pyqgis in my plugin, the polygons will not show up, although they are there

In Pyqgis after an "edit" button is pressed on my plugin, first I add google sat layer, then move it to the bottom, then I add a polygon layer and move it to the top, then I trigger editing ...
user avatar
  • 75
2 votes
0 answers
36 views

PyQGIS - QgsPalLayerSettings - Vector Labels Scale Visibility

I've created a script to automate loading layers from different sources. This includes dxf files that have a LineString layer and a Point Layer. For the dxf files I want to turn off the symbols for ...
user avatar
  • 21
0 votes
1 answer
25 views

GDAL cannot find file that exists? Running from QGIS processing script editor

I'm trying to create a script which takes an unkown number of equal size rasters and returns a single raster identifying the source (raster) of the maximum value for each pixel. GDAL is telling me it ...
user avatar
5 votes
2 answers
63 views

Difference between features in the same vector layer using PyQGIS

I have a vector layer containing 3 rows (see image2). Each row is a polygon. The blue polygon is number3 and the magenta polygon is number2 (see image1) I need to subtract the polygon that has the ...
user avatar
  • 53
4 votes
4 answers
176 views

Creating list from field values with PyQGIS

How is it possible to create a list from the values of a single field in a shp using PyQGIS? Example: field_capital_name London Paris Rome list1 = [London, Paris, Rome]
user avatar
  • 83
1 vote
2 answers
37 views

PyQGIS: Reload layer attribute table after editing the dataProvider

QGIS 3.24.0. I am adding a field to my attribute table using PyQGIS and populating the rows with a URL. The layer in question is a GeoPackage Point layer. The attribute is added to the dataProvider ...
user avatar
  • 7,251
2 votes
1 answer
43 views

QGIS addressing layer in field calculator in python script

I am trying to use the field calculator in a Python script. I use a formula to calculate shortest distance between two polygons (layer_A, layer_B). The formula for the field calculator works well when ...
user avatar
  • 1,211
0 votes
0 answers
43 views

How to populate QTableView/QTableWidget with attribute table of a layer using PyQIS?

I am developing a a plugin in QGIS. I want to add attribute table of a vector layer as data model in QTableView. I am using following lines of code but it is adding empty column. ...
user avatar
1 vote
1 answer
110 views

Workflow to convert Python script without UI file into QGIS Plugin

There is a 'startup.py' file with Python script (1200 rows) written by somebody. It works like a QGIS Plugin, see image below. What are the steps needed to convert this script into a proper QGIS ...
user avatar
  • 22.6k
3 votes
1 answer
80 views

How to create a polygon from a CSV file with coordinates using PyQGIS?

I like a write a script which: Imports a CSV file that contains a series of points (latitude and longitude) into QGIS Lat Long 56.99181358 -111.4801108 56.98924901 -111.4764563 56.98591437 -111....
user avatar
3 votes
1 answer
94 views

Creating points along the line on either side of an intersection point

I have a center line and an intersection point. I want to create points on either side of this intersection point along the center line with an interval 50 meters(can vary) starting from the ...
user avatar
-1 votes
1 answer
78 views

QGIS Process Modeler: Create Algorithm to update feature count in Layers Panel

I have a little Python script which I want to use, in order to update the feature counts of all layers in the Layers Panel by reloading them. I want to use this algorithm in the QGIS Graphical Process ...
user avatar
3 votes
1 answer
129 views

Display a progressBar and use the execution time of several functions in QGIS plugin

I developed a plugin under QGIS and I added a progressBar using QT Designer. Using a pushButton, I execute several functions directly in the __init__(self, iface) function. What I want to do is to ...
user avatar
  • 133
1 vote
0 answers
59 views

EPSG:3857 : find approximate distance between points with PyQGIS? [closed]

I'm trying to calculate the distance between 2 points with different methods, eg QgsDistanceArea(), trigonometry ((x2-x1)**2 + (y2-y1)**2)**(1/2) I always get the same result, nearly 150% of the real ...
user avatar
  • 319
0 votes
1 answer
42 views

How do I get raster rendering labels in legend from Python console in QGIS?

I have some code that searches a set of .tif files to find the overall min and max values so I can apply a consistent color ramp to all the files. This code works well, except that no labels show for ...
user avatar
  • 175
2 votes
1 answer
67 views

How do I set the print layout page size in Python console in QGIS?

I would like to set the page size of my print layout in QGIS through the python console. You can see what I tried in the # SET PAGE SIZE HERE section at the end of the code. I either get an error or ...
user avatar
  • 175
0 votes
1 answer
50 views

How to make backgrounds white for QgsLayoutItems in QGIS Python console?

I would like the background of my label and scale bar items to be white rather than transparent. I am using Python in QGIS. My code is below. See the # Add Scalebar and # Add Title sections towards ...
user avatar
  • 175
0 votes
0 answers
29 views

pyqgis - removing item node from legend in composer [duplicate]

I have a layer with a categorized symbology by field. I need to add a legend of it into composer and remove some nodes ('malls' as an example). It can be done manually like this: And I need to ...
user avatar
1 vote
1 answer
41 views

GDAL dissolve algorithm give error on input layer geometry column

I'm trying to use GDAL dissolve algorithm, like the following code: # Dissolve alg_params = { 'COMPUTE_AREA': True, 'COMPUTE_STATISTICS': False, 'COUNT_FEATURES': True, '...
user avatar
  • 141
3 votes
0 answers
103 views

PyQGIS: QgsRasterFileWriter generates blank (all zeros) raster when used in standalone script

QGIS version: 3.16.15 Python version: 3.9 I am trying to export some raster from a WMS-sourced background raster layer. For doing so, I am delimiting the export area to be exported by using a vector ...
user avatar
0 votes
0 answers
15 views

Is Qgis2threejs package available for use in standalone applications?

I am creating a standalone application in pyqgis. I want to use the 3D Raster data (DEM) visualisation functions/packages of QGIS. How do I go about it? Is Qgis2threejs available for use in standalone ...
user avatar
3 votes
1 answer
99 views

Drawing virtual dotted line using PyQGIS

I am developing a plugin in QGIS 3.14 to customize editing. I am drawing a line by clicking on map canvas. It is showing points with mouse click and creating a line with right click. I want to trace ...
user avatar
2 votes
1 answer
89 views

PyQGIS: Aggregate function used with field calculator

I'm using the following code with processing algorithm "Aggregate" to find neighbor polygons of some selected features in a polygon layer: from qgis.core import QgsProcessing from qgis.core ...
user avatar
  • 141
2 votes
1 answer
85 views

QGIS 3 - Identify tool - programmatically accessing "Derived" info in Identify Results

Is it possible to access this info programmatically? I know that the attributes portion of the identify results can be accessed, yet I can't seem to find examples pertaining to the "Derived"...
user avatar
2 votes
1 answer
75 views

Filter layer by FID with PyQGIS

I would like to duplicate a layer and apply a filter on the new layer that contains only selected features. Requirements are: using a memory layer is not an option, I want to keep the original ...
user avatar
  • 879
0 votes
1 answer
36 views

In a QGIS plugin, how to let user click on canvas multiple times and store coordinates of all the points in a single list?

I am trying to get a list of coordinates for 3 different points in a single list. I am able to make a list of coordinates of a single point and then it overwrites the previous one while clicking to ...
user avatar
2 votes
0 answers
68 views

Run PyTorch within QGIS Plugin using PyQGIS

I would like to run my object detection module (programmed in PyTorch) in a QGIS plugin. Currently, I have implemented all the required functionality in the QGIS plugin (getting the image, selecting a ...
user avatar
  • 53
1 vote
1 answer
71 views

Adding new provider to QgsProviderRegistry.instance().providerList() using PyQGIS

I'm trying to get vector layer from arcgisfeatureserver in a standalone app, didn't work, so I checked what providers I got on PyCharm: ['gdal', 'memory', 'mesh_memory', 'ogr', 'vectortile'] While in ...
user avatar
  • 133
2 votes
1 answer
330 views

Looking for manual on how to properly setup standalone PyQGIS without GUI

My goal is to create a standalone PyQGIS script that is able to run QgsProcessingAlgorithm scripts without GUI. My setup runs on Windows and my IDE of choice is VS Code. I've followed the Windows ...
user avatar
  • 425
0 votes
0 answers
110 views

How can I improve the following PyQGIS code used in QGIS Actions to display files containing images or PDFs?

Working environment: Windows 10 and QGIS 3.10.14 LTR (standalone old repository) Problem: in a shapefile with points, representing signs, the column "Code" of the attributes contains the ...
user avatar
1 vote
1 answer
58 views

QGIS join by location not working between two shape files

I am getting this weird error while using join attributes by location in QGIS, I have two layers - Source & Target. I am joining by target to source features using intersect option in join ...
user avatar
0 votes
0 answers
32 views

Calculating polygon areas using Field Calculator in PyQGIS [duplicate]

I am trying to calculate areas for polygons in QGIS 3.16.10 using PyQGIS 3 as you would with the Field Calculator. I am trying to use QgsExpression to create the necessary expression. However, the API ...
user avatar
0 votes
1 answer
87 views

Return QGIS processing algorithm's results after edition

I want to create a simple qgis processing algorithm, where input layer is copied, there are some basic operations done on attributes and the resulting layer is returned. However, I encounter following ...
user avatar
  • 484
6 votes
1 answer
89 views

Iterating over features of a same layer

I have thousands of polygons in a layer. I am using following code to delete one of two intersecting polygons from a layer by checking geometry intersection of each polygon with all others. But it ...
user avatar
1 vote
0 answers
55 views

How to perform intersect or overlay_within functions using Python/PyQGIS to circumvent graphical modeler limitations? [closed]

This relates to Creating field with 1/0 values depending if point sits inside polygon in QGIS for which people provided excellent answers but unfortunately highlighted a current limitation of the ...
user avatar
2 votes
1 answer
66 views

Get the current QgsFeature while rendering an Atlas

I'm building an Atlas generator based on the QGIS Layout engine. I want to fetch extra data from database based on some attributes of the current feature. In PyQGIS 2, that was possible with for i in ...
user avatar
  • 2,692
0 votes
1 answer
132 views

How do I add COGs from AWS S3 protocol to QGIS map canvas programmatically

I have a private bucket in S3 with COGs in it. Following the instructions here, it's actually very simple to do it manually. However, this does indeed only work manually. Trying to add a COG with the ...
user avatar
  • 8,162
3 votes
1 answer
82 views

Getting point geometry by clicking at the map within QGIS plugin

From QGIS 3 Plugin Tutorial I need the example for getting a point geometry from clicking at the map. So I have a file point_tool.py: from qgis.gui import QgsMapTool, QgsMapToolEmitPoint from PyQt5....
user avatar
  • 1,186
0 votes
2 answers
62 views

Automatically install third party Python library to QGIS while first install of custom plugin (Windows)

I've developed a QGIS plugin that needs to have installed external libraries to work. While I was working I've installed those libraries with pip command via osgeo4W shell but I don't want to each one ...
user avatar
  • 17
2 votes
2 answers
241 views

PyQGIS 3: Cannot Pass Memory OUTPUT To Next Processing Algorithm As INPUT

I am attempting to convert some ArcGIS arcpy command-line scripts to PyQGIS and am running into a problem working with memory layers. The script takes several vector files as input and progresses ...
user avatar
  • 31
0 votes
1 answer
69 views

Changing the value of geometry using changeGeometryValues in SpatiaLite layer

I am trying to update a geometry using changeGeometryValues, it works fine when the layer is of type shp or geopakage, but when I use it in SpatialLite layer it gives me the following error. This is ...
user avatar
3 votes
1 answer
165 views

How to extract "derived" attribute values in QGIS (using PyQGIS) into the attribute table?

I know how to extract the geometry data, but I am struggling with the following derived attribute data in QGIS: Searched a lot for extracting derived data, but only geometry data comes up. Result: I ...
user avatar
  • 1,135

1
2 3 4 5
15