Questions tagged [pyqgis]

Python bindings for QGIS.

Filter by
Sorted by
Tagged with
0
votes
0answers
12 views

Adding float attribute to layer using PyQGIS

QGIS 3.10 -- Mac OS I am creating a layer from a GPX file and other data using a script. One of the fields I want to add is a floating point number (a distance). I am accessing the dataprovider ...
2
votes
0answers
19 views

How Can I write Geopackage Layers with Abstract/Description/Metadata using QgsVectorFileWriter

How can I use the QgsVectorFileWriter to include metadata description for Geopackage layers in a python script? I can set the layer name using: options.layerName = "roads_layer" what I want is ...
0
votes
0answers
13 views

Insert image in a DXF file using pyqgis

I have created a DXF file using dxfWrite library with a plugin in QGIS. I want to know if it’s possible to insert an image using a function of dxfWrite library?
2
votes
0answers
27 views

Load vector layer with QgsVectorLayer using MSSQL by select statment

I want to read a layer from a database. I would like to access the table via a select statment. In PostgeSQL works both: vlp1='.....table="mytable" (geom)' QgsVectorLayer(vlp1, LayerName , "postgres")...
1
vote
0answers
22 views

Inserting image in DXF File with PyQGIS [closed]

I am using a DXFwrite library to create a DXF File using a plugin in QGIS. I tried to search in the official documentation of this library about adding or insert an image file into the DXF. Manually ...
1
vote
1answer
26 views

Exporting Geopackage table to directory as CSV with PyQGIS

I have the following extract from a PyQGIS script showing the final function. This script actually form part of a plugin tool for QGIS. I create three geopackage layers and save them into the chosen ...
2
votes
2answers
38 views

Programmatically defining WMS/WFS sources?

I would like to locate a QGIS project on a shared ressource. This project makes use of WMS / WFS data. Is there a way at project opening to programmatically define theses sources (if not existing on ...
1
vote
0answers
25 views

Distance matrix returns points in wrong order QGIS 3.4

I'm using QGIS 3.4 on Windows 10 and scripting in pyqgis. I have a layer representing building centroids that is in a projected CRS. I want to find the azimuth between each building and its nearest ...
1
vote
0answers
32 views

QGIS Python Standalone Script using qgis.rastercalculator

I have been attempting to use the raster calculator algorithm in a standalone python script and have been trouble getting it to work. My issue is with the expression. precip = QgsRasterLayer( ...
1
vote
1answer
30 views

Editing attribute using PyQGIS

I'm trying to automate a simple repetitive task on QGIS. I have some shapefiles with varying number of features in a layer and about 10 different attributes for each feature. I need to add the same ...
1
vote
1answer
23 views

PyQGIS: How to store the result of cliprasterbymasklayer

This Question is a follow up Question to this one I recently asked. In my plugin I have a function that clips rasters by mask and I would like that the function returns the raster layer object. And ...
0
votes
2answers
30 views

PyQGIS: hide a layers-group by uncheking it in the legend [duplicate]

I have a group of layers that contain itself other groups (as shown in picture). I need to hide one group by uncheking the checkbox in the legend. is there any way to do it programatically using ...
2
votes
0answers
44 views

Doing expression for project relation in PyQGIS

I've build an relation between two vectorlayers. Now i want to write an expression for the relation. The standard expression which is given, is to filter features from the first field. Did anybody ...
2
votes
2answers
48 views

PyQGIS: make memory layer permanent

I am working with QGIS 3.4 and I have written the next code in the Python editor. This aims to create a layer without geometry and save it as CSV file. This works fine but my problem concerns the two ...
0
votes
1answer
28 views

PDF export extent of 600 polygons in QGIS using PyQGIS [closed]

Within one polygon shapefile, I have 645 features spread across the UK which I need PDF plans of. The plans do not need to be scale specific, just so long as the extent (plus a 40px padding to show ...
0
votes
0answers
21 views

QGIS2.18.27 changelog

I know it is an old version, but I have a plugin that works fine on 2.18.16 (developed in 2.18.15), but it won't work on 2.18.27 and above. I am hoping that the changelog might help me figure out why, ...
1
vote
0answers
31 views

Object has no attribute “dlg”

I am creating a QGIS plugin and want to list the layers loaded in a Combobox when writing self.dlg the error message object has no attribute appears. I am new in this domain. The code below is for the ...
2
votes
2answers
84 views

QGIS expression, define start and step increment

This is a continuation of the question QGIS Extract by Expression with multiple polylines in Processing Modeler I have polylines with increasing values, Gabriel De Luca helped me to automate the ...
1
vote
2answers
60 views

Adding layer from cliprasterbymask using PyQGIS

In my plugin I would like to use the gdal tool "cliprasterbymask" and add the new clipped raster to my project. According to the Documentation the output has the type "raster". So it returns a ...
2
votes
2answers
57 views

Selecting features by radius using PyQGIS

in QGIS there's a very useful tool "Select features by radius", I'd like to add a similar function in my plugin. The user should be able to choose the radius and the center of the circle (from a ...
2
votes
0answers
33 views

Set image encoding default to PNG in QGIS WMS connections

Some WMS connections in QGIS offer a variety of image encodings and sometimes from am list [PNG, PNG8, JPEG, GIF, TIFF, SVG] JPEG ist selected per default, like shown below, sometimes PNG is selected ...
0
votes
0answers
26 views

LINE PATTERN FILL for plygon symbology in qgis 2.18 by pyqgis

i would like to create this symbology from this vector layer. by taking advatage of pyqgis and programming. i try to develope a code but i got stock , can somebody help me? layer = QgsVectorLayer('C:\...
0
votes
1answer
39 views

Export one attribute field of SELECTED FEATURE from QGIS to a .CSV file using Python [closed]

I found different Python code, which could export all the list of attribute list from QGIS to a .txt or .csv file. But, now I am creating a project where it is needed to export just ONE Attribute of ...
4
votes
1answer
62 views

How to create sub-menus in QGIS 3 plugin

I'm trying to create a sub-menu in a QGIS plugin like in the image. I found this Add extra item to drop down menu plugin. "Layers menu from project" plugin but I'm using QGIS 3 and PyQT5 and ...
4
votes
1answer
68 views

Python script output to console doesn't update beyond first page in QGIS

I'm debugging a python script that includes a Print statement. I'm running the script from the QGIS python editor and expecting to see output in the QGIS python console, however once the script has ...
2
votes
0answers
20 views

Howto “Enable feature simplification for newly added layers” with PyQGIS

Having some performance issues getting huge vector layers to be drawn the first time under heavy system load, I am interested to test what is called in QGIS application "Enable feature simplification ...
1
vote
1answer
43 views

Insert QGIS processed raster image (e.g. GeoTIFF) to PostgreSQL/PostGIS database by pyqgis

I've already connected to my database by a script, and loaded a vector a layer to QGIS. Is there a way to upload a raster layer back to the database? tablename = "***" geometrycol = "***" from qgis....
2
votes
2answers
72 views

PyQT5 - How to use QCompleter, QGIS Plugin

I'm trying to use QCompleter to get something like in the image. The code seems pretty simple, but in my dialog nothing happens. Is there some problem in this code? The dialog is created using Qt ...
2
votes
2answers
73 views

Export one attribute field from QGIS to a .TXT or .CSV file

I used this code in Python to export attributes from QGIS to a .TXT file : ##input_file=vector from qgis.core import * import processing # Load the layer layer = processing.getObject(input_file) # ...
2
votes
0answers
11 views

Howto cache a maplayer before drawing

Using my standalone pyqgis application the user is able to draw moving points with an refresh rate of 1 second. These points come from a sensor that moves around and transmits data over a wireless ...
6
votes
1answer
111 views

Change encoding type for all files or whole project

How can we change encoding mode for the whole project rather than doing to single shapefiles in QGIS 3.4? I wanted to change "UTF-8" to "Shift_JIS" to all project vector files.
1
vote
1answer
42 views

Error when using input() pyqgis (RuntimeError: input(): lost sys.stdin) QGIS 3

I need the user to input a value. I'm using input() on qgis python console, but getting this error: RuntimeError: input(): lost sys.stdin How can I solve it?
1
vote
2answers
35 views

Count features in layers and categories

I want to automatically count features in my opened layers, and add the result in the layer name, with pyqgis. I can do it with this code : layers = QgsProject.instance().mapLayers().values() for ...
1
vote
1answer
31 views

How to perform (sync or async) network request in PyQGIS

Following a question on the mailing list about what is the best way to perform network requests in PyQGIS both blocking and non-blocking and with or without support for authentication (QGIS' authcfg) ...
0
votes
2answers
39 views

PyQGIS in PysScripter

I am trying to add the PyQGIS in PyScripter, I have followed the tutorial provided in QGIS tutorial: IDE settings for writing and debugging plugins. I have created the bat file as follows: SET ...
1
vote
1answer
56 views

Writing shapefile using PyQGIS

In QGIS 3.10, the data for the layer SIMnodes seem to be OK as inspected in the respective data table but trying to save it into a shapefile: cSIMnodes = QgsProject.instance().homePath() + '\\...
3
votes
1answer
56 views

How can I process vector difference between 1 group layer and 1 polygon layer?

I have one layer group called 'left_buffer', containing 40 buffered polygon layers (name: 1,2,3,...,39,40). I want to use difference vector tool between 'left_buffer' and 'bldg' layer, but I'm getting ...
1
vote
0answers
34 views

python queries distance the nearest object [closed]

I have 2 point layers, I want to calculate the shortest distance between 2 point layers by python code and enclose the conditions of satisfaction. For example, a point a when there is the shortest ...
2
votes
1answer
24 views

RuleBasedRenderer with two different symbols using PyQGIS

I am trying to create a RuleBasedRenderer with two layers. The first layer is used to fill the polygons and the other should create a hatching effect with lines. However, the code below, creates the ...
2
votes
0answers
16 views

Getting coordinates of pixels inside QgsRasterBlock

I am trying to implement a function that filters some points around a focus point in QGis, based on a raster map, and then does some distance calculations with the result. For this, I need to convert ...
2
votes
1answer
36 views

Creating QgsVectorLayer from Pandas dataframe

I am writing a python script for QGIS. I have a pandas dataframe that I would like to use in order to create a QgsVectorLayer. At the moment I am saving the data frame into a .csv and then I load it:...
3
votes
1answer
36 views

Export looped layers at once using PyQGIS?

I am trying to use one-side buffer on road centerline (layer name: small_road) by 1~40m. I've succeeded in creating one buffer (2m) file at a time using 'SEGMENTS':2,'JOIN_STYLE':0,'MITER_LIMIT':2,'...
2
votes
2answers
36 views

Loading OpenStreetMap in PyQGIS

I've written a processing script using pyqgis 3.4 which works. The next step I would like to achieve is to load openstreetmaps as the base map from within the processing script. I can do so easily ...
2
votes
1answer
24 views

Loading all raster layers in folder using PyQGIS

I would like to load all raster layers with type .xyz which are in a folder into my QGIS Project using PyQGIS and wrote the following function for lyr in glob.glob(os.path.join(inputDir, "* .xyz")...
3
votes
1answer
82 views

Sum the values of all rasters in a user defined list

I am creating a QGIS plugin a part of which is like the SAGA Rasters sum tool. The user interface will have a widget to which the user will load the raster layers. I am trying to get the pixel-wise ...
1
vote
0answers
20 views

how to access Canvas mouse point on action of button from another window Pyqt5

I am PyQt5 and PyQgis novice. Below code snippet is my main window application. Below code throw a main Window with QGsMapCanvas as central widget as canvas, which displays maps. On menu action and i ...
0
votes
1answer
38 views

Getting bounding box of polygon

I'm having difficulties to get the bounding box of a polygon. My code is the following: def getBoundingBox(self): boundingBox = [] polygon = self.getVectorLayer() vertices = polygon....
2
votes
1answer
45 views

Getting screen coordinates from canvas coordinate using PyQGIS

I'm trying to set the initial position of my QGIS plugin dialog. I'm using .setGeometry() but the problem is that I don't know how to get coordinates. I want to set the initial position in the top ...
0
votes
0answers
44 views

Python/PyQGIS - Count from Image corner using pixel x y to create x y coordinates

I have an output from a model which provides me with .txt file containing pixel X Y values. What I need to do is convert them to a set of coordinates (Irish grid, 29902). The images feed into the ...
1
vote
0answers
26 views

Getting (0,0) instead of the intersecting co-ordinates value

This code works below fine when line(The Circle I mean) intersects more than two new lines but fails when both the intersection falls in the middle of the same line polygon_path = iface.activeLayer() ...