Questions tagged [pyqgis]

Python bindings for QGIS.

Filter by
Sorted by
Tagged with
2
votes
1answer
30 views

Rendering a map with Python works inside QGIS, but not in standalone script

I have an existing QGIS project and I want to write a standalone Python script that outputs a png file of the map. I work on Windows 10. This is the code that I use (basically taken from the PyQGIS ...
0
votes
0answers
38 views

Least Cost Path: interpretation of results

I am using QGIS 3.10.2-A Coruña and its built-in Python Console. I am currently trying to compute least cost paths between combinations of 2 points given a road network layer. For this I am using ...
2
votes
1answer
45 views

Delete subselected features with PyQGIS and processing

In QGIS 3.10, I have layers in which I select features by location (to find duplicates), using : selected_features = processing.run('qgis:selectbylocation', {'INPUT':layer1, 'PREDICATE':0, 'INTERSECT'...
3
votes
0answers
38 views

Import a layer in MySQL using PyQGIS

I managed to import a layer from a MySQL database in QGIS with PyQGIS. Now I'm looking to import a layer from QGIS into MySQL. I explored several ways : Using ogr2ogr on the command line, the ...
2
votes
1answer
31 views

Project CRS Setting Invalid

Somehow, my attempt at setting the QGIS project coordinate reference system to a Sinusoidal projection by defining the CRS' EPSG ID returns "Invalid CRS!". I would be very grateful for any help with ...
2
votes
2answers
56 views

Using temporary output in a Raster Calculator algorithm

I'm doing some DTM processing, the first couple of stages are a slope calculation and then a Raster calculator process using QGIS's native raster calculator. I want to use the output layer from my ...
1
vote
0answers
30 views

QGIS Layout - Add image in attribute table

I am creating a layout of map using QGIS 3.10 I want to show attribute table with each point logo in table. I have a field which has the complete path to each logo and this field is already being used ...
7
votes
1answer
98 views

Load QGIS project from database using PyQGIS

I am trying to open a QGIS project that is saved to the database (Project -> Save to -> PostgreSQL) by means of Python script. I find a similar way to open project which is saved to the desktop ...
1
vote
1answer
28 views

Saving each feature symbology to a image using PyQGIS

I am attempting to write a plugin to export a LayerVector (Points) to images. I need to get the symbology of each point to export as images (PNG). My intention here is to create a new file containing ...
2
votes
2answers
59 views

Impeding PyQGIS saving changes to file on disk immediately

I am using QGIS 3.10.2-A Coruña and its Python Console. Currently I am modifying features and attributes of a shape file, e.g. dropping features: caps = layer.dataProvider().capabilities() if caps &...
1
vote
1answer
45 views

Getting all web services and database connections from QGIS in PyQGIS?

I need to write a plugin for QGIS but I am not very familiar with QGIS itself and kind of new to all of this. I want to get all connections programmatically. By connections I mean everything from WMS ...
0
votes
1answer
27 views

Create OAuth2 Authentication in pyqgis

I want to complete a code that should create same OAuth2 authentication on many other computers but with different usernames. I already tested creating basic authentication and it works fine. am = ...
0
votes
0answers
62 views

TypeError: 'tuple' object is not callable (QGIS 3)

I'm getting this error when trying to run the following code: line = iface.activeLayer() a = processing.run("qgis:fieldcalculator", {'INPUT':line,'FIELD_NAME':'len','FIELD_TYPE':1,'FIELD_LENGTH':10,'...
2
votes
1answer
53 views

Automatic “Extract by Expression” processing with PyQGIS

Refering to this post and particulary the etrimaille's comment, I want to clean my dataset created from OSM data in QGIS. In each layer, I want to extract the entities having a specific key and value, ...
2
votes
1answer
53 views

QGIS: loaded .shp file not displayed

I am using QGIS 3.10.2-A Coruña and PyQGIS via the internal Python Console (Plugins -> Python Console). Currently I am trying to import a shape file using the following command: vlayer = ...
1
vote
1answer
47 views

How to calculate field based on another fields [closed]

I´m trying to calculate field based on another fields. I´ve got this attribute table. Example: If field "Smisenost" is S than FRST in new field. Example 2: If field "Smisenost" is NULL, if field "...
1
vote
0answers
16 views

Download layer in a specific group from Overpass with PyQgis (via Quick OSM)

I'm writing a plugin for Qgis in python (pyqgis) to download OSM layers and apply some process to them. I use the Quick OSM plugin's code for the downloading part. I just call the "run_query(key,value)...
1
vote
0answers
43 views

Merge all separated lines with connecting extremities into single continuous lines

I got a DWG file from a friend that contains the curve lines of an area. However, once I import the file and then convert it to shapefile, all the lines are split. I would like to connect all the ...
0
votes
0answers
51 views

Importing QGIS 3.10 python module from system Python

I have QGIS 3.10 installed on my Windows 10 system and I want to import the qgis module from my system Python installation. I used this description on the QGIS homepage to set my system up. My ...
1
vote
0answers
38 views

Filter QgsAttributeTableModel without geometry

Is it possible to filter a QgsAttributeTableModel without geometries. I was not able to filter a QgsAttributeTableModel without geometries, so I added a fake geometry column to my table ("geom_fake"). ...
1
vote
0answers
40 views

Setup PyCharm to develop Python scripts for QGIS?

I want to set up for the first time an environment with PyCharm to write scripts for QGIS on my Ubuntu desktop and I'm completely lost. I'm not having problems with the console on QGIS, but I couldn'...
4
votes
0answers
38 views

PyQGIS: What objects need to be destroyed in a custom expression

I'm using a custom (PyQGIS) function in expressions to make little detailed minimaps around each feature in a layer, and store it in the layer (gpkg) as a png. My code works but makes QGIS (3.12) ...
4
votes
0answers
41 views

QGIS processing tools - saving/exporting graph

I just tried QGIS processing tools for the first time. When using shortest path search for the first time, the algorithm is building a path graph (of course). However, the graph is never re-used. ...
4
votes
2answers
95 views

Using Plugin in standalone PyQGIS script

Typically, when I want to use a QGIS processing tool for my PyQGIS standalone script I write something like: processing.run('buffer:...'{…}) Now, I would like to use the functionality of the QGIS ...
2
votes
1answer
49 views

Default Value for Field with Python Expression in Function Editor

I have a line shapefile in QGIS with several columns and the values for many of those columns could be automatically calculated and updated depending on certain other fiels. Now, I came across the ...
4
votes
2answers
172 views

Get only fields with datatype int in PyQGIS

With the following line of code, I get a list of field names for the layer layer. fields = layer.fields().names() However, I would like to get only those fields with the datatype Integer. How ...
1
vote
0answers
50 views

Drawing Line Starting/Ending at Pre-Existing Points in QGIS

I am trying to create a editing condition with a error message. The condition is while drawing a new line feature, line should start and end at pre-existing point feature. If user try to start or end ...
5
votes
2answers
80 views

Qt Designer forms and QGIS [closed]

How can you link a qtdesigner form from the QGIS itself, and to call a code made from the console?
0
votes
1answer
58 views

Saving 'OUTPUT': from processing toolbox to a file path with unique file name [closed]

I'm using the QGIS Toolbox and Python Console to write a script for parsing data. I want to do something like this: output_path = open('C:/Users/EH/Desktop/PYQGIS_Model_Output') # Set location to ...
3
votes
0answers
84 views

import qgis.core in Python

I am trying to use QGIS3.4 by using Emacs (elpy) on Mac OS Mojava. I checked following sources: https://docs.qgis.org/3.4/pdf/en/QGIS-3.4-PyQGISDeveloperCookbook-en.pdf http://osgeo-org.1560.x6....
4
votes
1answer
106 views

Adding constrain/check after adding first point of line and after last point of line

I want to customize the QGIS editing tool in the following way. Scenario: The first and last point of the line layer must have a point layer. Steps: User selects a line layer. User starts/toggles ...
2
votes
1answer
37 views

Define HTML Map Tip using PyQGIS

using PyQGIS, I need to create a map tip using this HTML code: ID = [% ID %] and style it like the picture below (white text and black background). I don't know how to use CSS in this case. If is ...
2
votes
1answer
140 views

PyQGIS: QgsVectorFileWriter.create() doesn't flush even after deleted

If QgsVectorFileWriter constructor is directly used, the output is flushed when the reference is deleted. I'm trying to switch to QgsVectorFileWriter.create() because QGIS warns that the former is ...
3
votes
1answer
65 views

Importing all layers open in QGIS to PostGIS

I'm looking for write a PyQGIS code to import all layers open in QGIS to PostGIS. import os #Code from https://gis.stackexchange.com/questions/26257/iterating-over-map-layers-in-qgis-python layers = ...
2
votes
1answer
62 views

QGIS plugin closing all open PyQt dialogs

In my QGIS3 plugin I need to close all open PyQt5 dialogs. The structure of my plugin is like the following code. To be clear, when I call runCloseDialogs() I want to close both dialogs opened by run()...
1
vote
1answer
45 views

Raster layer to GeoTIFF QGIS Python

Is there a way to export a layer in GeoTIFF format from Python? I am able to perform georeference with Python and show the results on the canvas. However, when I am inserting the .tif file in any ...
3
votes
1answer
52 views

Loading a symbol from db (symbology-style.db)

I'm working on a Qgis python module. I would like to apply a symbol on a layer by his name entry from the symbology database. I know that some defaults symbols are saved into a sqlite db (symbology-...
2
votes
1answer
45 views

QgsIDWInterpolator crashes QGIS

After unsuccessfully trying to use processing.run('qgis:idwinterpolation', ...) using a layer object in memory as the source (seems to like full file paths to physically stored datasets), I tried to ...
1
vote
1answer
35 views

What is a correct input format for using qgis.processing.run(“gdal:buildvirtualraster”) in a python script for QGIS 3.10?

struggling by creating a virtual raster using a python script in QGIS. Currently I have a script as follow: rasters = [r'Z:\Rasters\raster1.tif', r'Z:\Rasters\raster2.tif'] outfile = r'Z:\Rasters\...
2
votes
0answers
44 views

Automatic folder selection for processing algorithms in graphical modeller

Background I have 19 layers which ALWAYS have the same file name, but are located in varying folders. These layers are all inputs to several big models. Now, instead of defining each algorithm input ...
5
votes
1answer
58 views

Change point symbol to an existing single marker symbol in PyQGIS

I have a code that takes a polygon layers and returns a temp point layer, I want to change the symbology for the point layer to the "topo pop capital" point symbol through Python. fn = "C:/Users/...
5
votes
1answer
89 views

Calculate centroids in memory from polygon using PyQGIS

I need to calculate Centroids from polygon layer without reading and writing shapefiles. I tried this code in python console (QGIS 3): layer = iface.activeLayer() params = {'INPUT': ...
1
vote
1answer
29 views

Conversion of array to tif_Expected array of dim 2

I'm trying to perform a simple operation on an image, which is applying a median filter to it (for now). I'm trying to do it with QGIS and the console Python. My code is : import numpy as np from ...
1
vote
1answer
60 views

Convert QGIS geometry into Shapely geometry to use orient method defined in Shapely

My idea is to fix the orientation of a polygon, so no matter the orientation it was created, when I run the code, the polygon become clockwise. How is it possible? I searched and found the shapely ...
2
votes
0answers
29 views

File locked after removing the layer , in Python code for a plugin for QGIS

I try to remove the layer, to re-generate it with the same name, but when the plug is started the layer is loaded, removeMapLayer does not unlock the file, and it is locked. I have seen several ...
1
vote
1answer
31 views

Median filter_invalid syntax

I would like to apply a median filter to an image (.tif). I looked for solutions in QGIS, and found a lot of possibilities to apply a mean filter, but none for a median filter. So I decided to try ...
1
vote
0answers
34 views

Calling outside function file in PyQGIS

I am making a plugin that calls a customised library which contains a list of functions. I, first saved this library outside the plugins folder, then inside it to see if it changes something. The ...
0
votes
0answers
24 views

Unload QGSVectorLayer from Python script

I have a Python script that processes several country sized OpenStreetMap PBF files at a time. The problem I'm having is that: each time I open and process one of these files, I lose anywhere from ...
2
votes
0answers
64 views

Open Feature form in multi edit mode using PyQGIS?

Is there a way to use PyQGIS to open the Feature form in the multi-edit mode for the active layer selected features? It's the "standalone" version of the one existing for the attribute table. https:/...
3
votes
0answers
10k views

Hiding a layer in Layers panel, but showing in Map Canvas

When a layer is added to QGIS, it is ordinarily added to "Layers" panel and "Map Canvas". The same thing happens when a memory layer (loaded/created by QgsVectorLayer) is added using QgsProject....