Questions tagged [pyqgis]

Python bindings for QGIS.

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

Using PyQGIS functions outside QGIS

I want to use PyQGIS function crs.isValid() in normal Python file outside of QGIS like this: wkt = 'GEOGCS["WGS84", DATUM["WGS84", SPHEROID["WGS84", 6378137.0, 298....
2
votes
1answer
37 views

Merge features before creating new shapefile in PyQGIS

I'm working with QGIS 3.10 A Coruña on MacOS 10.13 environment. I've got the following code (provided by @Kadir Şahbaz in this thread) to create new shapefiles from a loop selection of features for ...
4
votes
4answers
243 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 ...
3
votes
0answers
28 views

Is it safe to access layer object(e.g. QgsVectorLayer) in background task(QgsTask) in QGIS3

I was confused if it's safe for developers to access QgsVectorLayer in a background task(QgsTask), like reading data from layers? Because descriptions in PyQGIS cookbook are different with different ...
0
votes
1answer
38 views

QGIS: How to modify the selection style when selecting features in a standalone script

It's quite easy to modify the default style that QGIS applies when selecting attributes in the GUI by following the steps in this question: QGIS: How to modify the appearence of selected attributes ...
1
vote
1answer
26 views

QGIS Python Sum of rasters

I would like to make the sum of 12 input rasters in order to have one output raster, the sum. I run this code, that works, but the output raster has all the cells with invalid data (1.79769e+308). If ...
0
votes
1answer
36 views

Getting metadata information via PyQGIS [closed]

How can I get QGIS project metadata information via PyQGIS? QGIS version: 3.16.
2
votes
1answer
52 views

Setting project and layer CRS in PyQGIS with setCrs() has no effect on the map canvas

I'm using the following code to set the project CRS in a Python script: #creates the project and projectRoot objects projectObj = QgsProject.instance() projectRoot = projectObj.layerTreeRoot() #sets ...
2
votes
1answer
29 views

QGIS Python raster calculator

I would like to run this code that makes calculation at every loop between different input rasters and Itot that is a raster that in the loop remains always the same. The code doesn't give me any ...
0
votes
1answer
58 views

Sum of multiple rasters in QGIS Python

I would like to make the sum of 12 different rasters to get one raster as output. I wrote the following code but it doesn't work (or better, it works, but at the end it doesn't give me any layer, but ...
1
vote
0answers
47 views

QGIS Python script with raster calculations

I have a problem with this code, that works, because it gives me the output rasters that I want, but the problem is that these outputs show wrong values because they are all 1.79769e+308. I think the ...
3
votes
0answers
36 views

Displaying an alert before closing QGIS

I would like to display a message before QGIS close. But I can't intercept the closeEvent of the main window from my plugin. I've tested this code which doesn't work. # Main method QgsApplication....
0
votes
1answer
16 views

Render the point shapefile and raster layer together as single image

I have a point layer as one shapefile and MrSid file as raster layer. How to overlap these two layers and clip the merged layer and render it as an output image file?
0
votes
0answers
26 views

Setting layer properties through PyQGIS [closed]

I have to config several project files with many layers in each one, many of those layers have similar fields which should have the same forms configs. Is there a way to config forms attributes to ...
0
votes
1answer
38 views

Importing Python packages in PyQGIS?

I am struggling to import Python packages, such as fuzzywuzzy or pandas, into PyQGIS. Whenever I try to import, through import pandas for example, I get ModuleNotFoundError.
7
votes
1answer
109 views

How to create a geometry generator symbol using PyQGIS

I am trying to use PyQGIS to convert a Fill Symbol Layer into a geometry generator Symbol Layer in a rule-based renderer with 300 rules. I am able to iterate over the rules and return each rule's ...
4
votes
2answers
53 views

Save x,y,z values to a GeoJSON file from QGIS

I would like to save x,y,z values for polygon vertices as a geoJSON file using Python in QGIS. I've made several attempts, but all have issues. I've found that the QgsPoint object must be used as ...
2
votes
0answers
47 views

Stopping script processing without shutting down QGIS [duplicate]

I'm looking for a way to abort a script execution if a sql query returns some results. I've found a few solutions on the forum but all of them lead to shutting down QGIS (thing I precisely want to ...
1
vote
0answers
28 views

How to prevent commit to a vector layer during editin session in PyQGIS

I am writing a plugin that listens to editing events, such as the QgsVectorLayer.editingStarted, QgsVectorLayer.geometryChanged signals. So far all is fine but there are also some validation rules ...
5
votes
3answers
184 views

Adding scripts to Processing toolbox via PyQGIS

Is there a way for adding new Processing scripts into Processing toolbox using PyQGIS? In the GUI, I can click on "Add script to toolbox", but I want to add scripts using PyQGIS. QGIS ...
4
votes
1answer
43 views

Enabling “Show all labels for this layer (including colliding labels)” in PyQGIS

I am using PyQGIS 3.10. I am working on a project that will display about 30 cities and their forecast weather variables (temperatures, winds, etc.), and some of the labels are a bit close together ...
1
vote
2answers
97 views

Writing PyQGIS script with operations on multiple set of rasters

I would like to perform a loop that takes from a given folder a set of rasters and for every raster makes the following operation, that in the specific case is the calculation of the monthly ...
7
votes
2answers
157 views

Getting unique values from multiple fields as matched using PyQGIS

There are Code and Color fields in my layer like this: (Sample 6 rows) Code Color ---- ----- A Red B Blue A Red A Red B Blue C Green ... ... All As are Red, all Bs are ...
0
votes
1answer
31 views

Apply transparency on a WFS layer (PyQGIS)

I'm trying to make a wfs layer transparent, but it gives me a mistake, but I can't solve it until now. This is my code: uri ='http://gstore.unm.edu/apps/rgis/datasets/6ca5428a-a78c-4c82-8120-...
4
votes
1answer
43 views

Creating custom categorized symbology and coloring based on two fieldNames

I am developing a plugin in PyQGIS 3. Within this plugin, I want to change the symbology of a layer to categorized. I want to categorize based on the column Collecti_2 in PyQGIS 3. This step has been ...
6
votes
2answers
106 views

Warning displayed even though the file is detected in QgsMessageBar

I try to display a warning message when a file is not found in a folder but I don't understand why the warning message appears even if the layer is loaded. I used if then else but it is not working. ...
4
votes
0answers
52 views

Catching and canceling event when I press button using PyQGIS

I develop a script. When I select a feature from layer and press delete selected, I want to execute my function that checks something for this feature, and if the checker function returns False, it ...
1
vote
1answer
53 views

Accessing and using the QuickMapServices Plugin externally (outside of QGIS)

I would like to add a OSM Standard Basemap to my project through a python script running in PyCharm, outside of QGIS. Within QGIS, I use QuickMapServices and add an OSM Standard Map but I can not seem ...
0
votes
0answers
26 views

Query astropy or skyfield to get planets positions into a QGIS layer

I want to have a layer in QGIS where I give a date/time input and it will query astropy to get the sun, moon and planets position at that specific moment. https://docs.astropy.org/en/stable/...
6
votes
1answer
88 views

Creating grid with PyQGIS

I cannot create correct grids with PyQGIS. When I create grid with PyQGIS, the grid shape is not correct, i.e. rotated grid. But it's correct when I create it with QGIS > Vector > Research Tools ...
5
votes
1answer
63 views

Implementing French language in PyQGIS Plugin

I build a plugin with PyQGIS. If the user changes the language of QGIS interface then automatically my Plugin dialog and messages need to change that particular language (we just looking into French ...
4
votes
0answers
109 views

Accessing the spatial index of a layer (shapefile) with PyQGIS

I built a manual index on a shapefile, through the process "Create spatial index", which can be found in the process toolbox > general vector tools. This process creates a persistent ...
3
votes
2answers
162 views

Adding an XYZ tile using PyQGIS in PyCharm

I am trying to add a XYZ Open Street Map tile into my QGIS project, using PyQGIS. I am currently trying to use PyCharm to start with, to see if my script is running correctly. I have looked through ...
2
votes
1answer
47 views

Shortening line with PyQGIS

I tried to shorten a given LineGeometry with some Python code. layer = iface.activeLayer() fs = layer.selectedFeatures() for f in fs: fg = f.geometry() geomSingleType = QgsWkbTypes....
0
votes
2answers
68 views

Executing QGIS tools in Python from Linux Shell [duplicate]

I would like to execute a Python script which uses QGIS Processing tools. On Ubuntu 20.x I installed qgis, qgis-common, python3-qgis and python3-qgis-common. My objective is to execute the tool Exploe ...
5
votes
1answer
62 views

Adding page to layout after populating the page using PyQGIS

TL;DR How can I add items to the page (QgsLayoutItemPage) without using layout? I want to add an item to the 2nd (or 3rd, ...) page in the project layout. Normally, I can add the item to the 2nd page ...
-1
votes
1answer
34 views

Performing an operation on all values in certain fields as specified in a list, then overwrite those fields in their layer file using PyQGIS

I'm stumped here. I want to multiply all of the values by 100 in all of the CSV files I'm using in this project for all fields other than the join field. I don't need to create a new field. I simply ...
6
votes
2answers
69 views

Exporting layers to different sheets of an Excel file

I have two memory layers that I would like to write their attribute tables to the same Excel file but in different sheets. So far, I've managed to write the attribute tables to separate files using ...
3
votes
1answer
79 views

Working a PyQGIS Script in cmd, outside of the QGIS python console

I have a perfectly fine working script that runs within the QGIS Python Console and I would like to run the script outside of the software, preferably in cmd as a .bat, so then I can use task ...
1
vote
1answer
40 views

Showing only selected features of vector layer in PyQGIS [closed]

I am developing a Plugin in QGIS and I want to show only selected parts of a layer. How can I handle this with PyQGIS?
1
vote
1answer
27 views

Trying to perform table joins iteratively using Python in QGIS3

Back again with a similar issue, but this time with commented code! I'm trying to perform table joins iteratively for each field in each CSV I'm using for each of vector layers in the project. The ...
1
vote
1answer
26 views

Conducting operation to shift DEM tilted on Z axis using PyQGIS

I have two DEMs of a stream channel created with photogrammetry from different times. One of the DEMs used ground control points and is georeferenced correctly. The other model did not use ground ...
1
vote
1answer
68 views

Accessing Python dictionary by field value in QgsExpression

I'm writing a QGIS processing plugin. In this plugin, I use the processing algorithm pointsalonglines, and for the distance parameter, I'd like to use an expression which gives back the value of a ...
0
votes
0answers
39 views

MultiRing buffer plugin to Python script in QGIS

Is there a way to get the MultiRing buffer plugin into a Python script? I want to use it in the QGIS Modeler, but I cannot use plugins in there, or to get multiple buffers with varied (not equal) ...
5
votes
2answers
114 views

What's a provider in PyQGIS and how many types of providers exist?

What's a provider in PyQGIS and how many types of providers exist? I am really not sure what a provider does. There is an example below from PyQGIS cookbook where a provider is used to load a ...
3
votes
1answer
40 views

Drawing line from variable number of points stored in two lists

I have two Python list latitude and longitude which stores the coordinates, and I want to draw a single line from the list coordinates. I can draw the line if I know the number of latitude/longitude. #...
1
vote
1answer
26 views

Layer styling - raster symbology

I have two lists of raster (digital elevation model - DEM) layers by name. The first list of layers should be symbolized as follows: symbology should be set to hillshade layer rendering, blend mode ...
2
votes
0answers
28 views

Save edits using a form Python action

I'm trying to implement a couple of Python actions so that you can start editing an object and save the changes from the id form. I have had no problems adding the start edit action. However, saving ...
2
votes
0answers
38 views

Trying to save grouped CSV (and eventually SHP) layers in QGIS

So, I'm trying to automate the creation of layers in QGIS using Python the data in CSV files to drive symbology shading, layer naming and file naming. The part I'm really having trouble with is saving ...
5
votes
1answer
61 views

Cloning multiple layers within group using PyQGIS

I have a problem cloning more than one layer within a group. I am not proficient in PyQGIS by any stretch of the imagination. My task is to effectively duplicate all raster layers which names end with ...

1
2 3 4 5
113