Questions tagged [pyqgis]

Python bindings for QGIS.

Filter by
Sorted by
Tagged with
0
votes
1answer
20 views

Handling PostgreSQL IntegrityError from PyQGIS

I am developing a QGIS plugin, in which I want the user to be able to add/delete features from some layers. Here is the code I'm using to delete a feature with id = trayId try: self.traysLayer....
0
votes
1answer
25 views

Using Python Code from QGIS modeler with if and else

I am using QGIS 3. The following script code is generated from a model. At the end the code has to create a field Fl_m2, if the blnFl is true. if ['blnFl'] is True: If it is not true the ...
1
vote
0answers
20 views

QGIS custom script to run one process or another depending on input

[QGIS 3.10] I have two processes I have created using the graphic modeler. I'm trying to create a script that would run one process or another depending on the inputs. But I'm getting an error in line ...
1
vote
0answers
17 views

Manipulating Transformation parameters with PyQGIS

Is it possible to add a layer with a local coordinate system, transformed on the fly by a custom transformation entry from this local CRS -towgs84 and furthermore to manipulate the -towgs84 Parameters?...
0
votes
2answers
27 views

Calculating elipsoidal length of line in PyQGIS

I am using PyQGIS with QGIS 3. This code below is what I developed already, what I am doing wrong? layer = iface.activeLayer() feature=layer.getFeatures() for feat in feature: feature....
1
vote
2answers
38 views

Converting from SHP into TXT file using PyQGIS

I'm working with many shp file point format with geometry attributes like this: But I need convert it into such format in textfile like below: Are there any ways to arrange my shapefiles format into ...
0
votes
0answers
32 views

Difference between mapshaper simplify and generalization tools available in GRASS and QGIS? [closed]

I had the idea to develop a qgis plugin with python that mimics the functions of the mapshaper simplify webtool. However, after doing some digging into the generalization tools already available in ...
2
votes
1answer
40 views

Filter combobox to show only Points layers

I am creating a plugin using QT Designer and QGIS 2.18. Using Plugin Builder along with examples I have been able to create a combo box that list all current layers in QGIS. I only want to list ...
2
votes
1answer
42 views

Calculate distance from a point to a MultiLineString geometry - PYQGIS

I'm trying to calculate the distance from a point to the closest river in my QGIS plugin. But I receive this message: MultiLineString geometry cannot be converted to a point. Only Point types are ...
1
vote
1answer
49 views

Converting selected polygons to lines using PyQGIS

In PyQGIS 3, how can I convert selected polygons with n sides, into another layer with n lines? import processing mapcanvas = iface.mapCanvas() layer = mapcanvas.currentLayer() features = layer....
2
votes
1answer
42 views

QGIS Processing Model with IF script

I have a QGIS model that I want to modify with an IF personalised script. Basically one of the inputs is optional, but if it's empty then the model is throwing some errors down the line. Hence the ...
2
votes
1answer
25 views

TypeError: QgsGeometry.fromMultiPolygonXY(): argument 1 has unexpected type 'list'

When I modify the code (which works) from: vertices = fProject.geometry().asMultiPolygon() for v in vertices: points.append(v) fet.setGeometry(QgsGeometry.fromMultiPolygonXY(points)) to: pt = ...
-2
votes
0answers
38 views

Seeking complete guides on How To Extract data from Attribute Table using Python [closed]

I am not a Python user but if I can learn how to extract data using python then maybe that will make my work faster and easier. The guide must be on QGIS 3.4 or later. Can you link me some guides?
1
vote
0answers
31 views

Convert GeoTIFF to KMZ

I am trying to convert a GeoTIFF to a KMZ. Here's my code: from osgeo import gdal import zipfile srcf = r"C:\raster_to_kml\OrthoImage.tif" vfn = "/vsimem/OrthoImage.jpg" drv = gdal.GetDriverByName('...
1
vote
1answer
37 views

Getting QgsMapCanvas viewport's four corners' coordinates

I have a PyQgis application that uses the QgsMapCanvas as map display. I am trying to retrieve its four corners' coordinates, but couldn't find any public function to do that. All I have is its width()...
2
votes
1answer
30 views

Setting QGIS simple line color depending on fields value in python plugin in QGIS

I am new to QGIS and using QGIS 3.6. I am trying to add a geojson file to QGIS and then export it to a png. I have a color filed in geojson, and can apply it with GUI. Now I want to do it using ...
1
vote
0answers
17 views

Rename layer result from PyQGIS QgsProcessing.TEMPORARY_OUTPUT to something else

I have a PyQGIS script that I exported from a QGIS process model. I have set output layer names that make sense in the model but when I export and run the model in PyQGIS it outputs the temporary ...
0
votes
0answers
18 views

QGIS save raster as rendered image AND change projection [closed]

I'm trying to save a raster as a rendered image by doing "save as.." in QGIS. My problem is that I need to do this for a lot of raster layer and I need to give it a new projection at the same time. ...
1
vote
1answer
34 views

Using QGIS Python Console in QGIS

I'm pretty new to using the console and still have a lot to learn so this might come across as a really stupid question. I imputed this code into the console: counter = 0 # Set the path for the ...
1
vote
1answer
43 views

Create Rubber Band with rotation using PyQGIS

To start I am going to be upfront, I am trying to add a feature to a QGIS Plugin Called instantprint. I am trying to add rotation to the tool so that you can align features to the print box and have ...
1
vote
1answer
32 views

Using iface in standalone pyqgis script

I am practicing QGIS python API and I made standalone script to create .qgs file and import some layers from postgis database. Now I need to zoom to imported layer but I saw that it is not possible ...
1
vote
1answer
28 views

QGIS Python Console SQL Server Layer Incorrect Attributes

I am using the QGIS python console to load a SQL Server layer in QGIS using the follow code: uri = "MSSQL:{MYSERVER};database={MYDATABASE};tables= MYTABLE};trusted_connection=yes" lpBatch = ...
0
votes
0answers
27 views

Getting layer reference using a feature

Using an existing feature, is there a way/method to get the layer which contains that feature? Example: # new empty feature which doesn't belong to any layer new_feat = QgsFeature() #---------------...
0
votes
0answers
45 views

How can I import pyqgis API into standalone Python script?

I want to create .qgis file from standalone Python script and I need to import pyqgis (qgis.core ). I tried commands: set PYTHONPATH=C:\Program Files\QGIS 3.4\apps\qgis-ltr\python and set PATH=C:\...
2
votes
1answer
43 views

Interpolation (TIN) from Python Console in QGIS

I am referring to the most voted answer by root676 in Calling interpolation plugin from Python console of QGIS. root676 ends his/her answer with: Keep in mind that the QGIS-API is currently ...
3
votes
2answers
128 views

Using QGIS Python interpreter outside QGIS

I'm writing a simple Python Geoprocessing script which leverages two specific modules: from osgeo import gdal import pyproj The script must be shared with colleagues in my organisation.To avoid ...
1
vote
0answers
30 views

QGIS API (PyQGIS) doesn't properly read layers

I have a problem with reading qgs file by PyQGIS lib. I'm creating python standalone stript which externally use PyQGIS from installed QGIS desktop application. The problem is that PyQGIS sometimes ...
1
vote
0answers
30 views

Using Input Layer as part of Global Expression in PyQGIS

In Advanced Python Field Calculator tool, I can get a feature's geometry using $geom or its id using $id in Formula section. Is there a way to get reference of layer selected as Input Layer to use in ...
2
votes
0answers
19 views

Exporting from Atlas to PDF in QGIS GUI and adding metadata with Python

I'm trying to add metadata to all my PDF files generated by an Atlas export in QGIS 3.10. GUI. Is there any Python signal to which I can connect a slot, that gets executed when each Atlas page ...
1
vote
1answer
27 views

QGIS: Selecting active layer to be processed in Python script exported by Graphic Modeller

I created a model and I would like to have it as a python script. This is what I see when I run my model and I can select a layer from this window. I don't necessarily need to select a layer, it can ...
2
votes
1answer
54 views

QGIS 3.4, plugin builder, refresh layers

I created a very simple plugin with the plugin builder for GIS 3.4. Wihtout any GUI-Widget - by clicking the plugin button I just want to save the edits from several layers at one time and start the ...
2
votes
1answer
39 views

Read path project and load layer

How can I correctly concatenate the path of a project with a specific shapefile layer and to be able to load it; this is: QgsProject.instance().readPath("./") <---path layer = iface....
0
votes
2answers
30 views

Getting field names in PyQGIS [closed]

How do I get field names in PyQGIS 3.x?
2
votes
0answers
30 views

Select extent on canvas - QGIS Plugin

I'm designing a QGIS plugin where I'd like to offer the user the functionality to select the extent of a bounding box from the canvas like in some tools like Create grid. I've explored QT Designer ...
-1
votes
1answer
66 views

Error in QGIS with Raster Tool in plugin [closed]

When I open QGIS I get the following error: Couldn't load plugin 'rastertool' due to an error when calling its classFactory() method and the following command: ModuleNotFoundError: No module named '...
1
vote
0answers
32 views

Adding north arrow using PyQGIS

I am trying to put the north arrow on the graphic output of the map using Pyqgis (Qgis 3.4). I tried adding it as an image with the attached code but I have the background of the image and it does not ...
1
vote
1answer
38 views

Using Python script inside QGIS Graphic Modeler and iterating over all features

I created a graphic model which simply creates multiple vector attributes. All attributes are empty to be filled manually. Only one attribute column (let's call it KEYS), needs a different process and ...
0
votes
1answer
37 views

Script to upload several .xyz files into QGIS

The following script has the purpose to upload all .xyz files into QGIS that are within the folder xyz_data. That's the script: from qgis.core import QgsVectorLayer, QgsProject import glob, os dir = ...
1
vote
0answers
24 views

Separating islands into individual rasters from island chain mosaic using QGIS [closed]

I've manually created mosaics of some island chains using the SRTMGL1 v3 data, for example the Hawaiian Islands. From a mosaic, I want to create a set of separate rasters for each of the islands. (I'd ...
1
vote
0answers
42 views

Calling processing algorithm in different file than main file for standalone application [closed]

I need to run a processing algorithm that is coded/called in different file than main file. I've read some posts (1, 2, 3, 4, 5) but they give a solution that runs algorithm in main file. When I use ...
0
votes
1answer
68 views

PyQGIS - Save processing output to temporary file which is discarded when QGIS is closed (on Windows)

QGIS 3.10.1, Windows 10: When using the GDAL tool Clip Vector by Extent from the processing toolbox and saving the output to a temporary file, the output layer appears in the layer list with a ...
1
vote
0answers
56 views

Python command for QGIS that iterates over .xyz files doesn't work [closed]

I have a small Python script for QGIS that goes to a folder and iterates over its files and uploads all .xyz files. This is the script: import glob, os dir = r"C:\Users\User\Desktop\xyz_daten" ...
1
vote
0answers
48 views

How to install an in house package from local directory in QGIS?

I need to install a private package which is in my local directory to the QGIS Python environment. I can install it to my conda environmnet by defining the local directory path as channel. How do I ...
1
vote
1answer
48 views

How to batch the import of DWG files in QGIS?

I can import and open DWG files to geopackage one-by-one with the Project -> Import/Export -> Import Layers from DWG/DXF command. This window use the QgsDwgImporter cpp function: https://github....
1
vote
1answer
41 views

PyQGIS script for loading several .xyz files into QGIS gives NameError

I found a script for loading several csv files into QGIS and modified it for .xyz Data. Yesterday on one Computer it worked and today on a different Computer it's not working anymore. Is there ...
0
votes
0answers
18 views

Showing geometry from MySQL table on standalone QGIS application

I am using below code to connect the MySQL table on a QGIS based standalone application. I am using QGIS 2.7 and MySQL 5.7 version. uri="MySQL:mysql,host=localhost,port=3306,user=root,password=...
2
votes
2answers
91 views

Use QGIS general tools/actions in my plugin

I am creating a QGIS plugin that will use some general tools available in QGIS like "identify features" and a plugin like a "digitizing tool". Is it possible for example to link a button of my plugin ...
0
votes
0answers
51 views

Since installing QGIS 3.10.1-A Coruña I can't get Python script to work in IDLE: ImportError: No module named qgis.core

I have tried adding sys.path.append and under cmd.exe set Python Path but am still getting the dreaded ImportError: No module named qgis.core. I set PythonPath to C:\OSGeo4W64\apps\qgis\python I ...
0
votes
1answer
31 views

Exporting shapefile to KML with set line width using PyQGIS

I am currently using QGIS 2.18. I have some code to export certain shapefile layers to bring into KML. When I bring them into Google Earth, the lines are much thinner than I would prefer them to be, ...
2
votes
1answer
57 views

How to set widget type to 'Attachment'?

I would like to make an open file dialog to appear in a field in the attribute table of a vector layer. I guess I need to set widget type to 'Attachment' for that field and to check 'Display button to ...