Questions tagged [pyqgis]

Python bindings for QGIS.

1,092 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
4
votes
1answer
295 views

Showing only selected features from a a layer in the QgsComposerLegend?

I have developed a custom qgis plugin. I have a button to export the map canvas in the form of image along with the legend. I came up with the following code for the legend: legend = ...
4
votes
0answers
217 views

Can you build a login window in QGIS?

Can you build a login window before loading QGIS interface? I use QGIS 2.8 I just built message windows when loading QGIS interface, but no more.
4
votes
0answers
79 views

QGIS plugin window qt creator formatting is ineffective

I am developing a QGIS plugin. I have assigned the QGIS main window as the parent window of custom plugin using: QtGui.QDialog.__init__(self, iface.mainWindow()) But after doing so the problem is ...
4
votes
0answers
247 views

How are costs returned by the pyQGIS implementation of Dijkstra calculated?

How are the costs returned by pyQGIS implementation of Dijkstra (QgsGraphAnalyzer.dijkstra) calculated? As far as I know, these costs correspond to the distance from the starting node to each of the ...
4
votes
0answers
5k views

How to import netcdf in qgis

I have been trying to impot netcdf files following this guide online http://www.ggiuliani.ch/download/netcdf_qgis_GG.pdf into qgis 2.10 with no success. ALthough the file is imported, the dimensions ...
4
votes
0answers
304 views

Is it possible to lock the layers using Qgis API Python?

I would need to load and "lock" two layers on the map. Locked means that layers cannot be removed from the layer registry. When I say removed I mean removed by the user using the QGIS interface (the ...
4
votes
0answers
107 views

Action: Move pointfeature to other layer - Point becomes Multipoint

I'm trying to write an action that moves a pointfeature from one layer to another. It works fine until i try to save the layer with the new feature on. He says he can't save a MULTIPOINT to a point-...
4
votes
0answers
970 views

Ubuntu 14.04 Another ImportError: No module named qgis.core

Issue I feel like this is covered territory here, but the issue is has appeared on two separate occasions for me--first when upgrading from Ubuntu 12.04 to 14.04 in May. I got it fixed then, but I ...
3
votes
0answers
32 views

Saving Processing result to GeoJSON string instead of QgsVectorLayer or GeoJSON file

I run processing.run("native:buffer") and from newly created vector I get all features and export them to string using QgsJsonExporter(). My problem is that newly created vector gives new IDs to all ...
3
votes
0answers
29 views

Applying graduated symbol renderer only on some features using PyQGIS

I have set up a graduate symbol renderer (QGIS cookbook - Graduated Symbol Renderer), and I am now trying to make it conditionally applied to some features only, depending on one (or more) attributes. ...
3
votes
1answer
45 views

Python script terminates after calling QgsProject.write()

Python script using QGIS package terminates suddenly when calling QgsProject.write. Idea is to create QGIS Project with select list of files and save it to disk, in automated manner. Script: from ...
3
votes
0answers
84 views

Azimuth calculations - PyQGIS

According to the QgsDistanceArea docs, an azimuth for computeSpheroidProject should be in radians, clockwise from North So, to build a new point with computeSpheroidProject i use math.radians(...
3
votes
0answers
61 views

Creation of conditional statement with Python fails

I want to calculate new values with the QGIS field calculator, while running the code in the calculator GUI from QGIS it works quite well, but trying to apply this via PyQGIS it just give me in ...
3
votes
0answers
38 views

Delete “children” feature, if “father” feature is deleted, inheritance

I am developing a dimensioning tool, and I would like that the "son" feature been deleted, when the father is deleteted, (on the fly). How can I do this? It can be done via application or PyQGIS. ...
3
votes
0answers
37 views

Using Spatialite to add features to a layer does nothing in custom plugin but works in QGIS python console

Context I am developing a QGIS plugin which among other things can save digitized features to existing vector layers in a Spatialite database. I am using the utility class below, to help with ...
3
votes
0answers
75 views

QGIS Plugin reload is incomplete

I am developing a QGIS Plugin in PyCharm. I use the QGIS Plugin "Plugin reloader" to reload the plugin when I want to test the plugin. But changes in the code are not applied on running the plugin ...
3
votes
0answers
69 views

Selecting and deselecting features with PyQGIS

I'm trying to apply the algorithms "Random Points along Lines" at the feature level. I did some PyQGIS code to iterate through the features to select each individual instance and apply the algorithm ...
3
votes
0answers
38 views

PyQGIS Layout - Change Image Source QGIS 3

Looking for a solution to loop through existing layouts in a QGIS 3.6 document and change a source of an image. The image is the same in each of the layouts. What I have is: from qgis.core import ...
3
votes
0answers
39 views

Manually giving input and output for QGIS graphical modeler exported python script

I am using QGIS 3. How could I manually give the input layer and the output path to the following script extracted from the graphical modeler? It is a simple model, it takes a DEM as input and ...
3
votes
0answers
35 views

Changing Map Tip popup direction dynamically

Is there a way to dynamically (or semi-automatic) change direction of a popup? Default direction is 'right-down', which in some cases, where hovered feature is at the bottom of a canvas, Map Tip is ...
3
votes
0answers
62 views

Testing nodes connectivity

I'm working on a shapefile of Brussels (QGIS 3). This shapefile contains all the streets in Brussels, see below. With the attribute table, I have an "X" and "Y" position for each line (debut and end),...
3
votes
0answers
113 views

Running Standalone PyQGIS Script with Multiprocessing?

Is it possible to run a standalone PyQGIS script using multiprocessing for better performance? I'm creating 1,800 rendered map images and would like to run it across 4 processes to speed it up. If I ...
3
votes
0answers
27 views

Preserving provider of original raster layer when it is modified for another resulting raster layer?

A while ago, I asked for a method to assign new QgsRasterBlock objects to a QgsRasterDataProvider objects at Assign new QgsRasterBlock object to a QgsRasterDataProvider object. The reason was for ...
3
votes
0answers
63 views

Setting input layers as PostGIS tables when building a model?

I am trying to build a QGIS 3.8 model where the same inputs are used each time and only the clipping layer extent changes. I can do this using shapefiles and editing the script to use the same input ...
3
votes
0answers
328 views

Using both QGIS and native processing algorithms in standalone Python script?

I am developing a Python standalone script to process DEM in order to produce slope in vector format. I used PyQt5 to make a GUI to accept input data and parameters from user. My script is like this: ...
3
votes
1answer
89 views

Saving raster layer to disk using Python: TIFF raster layer loses data type when saved with QgsRasterFileWriter

I'm trying to save a TIFF image stored as a raster layer. The image is fetched from a server so that its source (the url passed when creating the layer) is a HTTP url: the image should be saved to ...
3
votes
0answers
58 views

Lines length plugin - QgsVectorLayer error

Several similar questions have already been made, but none of the is helping me. I have a layer of polygons and I want to known the length of each line of each polygon. And based on the length I ...
3
votes
0answers
175 views

Pyqgis 3: Trying to Update Attribute with Value but Getting Index out of Bounds

I'm able to successfully add attributes with an expression to my vector layer using: #Add fields to get evaulated based on an expression vectorLayer.addExpressionField("'R'", QgsField("rtype",...
3
votes
0answers
103 views

How to refresh cached join layer using PyQGIS

I have exactly the same problem like Kory Roberts in his unanswered post on osgeo.org: http://osgeo-org.1560.x6.nabble.com/Help-with-cached-join-layer-refresh-using-PyQGIS-td5352190.html This is the ...
3
votes
0answers
135 views

GDAL processing output to memory in Pyqgis

How do I save GDAL processing output rasters to a temporary layer? Using 'memory:' for vector processes works fine, but I couldn't get it to work for GDAL processes. output_rast = self....
3
votes
0answers
460 views

Canceling task currently running in background using PyQGis?

I am trying to close QgsProject on loading layer (if password and username from QgSProject - datasource are incorrect) before QgsCredentialDialog is shown. on signal : QgsProject.instance()....
3
votes
0answers
125 views

Updating shared custom functions / expression code in QGIS

All the QGIS documentation I've seen on custom functions (used in expressions) says that the code is saved in the user's local expressions directory, e.g. ~/.local/share/QGIS/QGIS3/profiles/default/...
3
votes
0answers
106 views

QGIS parsing layer source

I periodically need to refresh my QGIS map based on changed underlying data sources (currently locally-saved KML, GPKG, but trying to be general) using PyQGIS. Following Make a Qgis layer update from ...
3
votes
0answers
169 views

QGisPlugin : Trigger closeEvent by clicking 'X' in QgsAttributeForm

This is the code: def formOpen(dialog, layer, feature): """Function called when a connec is identified in the map""" global feature_dialog # Create class to manage Feature Form interaction ...
3
votes
0answers
140 views

Unable to compute intersection between two polygons using PyQGIS?

I have two polygons in different layers. I am trying to find the intersect between the two polygons. Below a figure showing my test case. I initially wanted to find the intersect between the green ...
3
votes
0answers
29 views

We need to have a login occur before QGIS3 loads

Where is the hook for the invocation of the QGIS3 launch? I have looked at the pyqgis api and did not find a bootstrap class or anything similar.
3
votes
1answer
471 views

startup.py in QGIS not executed

I would like to use a startup.py which is part of a rollout and not located inside the users config-folder (like ~/.qgis2). Plugins located in the apps folder (e.g. C:\OSGeo4W64\apps\qgis-ltr\python) ...
3
votes
0answers
656 views

PyQGIS Layout export

I have some problems with PyQGIS while generating a layout. Here is a minimal (non-)working example in which I first load some layers with their styles. Then I would like to export them using a ...
3
votes
1answer
224 views

Activating snapping with PyQGIS?

I would like to construct a map tool application that allows only to add some point features. How do I complete the following code to activate snap mode while editing a layer with PyQGIS 3? from ...
3
votes
2answers
449 views

PyQGIS standalone script using QGIS 3.2

I want to work with PyQGIS Python 3 using QGIS 3.2 standalone install. I created a simple batch file to work with PyQGIS but I have some errors. Here's the batch file: @echo off SET OSGEO4W_ROOT=C:\...
3
votes
0answers
89 views

Standalone Application QgsCoordinateReferenceSystem fails without OSGeo environment

I am writing a simple standalone QGis application. My code is like this: class MainForm(QtGui.QMainWindow, Ui_MainWindow): def __init__(self): super(MainForm, self).__init__() ...
3
votes
0answers
176 views

Using true north bearing in label expression

In QGIS there is an option to rotate the north arrow as grid north or true north. For my case I need the true north angle. The rotation works just fine but now I also wanted to add the image rotation ...
3
votes
0answers
56 views

Use vector layer attributes as edge properties of a QgsGraphArc with PyQGIS

With PyQGIS 2.18 I created a QgsGraph as describe in the PyQGIS developer cookbook, Release 2.18, ch. 21.2, pp. 95-97. In the cookbook it says "Vector layer attributes and length of an edge can be ...
3
votes
0answers
324 views

GeoPandas causing issues with PyQGIS standalone

I have a code where I would like to be able to use both GeoPandas and PyQGIS. However, it seems that including GeoPandas is causing issues in the output of PyQGIS. Here is a small illustration using ...
3
votes
0answers
122 views

Reload attribute table does not work for attribute changed by dataProvider

In QGIS2.18, I'm changing feature attributes using the following two methods: dataProvider: attrs = { 0 : "hello", 1 : 123 } layer.dataProvider().changeAttributeValues({ fid : attrs }) layer object:...
3
votes
0answers
556 views

Import qgis.core to Python IDLE - No module named 'qgis'

I'm trying to import the qgis.core module as explained here: https://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/intro.html I'm working on a macOS system and installed python.org Python 3....
3
votes
0answers
66 views

How to split lines with defined split number by user in pyqgis?

Actually my question is on header. I want to split (or explode whatever you say) every line in my lineshape layer. For every line, I must define the split number and it should split them with equal ...
3
votes
0answers
115 views

Indexing Data in QGIS

Each time I open a my project, it starts to index and takes as long as up to 4 hours at times. My project has some layers that are stored in a remote database. How do I bypass the indexing process?
3
votes
0answers
203 views

PyQGIS 3.0: cannot make it work under Windows

I've just tried to install QGIS 3.0 package in my Anaconda (Win7x64, Python 3.6 x64). I wanted to use QGIS widgets in my PyQt application. Alas, QGIS works incorrectly: at first, when I just tried to ...
3
votes
0answers
277 views

Match Projection & Extent Using GDAL

I am looking to match both the projection and extent of two separate .tif files. The file I want all other .tif files introduced into raster calculations is as follows: The other raster image covers ...

1
2
3 4 5
22