Questions tagged [pyqgis]

Python bindings for QGIS.

Filter by
Sorted by
Tagged with
2
votes
0answers
109 views

Batch Raster Georeferencing GDAL plugin in PyQGIS

I use to manually georeferencing rasters using the plugin GDAL using: raster .tif 4 gcps in a file .point and it results this : My aim is to batch this method for thousand of rasters (drone ...
3
votes
1answer
131 views

Making custom widget visible as layout element for printing in QGIS with PyQGIS

I need to make a widget visible as a layout element for printing, for a QGIS plugin I am developing. Which of the classes do I need to extend to do this? After some research I think I begin to discern ...
2
votes
0answers
27 views

Debugging QGIS plugin using pdb

I typically use pdb for debugging. However, when I follow the docs for debugging with pdb, I get the error: input(): lost sys.stdin I'm developing my plugin straight out of the load directory: %...
2
votes
1answer
85 views

Automating QGIS layout export by looping on project layers

I've a QGIS project with several vector layers that I need to be represented in a layout I've prepared one by one. I can manually make visible and select one layer at a time, so that the layout after ...
3
votes
1answer
79 views

QGIS iterative rasterize naming

I am working on a PyQGIS script that gives similar behaviour to the GeoCube package. Specifically, I want to create a bunch of rasters from vector data for a selection of fields. For example, if I ...
4
votes
3answers
187 views

Splitting string with dates by '/'-character and getting ancient/latest date as new column in QGIS

I have dates separated by '/' character in column "date" in format RRMMDD as on the screenshot below: I want to separate dates into another columns "date_from", "date_to"...
2
votes
1answer
78 views

After creating layer by means of PyQGIS it does not show up on the map

I made a script in PyQGIS to create a layer but the layer does not show up on the map. Can someone help me? from qgis.PyQt.QtCore import QVariant vl = QgsVectorLayer("Point", "...
2
votes
1answer
91 views

Accessing and interacting with widget of form annotation using PyQGIS

I am working on a plugin to display and interact with graphics, which are visible in the view and layout. Form annotations are a great alternative for this. The form annotations (QgsFormAnnotation) ...
7
votes
1answer
106 views

Starting QGIS Desktop with Python script

I looked at the QGIS official documentation (e.g., Using PyQGIS in custom applications) and a few questions here (e.g. Running QGIS through Python), but I was unable to find an example of a Python ...
7
votes
1answer
82 views

Layer not repainting using PyQGIS

I'm trying to change the color ramp for a raster layer using PyQGIS. What I have works, but the layer doesn't redraw. However, if I open the layer properties and click "Apply", the map ...
2
votes
1answer
28 views

Sum of raster file in QGIS using Python Console

I have 8760 raster file for the precipitation in the netherlands on hourly base, from the first day of the year (01.01.2020) till the last hour of the year (31.12.20). What I have to do with these ...
3
votes
1answer
48 views

Creating different numbers of random points inside polygons using PyQGIS

I am developing a plugin using PyQGIS and PyQt5. I am calling qgis:randompointsinsidepolygons, where I am trying to give field input at VALUE parameter. It will take a variable number of points for ...
4
votes
1answer
97 views

Measuring loading time of each layer when opening a QGIS project

I often find myself working with QGIS projects that load too many layers. I'm talking about a mix of raster and vector layers, some with small file size, some very large file size. Most of them are ...
1
vote
0answers
44 views

Importing and updating raster table in GeoPackage using gdal-translate

Based on answered script from a previous question I continued studying GeoPackage documentation but I didn't found a solution to overwrite the table in GeoPackage when the original file (in '...
1
vote
1answer
50 views

PyQGIS: Prompt ogr2ogr error in the log window of the processing tool

I have a processing tool that helps users to export data from PostGIS tables to GPKG. I am using ogr2ogr commands to achieve the tasks. I am calling the commands via subprocess. However, I cannot ...
2
votes
1answer
101 views

QGIS crashing on custom processing plugin

I am pretty new to Python and QGIS but I am trying to create an algorithm for a processing plugin that will import a CSV of Tweet IDs. It then hydrates them using the Twarc Python library to get a CSV ...
3
votes
0answers
49 views

QGIS symbology to SLD for web map

I use OpenLayers together with QGIS Server to deploy GIS projects as WMS service online and everything works fine using it together with MapProxy for seeding and caching layers. Now I want to ...
1
vote
0answers
131 views

PyCharm with pytest run configuration fail importerror PyQt5 with pipenv

I have difficulties setting up PyCharm to run my tests correctly while using a pipenv interpreter if i run my tests through a terminal with pipenv run pytest it works perfectly because it loads the ....
0
votes
1answer
58 views

Use QGIS Python API to modify feature attributes

In the QGIS User interface, it is possible to view the Attribute Table for all the features of a Vector Layer. Is there a way to directly read and write the Attribute Table in the Python API? I ...
4
votes
1answer
74 views

Using "layer.selectionChanged.connect()" to run another function every time new feature is selected in PyQGIS

I'm trying to use the layer.selectionChanged method in a plugin to run a little function every time a user select one or several new features on the active layer. The problem is that QGIS crashes ...
2
votes
1answer
42 views

Creating QGIS processing script parameter with multiple Rasters

I'm trying to create a QGIS script that would use multiple Raster layers as an input parameter. But QgsProcessingParameterRasterLayer only gives a single Raster as input and ...
2
votes
2answers
87 views

QVariant error when converting DataFrame into attribute table using PyQGIS

I have a df which looks like that: ID Happy 0 Very 1 Little I'm trying to convert it into an attribute table: headers = [col for col in df.columns] fieldlist = QgsFields() fieldlist.append(...
0
votes
1answer
59 views

Connecting PostgreSQL/PostGIS registry in qgis.core.QgsProviderRegistry

I'm developing a standalone QGIS based Python script for loading layers from/to PostgreSQL/PostGIS database. If I check the list using code: providers = QgsProviderRegistry.instance().providerList() ...
0
votes
0answers
44 views

Using the QGIS Python API to modify vector layer features

Starting from a QGIS project with many vector layers, I wish to load a file that extends the attribute table of one vector layer where a primary key matches. This is my first foray into QGIS and ...
2
votes
0answers
28 views

Using QgsNetworkContentFetcher to POST data

When programming a QGis plugin, I would like to POST a .json-file to a remote server; preferably using QgsNetworkContentFetcher to do this on the background while waiting for a response. However, I ...
1
vote
1answer
56 views

Writing SQL queries with PyQGIS [closed]

I never really paid much attention on how I was writing my SQL queries with PyQGIS since I didn't encounter any issues so far. However, I'm currently having difficulties building a SQL query based on ...
1
vote
0answers
44 views

How to use QGIS desktop Python code functionality in QGIS Cloud?

I have made QGIS map with different layers and upload my map on QGIS cloud. I have add some functionality like click function and drilldown functionality by Python code in QGIS Desktop. but these ...
5
votes
1answer
59 views

Propagating symbology changes made with PyQGIS to Layer Styling Panel

I am using a script to change the opacity on a rule-based symbology. layer = iface.activeLayer() opacity = 0.2 if layer.renderer().type() == 'RuleRenderer': renderer = layer.renderer() #...
3
votes
1answer
104 views

PyQGIS - Changing scalebar width from an existing layout

I have a project on QGIS 3.16 with several layouts. I would like to change the scalebar width according to the value of a Python variable, either a fixed sized of 1000 or 500 units (for instance). ...
4
votes
0answers
74 views

Loading layer from PostGIS with non-unique primary key

I'm trying to load (by mean of PyQGIS) a layer from PostGIS based on query involving a inner join with a non-spatial table. When I run the query in pgAdmin I get the desired output but when I ...
4
votes
1answer
115 views

QGIS Stand alone python script terminating problem

I want to write Python standalone QGIS script to layout export and my code is as follows: import os from qgis.core import ( QgsVectorLayer,QgsProject, QgsWkbTypes,QgsVectorLayerExporter,...
6
votes
1answer
165 views

Calculating line lengths of road network in PyQGIS

I have a road network 'TR_ROAD' with EPSG:4283 crs and 1200 features. I am trying to calculate length of each line segment in road by using "length" geometry in PyQGIS. When I tried below ...
4
votes
1answer
83 views

QGIS PDF export SVG display issues within container

I'm working on an automated PDF export from a QGIS layout. The export is scripted and works as expected on my development machine. However, in order to integrate with a CI pipeline I need the process ...
4
votes
1answer
133 views

Creating integer and string fields in attribute table

I am trying to create a new attribute field "FromNode" in a layer that contains string with an integer. EXAMPLE: name1, name2, name3, name4, ... till the end of the table. I got the ...
4
votes
1answer
75 views

Changing feature id's of a layer using PyQGIS

How can I change the feature id's of a layer using PyQGIS to an attribute value of that feature, where the attribute value is a unique integer? Is that possible at all, and if so, how? Things like: ...
2
votes
0answers
93 views

Setting legend subgroup to hidden using PyQGIS

I am trying to set the legend subgroup to hidden with PyQGIS. The context : self._project = QgsProject() layout = QgsPrintLayout(self._project.instance()) map_= QgsLayoutItemMap(layout) legend = ...
1
vote
1answer
64 views

Using coordinates from mouse click for QgsPointXY when creating point using PyQGIS

I can not figure out how to input the coordinates through a mouse click instead of the code below. I am trying to create a temporary layer of a point from a mouse click. Everything seems to work ...
0
votes
0answers
23 views

Retrieve database path for using processing.run(INPUT: ...) inside the QGIS python console

I am creating a Python script inside the QGIS Python console for the automation of creating a buffer, clipping over multiple layers, and fixing geometries. The layers are in the PostgreSQL database. ...
0
votes
0answers
52 views

To Plot a multiple TIF file and save a map in JPG format

Hi I am a beginner in python and I try to plot a multiple tif into a map as image file. I get the file and list the all files from the directory. And also create a function to create map as image I ...
0
votes
0answers
22 views

How to get estimated height for any UK coordinates based on OS Terrain 50 contour data

The OS nicely provide full terrain vector contour data for the UK in their Open data OS terrain 50. I can view this nicely in QGIS using the stylesheets here. But what I'd really like is a python API ...
3
votes
1answer
83 views

Read WFS layers with PyQGIS

I need to read published WFS layers from QGIS Project file, but without success. I try using QgsProject.entryList() method, but only get an empty list as []: from qgis.core import * from PyQt5.QtCore ...
4
votes
1answer
98 views

Run QGIS Processing Algorithms on Multiple Input Files Using a Standalone Script

I'm new to QGIS(3.20.2), and have even less experience with python. I've been working on automating a simple task and have been having difficulty tying together the pieces of information that I've ...
3
votes
1answer
59 views

Converting multiple MapInfo tab files to shapefiles using PyQGIS and GDAL

I am trying to put together a script to convert multiple (>50) Tab files into shapefiles. I am planning on executing this through the python console in QGIS 3.8.1 When I run the below code all I ...
1
vote
0answers
40 views

QGIS 3.16 version cannot open python console in PyCharm development environment for standalone application

We developed a few standalone PyQGIS application using QGIS's libraries that come with QGIS installed program. A bit more information about our application setup. We develop using PyCharm on Windows ...
1
vote
0answers
50 views

QgsProcessingException when running standalone script

My task is to run QGIS in standalone script. All the modules import correctly and I am running QGIS in conda environment. Error occurs when running the processing.run() command QgsProcessingException: ...
1
vote
1answer
86 views

Import qgis.core and tkinter in one application

I try to import modules:qgis.core and tkinter in one application, but I have a problem :ModuleNotFoundError: No module named '_tkinter'. I add to Path: C:\Program Files\QGIS 3.20.1\apps\Python39 and I ...
0
votes
0answers
26 views

Setting layer visibility in standalone QGIS Python script [duplicate]

I've been writing a standalone Python script that calls QGIS 3 libraries to draw stuff in a QWidget. I'm trying to change the visibility of layers based on a callback, but it doesn't seem to work. ...
3
votes
1answer
50 views

Modifying attributes with map selection using PyQGIS

I am trying to write a basic script or tool that will allow me to select a feature from the map, store those features initial attributes, then click additional features from the map and assign the ...
5
votes
2answers
142 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 ...
5
votes
3answers
167 views

What is algorithm name for "Count Points in Polygon" using PyQGIS?

I want to count points in polygon, using PyQGIS. When I check the documentation, I find the description of the {parameter_dictionary}, but not the algorithm name which must also be provided. What is ...

1
3 4
5
6 7
127