Questions tagged [pyqgis]

Python bindings for QGIS.

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

Get print layout's item width and height in PyQGIS

I'm trying to create a function that will return the width and height of a print layout item. This one doesn't work. from qgis.core import * from qgis.gui import * @qgsfunction(args= 'auto' , group='...
user avatar
  • 786
3 votes
1 answer
30 views

Select feature by expression and run "native:buffer" on selection, works for "id" field but no other field in PyQGIS

I'm trying to select features from a polygon layer where a specific string value ('yes') is found in a field called "result" and buffer them. My script can select features with a specific ...
user avatar
0 votes
0 answers
21 views

Importing files using PyQGIS on Mac OS

I have a strong issues to identify the path I must specify to import (or save) a file in PyQGIS. Here are the different paths given by sys.path : import sys print(sys.path) #results ['/Applications/...
user avatar
1 vote
0 answers
42 views

Connect QGIS with PyCharm

I don't get the concept of developing with Python in QGIS. There is a Tutorial in the QGIS docs how to setup PyCharm for developing standalone scripts or how to develop custom applications. The first ...
user avatar
  • 133
-1 votes
0 answers
16 views

Quick OSM on QGIS erro [closed]

when I load man_made and Survey_point on the OSM for Randfontein town in South Africa the query does not recognize the Randfontein town.
user avatar
  • 1
-1 votes
0 answers
22 views

PyQGIS, path to the folder from which the script is run [closed]

How to get the path to the folder from which the script is run? I need this file path:
user avatar
2 votes
1 answer
32 views

Toggle display of unplaced labels with PyQGIS

I am making a script that works with labels. Is it possible to turn on/off the display of unplaced labels with PyQGIS?
user avatar
0 votes
1 answer
25 views

Unable to save KML file using QgsVectorFileWriter

I am using this code: default_filename = Path.home() / "Documents/test.kml" outputlayer, _ = QFileDialog.getSaveFileName(self, "Save KML file", str(default_filename), "KML ...
user avatar
  • 362
0 votes
0 answers
19 views

QGIS Plugin to inject headers on the fly

Is it possible to create a QGIS Python Plugin, or even a standalone Python script, that listens for network requests, and, if they don't meet certain criteria, will inject some headers? The requests ...
user avatar
0 votes
1 answer
44 views

Using graphviz module in PyQGIS [closed]

I need use the graphviz module. this is first time. I performed following steps. Open the OSGEO4W shell and run py3_env commend and installed graphviz module by using python -m pip install graphviz ...
user avatar
1 vote
1 answer
23 views

Unlocking scale with PyQGIS

I'm making a script that uses canvas.zoomScale(550_000, False) zoom. However, if the user is zoom-locked, the script will run incorrectly, but it will not give any error. Is it possible to somehow ...
user avatar
0 votes
1 answer
26 views

PyQGIS cannot set proper symbol color

I have created a script to run inside QGIS via the Script Runner. It works by checking if a layer is already present. If so, it just reloads the layer but if the layer is not present it loads the ...
user avatar
  • 163
0 votes
0 answers
18 views

QGIS mapCanvas refresh event: infinity loop

[Background] I am building an QGIS app that communicates with the MapGuide server, which returns an image. That image is then stored in a layer which is added to mapCanvas. Basic workflow of an ...
user avatar
1 vote
1 answer
34 views

Open the algorithm dialog of a custom QgsProcessingAlgorithm instance

In a custom plugin I'm calling some custom QgsProcessingAlgorithm that are loaded with the plugin itself. If I create an instance of these algorithms I need to prefill the parameters with some custom ...
user avatar
  • 2,682
2 votes
0 answers
55 views

No module name qgis in QGIS 3.22

I recently upgraded to QGIS 3.22 For plugin development I am using PyCharm. after upgrading QGIS to this version PyCharm is not able to read the pyqt, QGIS modules. I am running PyCharm with the ...
user avatar
1 vote
0 answers
45 views

Using joinattributesbylocation in PyQGIS

I want to join the attributes of two layers but only want to keep the objects of my input layer. So I came across the function "joinattributesbylocation" and tried to add it in my script ...
user avatar
  • 67
0 votes
0 answers
25 views

No output from saga:polygonselfintersection process in PyQGIS

I'm trying to use the saga:polygonselfintersection process in my script but only the .prj file is saved in the output. When I'm using the process in a testscript in the python-console its working fine....
user avatar
  • 175
-1 votes
0 answers
42 views

dataprovider() AttributeError

My code: cLayer = qgis.utils.iface.mapCanvas().currentLayer() provider = cLayer.dataProvider() Error: Traceback (most recent call last): File "C:\PROGRA~1\QGIS32~1.7\apps\Python39\lib\code.py&...
user avatar
  • 1
0 votes
0 answers
23 views

Prevent 'Stop Editing' popup from showing when editing mode is toggled PyQGIS

In my plugin, when the user adds a feature, I am committing the changes in code, so when the user clicks the 'done' button, there is no need for the popup that asks the user if they want to save ...
user avatar
  • 362
-1 votes
0 answers
15 views

programação iniciante [closed]

boa tarde... sou iniciante em programação, e estou tentando desenvolver uma aplicação no qgis...para que ele crie uma função na minha caixa de processamento... assim o problema é que quando executo o ...
user avatar
1 vote
1 answer
38 views

Using variable in QgsDefaultValue() of PyQGIS

This is not working for me: # set default values fields = { 'target_geometry_set_id': self.poly_set_id, 'target_geometry_type': 'Polygon', 'target_geometry_source': '...
user avatar
  • 362
0 votes
0 answers
14 views

Error starting QGIS 3.22.5 (Białowieża) [closed]

I am using QGIS 3.22.5 (Białowieża) with Py and when start the software, an error message appears: No se pudo cargar el complemento 'MetaSearch' debido a un error al llamar a su método classFactory() ...
user avatar
1 vote
1 answer
24 views

Auto populating attributes when feature added instead of edit form popping up using PyQGIS

In my plugin, the user can go into add feature mode: self.poly_layer.startEditing() iface.actionAddFeature().trigger() And I can suppress the edit form from popping up by doing this: ...
user avatar
  • 362
0 votes
1 answer
23 views

Change Color of QgsMapToolEmitPoint

I have built a QGIS Plugin which activates the QgsMapToolEmitPoint for getting XY-Coords when I click on the map. Everything works as desired with the following code: def foo(tool): click = (tool....
user avatar
  • 1
0 votes
0 answers
9 views

How to add colormap renderer from a classified single band "QgsRasterLayer" with PyQGIS

I'm trying to add a colormap to a TMS service which is serving single band PNG with values ranging from 1 to 11. At this point, the layer renders in black (low values between 1 and 11) but I would ...
user avatar
1 vote
0 answers
30 views

QGIS 3 : Removing a memory layer with pyQGIS

I'm trying to remove a memory layer from the QGIS TOC. Here is my code to create the memory layer : self.uri = QgsDataSourceUri() self.uri.setConnection("bd", "bd", '', '', ...
user avatar
  • 379
3 votes
1 answer
74 views

Generating horizontally ordered ids for irregular grid

How can I generate ids for an irregular shaped grid that increase from west to east and north to south (left to right, top to bottom)? I've tried using this example and it almost works, but it does ...
user avatar
  • 121
1 vote
1 answer
87 views

Change XYZ tile to Color Rendering to Grayscale

I want to change Color rendering of the XYZ tile(namely google satellite). In case of raster image we can easily convert using following code. layer = iface.activeLayer() myGrayRenderer = ...
user avatar
0 votes
0 answers
16 views

pyQGIS script 'not a valid or recognized data source'

I have been running pyQGIS scripts successfully using the plugin Script Runner. Now I am trying to adapt the scripts to run outside QGIS (a standalone script). Following the pyQGIS cookbook (...
user avatar
  • 163
2 votes
1 answer
46 views

Getting geometry from attribute using PyQGIS

I am using PyQGIS 3. I pull in a line table from postgres database. and one of the attributes is a point geometry, when I open the attribute table that column shows data in this format: SRID=4326;...
user avatar
  • 362
2 votes
1 answer
44 views

Structure of QGIS_Processing commands

As per https://docs.qgis.org/3.22/en/docs/user_manual/processing/standalone.html?highlight=qgis_process I am trying to run the following (that works in the QGIS python console). alg_params = { ...
user avatar
  • 7,616
0 votes
1 answer
35 views

Strange "TypeError: string indices must be integers" when refactoring fields (processing.run()) in PyQGIS

I wrote a small function to refactor fields (just one field really) in a given Shapefile which I output as a temporary layer. In principle it works just fine. I build a String with all the info the ...
user avatar
  • 165
0 votes
1 answer
51 views

Saving temporary vector layer after adding into group using PyQGIS

This code is not displaying any feature in QGIS , so I want to save the temporary layer so that the features can be visible. extract1 = processing.run("native:extractbylocation", { 'INPUT': ...
user avatar
0 votes
0 answers
18 views

Using Pyjulia/Julia with PyQGIS

Does anyone know how I can go about using PyJulia in QGIS Python? I was able to pip install pyjulia, but it can't find the Julia installation on my computer ("not in PATH", which it most ...
user avatar
  • 1
1 vote
2 answers
57 views

Open attribute edit when feature is selected using PyQGIS

For my plugin I want the user to be able to select a feature and an edit window popup for editing a certain attribute of that feature. I could do this by making a QInputDialog.getText show up when a ...
user avatar
  • 362
0 votes
2 answers
26 views

PyQGIS QGSExpression translate nothing happen

I'm trying to use this expreission and apparently works if I print the result, but nothing happen in the map canvas. Do you have some suggestions? from qgis.core import * from qgis.utils import ...
user avatar
0 votes
0 answers
32 views

Create a QgsProject without opening it

I could find a method to do that. Suppose you have a list of QGIS project paths and you want to get the project information, like the loaded layers, canvas extent, etc from the project. I thought the ...
user avatar
  • 2,682
1 vote
1 answer
31 views

Correct way to use DROP TABLE on SpatiaLite in PyQGIS

I try to delete a table in an SpatiaLite database using PyQGIS. The table is deleted, but still shown in the browser panel. I'm using the following code: query = "DROP TABLE table_name;" ...
user avatar
  • 298
0 votes
1 answer
37 views

Python editing of QGIS layer metadata

I want to feed metadata (title, attribution, etc) to a lot of raster layers in a QGIS project. From what I have read, I managed fine to get hold of metadata from the QGIS python console, using simple ...
user avatar
-1 votes
0 answers
29 views

Building origin-destination graph with PyQGIS

Is there a way we can design an origin-destination graph (see #figure2) with PyQGIS ? This graph would be based on the attributes of two QGIS layers (see #figure1) : Lines : a shapeline that describe ...
user avatar
  • 434
1 vote
0 answers
39 views

Adding features to a vectorlayer using PyQGIS in VSCode

I'm trying to create a plugin that generate a vector layer with geometry using 2 other layers, the first one 'layer_segment'contain features with geometries to dissolve based on common field value ...
user avatar
1 vote
1 answer
36 views

PyQGIS: Create raster layer from QgsRasterFileWriter

I would like to create a singleBand raster (grayScale) using the method qgis.core.QgsRasterFileWriter.writeRaster According to the documentation: writeRaster(self, pipe: QgsRasterPipe, nCols:...
user avatar
0 votes
1 answer
43 views

Not able to create memory layer while running processing algorithms

I am trying to run processing algorithms in Python code editor inside QGIS. Here is my code: zones = QgsVectorLayer('C:/Users/pamidiashoka/Downloads/OP_Pen/boundaries.shp', 'zone boundaries', 'ogr') ...
user avatar
-1 votes
0 answers
14 views

Unable to import QGIS and processing algorithms in a venv for a standalone Python script [duplicate]

I am trying to run QGIS processing algorithms in a standalone Python script (in a virtual environment). I adjusted the path variables so that Python from QGIS will be accessed first instead of Python ...
user avatar
0 votes
0 answers
44 views

Unable to import QGIS algorithms in a virtual environment

I am trying to run QGIS processing algorithms in a standalone Python script (in a virtual environment). I adjusted the path variables so that Python from QGIS will be accessed first instead of Python ...
user avatar
0 votes
0 answers
55 views

Make QGIS Python console wait for user input

I am trying to manually edit a bulk of GeoJSON files in QGIS, and I want to use the Python console to make the process more efficient. I figured out how to load and save the file, but I could not ...
user avatar
1 vote
1 answer
60 views

Identifying the maximum value of each row in attribute table

I am trying to identify the maximum value from specific columns for each row in the attribute table of my shapefile. Therefore I wrote the following script (as part of a bigger script): layer = ...
user avatar
  • 67
0 votes
1 answer
57 views

RuntimeError: wrapped C/C++ object of type QgsPrintLayout has been deleted

When I am running the code in QGIS python console, I am getting an error - RuntimeError: wrapped C/C++ object of type QgsPrintLayout has been deleted from PyQt5.QtCore import QTimer fileName = 'D:\\...
user avatar
0 votes
1 answer
36 views

PyQGIS save a project and close a project - QGIS v3

Using PyQGIS with QGIS v3 My script opens an empty QGIS project (thinking this would retain the path). I add some layers, perform a few tasks. All is good. Now I want to close the project or I should ...
user avatar
  • 163
1 vote
1 answer
20 views

QgsVectorLayer Line layer in memory, layer source could not be found PyQGIS 3

I'm at a loss for what I could be missing here self.curve_layer = QgsVectorLayer("line?crs=epsg:4326", "curves", "memory") feats = [] xform = ...
user avatar
  • 362

1
2 3 4 5
133