Questions tagged [pyqgis]

Python bindings for QGIS.

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

Loading layer from PostGIS database

I'm trying to load a layer from a PostGIS database using PyQGIS. The code is: import os from qgis.core import * project = QgsProject.instance() project.clear() uri = QgsDataSourceUri() uri....
2
votes
1answer
78 views

How to convert a .csv file to shapefile with the attribute table geometry using pyqgis

I am trying to convert a .csv file to .shp using pyqgis. With this publication ETA managed to generate the file with all its extensions and the table of attributes but I do not see the entities (type ...
1
vote
1answer
54 views

Export clustered points as coordinates in QGIS

I have been looking at taxi data in a city and wanted to cluster points over a set area to see how many entries would be in each clustered area. My input is a csv of taxi data points [TaxiID, lat, ...
4
votes
1answer
79 views

Manually creating or copying an auxiliary table in QGIS 3 with Python

I have a local layer which gets updated every now and then by being copied from a WFS. The local layer has some labels shown and some hidden through auxiliary table, because QGIS seems to only accept ...
0
votes
1answer
78 views

Accessing Vector Field Parameter Value inside Python Script

I have created a QGIS Graphic Model using the built-in Graphic Modeler. My model is supposed to ask the user for an input layer, an overlay layer, and a field from the overlay layer. The model then ...
0
votes
1answer
35 views

Online Courses to Learn Writing Custom Python Scripts / Plugins in QGIS? [closed]

I am looking for resources to learn writing Python Scripts / Plugins for QGIS. The Developer Cookbook is a good start, but I am specifically looking for a video-based resource that teaches with hands-...
0
votes
1answer
35 views

Printing portion of a map for multiples locations in QGIS?

I need to generate .png or .pdf files with a portion of the map that Im currently working on for each object in a shape file. Im working on QGIS3. I have a shape file with multiple points wich ...
8
votes
3answers
263 views

Providing QGIS expression within a plugin

I have written a custom function in the field calculator in QGIS. How do I distribute this function to other QGIS installations the best way? I can of course instruct the user what to type or copy / ...
1
vote
1answer
46 views

Load raster layer from gpkg file

I'm new with PyQGIS. I need to load a raster layer from gpkg file, and i tried this way: gpkg_raster_land_layer = "GPKG:" + path_to_gpkg + ":" + layername r_layer = QgsRasterLayer(...
1
vote
0answers
19 views

Debug In-dialog provided python code in QGIS attribute form 'Python Init Code Configuration'

In a QGIS layers attribute form configuration I have the following Python Init Code Configuration: Code in plain text: # -*- coding: utf-8 -*- from qgis.PyQt.QtWidgets import QWidget, QLineEdit ...
0
votes
1answer
31 views

Implementation of multiple-point statistics in GIS

Is there any implementation of multiple-point statistical algorithms in GIS? at least for spatial interpolation. code for instance.
3
votes
1answer
10k views

Setting options in “PDF Export Options” to export an atlas to PDF using PyQGIS

While saving an atlas as PDF in QGIS, I can manually change the settings shown the image using "PDF Export Settings" window. How can I set those options using PyQGIS? Minimal code: layout_manager = ...
2
votes
1answer
76 views

List of usable ogr-drivers for PyQGIS

When using the following PyQGIS line, I write a layer as a CSV into an output path. QgsVectorFileWriter.writeAsVectorFormat(lyr, outputPath, 'utf-8', lyr.crs(), "CSV", ...
1
vote
0answers
48 views

PyQgis Cycle to create multiple maps

I am developing a PyQgis script, which automates the creation of maps in .png format. Loading the corresponding rasters and shapes first, adding format to each layer and then creating a template and ...
4
votes
1answer
64 views

QGIS: Accessing layer's CRS from expresison and/or PyQGIS

How can I access the current feature's/layer's CRS from an QGIS expression, or from a custom expression in PyQGIS? In my expression, I use the following to buffer a (currently lat-long-specified) ...
1
vote
0answers
20 views

Keeping same color when using “gdalogr:polygonize” function to polygonize segmented image

This is one example of images that I have: Now I want to polygonize it to get shapefile of different polygons. Every time I run this algorithm I get polygons of different colors but I want to keep ...
3
votes
1answer
81 views

Setting “Disable tiled raster layer exports” option to export to PDF using PyQGIS

I need to use the setting Disable tiled raster layer exports from the GUI in my Python code, but I can't seem to find it. exporter = QgsLayoutExporter(layout) exporter.exportToPdf(path, ...
5
votes
1answer
86 views

QGIS 3.6 and QGIS 3.10 report different geometry types for the same shapefile

I used QGIS 3.6.3 to create a polyline shapefile, and the program reported the polyline as LineStringZM. When I opened the same shape file in QGIS 3.10.3-2, the polyline was reported as ...
3
votes
1answer
48 views

Consecutive -not parallel- QgsTask execution in QgsTaskManager

Situation: I am working on a PyQGIS plugin that sends a multiple WPS request (https requests) from a QgsTask object to a server. In order to avoid freezing of the GUI for long requests I am using ...
1
vote
1answer
45 views

PyQGIS error: 'QgsVectorLayer' object has no attribute 'xMinimum'

I have the following code: def moveFiles(self): mask = self.getBoundingBox() #BoundingBox of polygon layer inputDir = self.dlg.input_folder.text() #directory of xyz files - "Users/denni/...
1
vote
1answer
122 views

“QgsVectorFileWriter.writeAsVectorFormat(): arguments did not match any overloaded call” in PyQGIS

The following code iterates through a folder of .xyz files and is supposed to copy them into another folder. for file in glob.glob("*.xyz"): uri = "file:///" + inputDir +"/"+ file + "?type=csv&...
-1
votes
1answer
67 views

TypeError: QgsVectorLayer(): argument 1 has unexpected type 'QgsVectorLayer'

I'm getting this error when I try to run the following code: a6 = processing.run("native:difference", {'INPUT':'_78b00e45_4a8e_4490_9920_f75f6e055a6a','OVERLAY':'...
2
votes
1answer
47 views

Why does my PyQGIS standalone script not work

I wrote a pyqgis script that should iterate over a folder with xyz files, check if the bouding box overlaps with a polygon in my QGIS project and if yes, it should copy the file into a new folder. I ...
1
vote
0answers
82 views

Programatically create WMS and specify data sources in QGIS Server from a web app

Is it possible to programatically create a WMS and specify data sources in QGIS Server from a custom web app? Let's say I have a QGIS project being served up by QGIS Server and accessible via a web ...
4
votes
2answers
77 views

Key error when trying to add a new attribute value to feature - PyQGIS3

I get this error KeyError: 'FieldOne' when I try to add a new attribute value to my feature. This is the code that I use to create a new Layer: v_layer = QgsVectorLayer('LineString?crs=epsg:4326', '...
1
vote
1answer
55 views

Disable anti-alias QGIS?

How to disable anti-alias in QGIS using PyQGIS? I need to create output rasters (tiff / png) which has not used antialised using QGIS Composer / Atlas. Do you have some PyQGIS commands for novice (not ...
0
votes
0answers
53 views

import pyproj in QGIS 3.10.3, ImportError: DLL load failed

When I try in python console to import pyproj with QGIS 3.10.3 in Windows 7, I get the next error: ImportError: DLL load failed I don't get any error with QGIS 3.10.2. I have PROJ 6.3.1 in v3.10.3 ...
1
vote
1answer
45 views

ArcGIS FeatureServer in QGIS plugin

Can someone tell me how to add a ArcGIS FeatureServer to a QGIS plugin? I've found a post here on how to add maplayers which is simple enough but I can't find an description on how to do the same for ...
2
votes
1answer
74 views

Possible to automatically export atlases from QGIS containing PostgreSQL views/tables?

I've managed to export several atlases automatically from QGIS with a Python and a .bat file, see Export several configured atlases with a Python script I'm using QGIS 3.10.2 on a Windows 10 PC and I'...
2
votes
1answer
76 views

Calling a plugin (quickosm) from a python standalone application?

I am trying to call the QGIS-plugin quickosm from a standalone Python application and I´m not quite sure how to or if this is even possible. My QGIS version is 3.10 (using OSGeo4W64) with the ...
1
vote
1answer
46 views

Convex hull for selected features - PyQGIS

I changed the code to create a convexhull for selected features from this question (Convexhull for selected features and performing buffer for the resultant convexhull using python) to adapt it to ...
0
votes
1answer
60 views

Importing CSV as a point layer via the Python console. No point layer is loaded. How can I fix my code?

Code import os from qgis.core import ( QgsVectorLayer ) uri = r"file:\\\C:\Users\imper\Desktop\XYbuffer_tool\Calapan_XYpoints_comma?delimiter={}&crs=epsg:32651&xField={}&yField={}"....
2
votes
1answer
57 views

Display buffer in a new layer - PyQGIS

I'm trying to create a new layer, in which the buffers are displayed. I tried this code, but it does not work. Where is the error? layer = iface.activeLayer() buff_layer = QgsVectorLayer("Polygon?...
0
votes
1answer
49 views

PostgreSQL connection doesn't show up in Data Source Manager

I have data for a PostgreSQL connection. After writing the data in QgsSettings. The connection works but in the Data Source Manager under PostgreSQL connections is nothing documented. After I restart ...
0
votes
0answers
43 views

Creating a points layer from a CSV file with distances along a line, based upon a known vector in QGIS?

I have transect data with know start and end lat/long and length for each transect, which I have made into a vector shapefile in QGIS. I want to add points for each sighting along the transects, which ...
2
votes
1answer
50 views

postProcessAlgorithm in processing algorithm for QGIS 3.10

I've created a processing script in QGIS 3.10, but can't seem to achieve the last step of styling the processed layer. My script follows the new easy processing script format that have come back since ...
2
votes
0answers
27 views

Saving Processing algorithm output to string instead of file.geojson [duplicate]

Is there any way to save processing.run("native:algorithm") output directly to string instead of file or temporary layer? I'm aware of saving output to layer and exporting features using ...
0
votes
0answers
51 views

QGIS parallel processes

I am processing a bunch of GPS data using a Qgis python script. The processing takes a LONG time to execute and when it is executing I notice that only a single CPU is pinned at 100%, the remaining ...
7
votes
1answer
102 views

Generating the skeleton of polygon using PyQGIS

I develop a plugin for my project which includes some useful tools. I reviewed some answers in GIS SE about generating skeleton of polygon. I couldn't find any solution which used PyQGIS. And then I ...
2
votes
2answers
59 views

Hook two horizontal slider each other - PyQt5

In my QGIS Plugin I have this Qt dialog where there are two horizontal sliders. I'm trying to hook one to the other in this way: if the checkBox is checked, I take the difference between them and if ...
2
votes
0answers
25 views

Problem with QgsRasterCalculator.processCalculation() in PyQGIS

I have a really weird problem with a PyQGIS script which use a "for" loop. My script is doing those tasks : Go in a given directory and list all the files with os.listdir Enters a for loop to run ...
1
vote
1answer
65 views

Export/Import a layer as QLR in QGIS 3.4 using PyQGIS [closed]

I am trying to find a way to export a layer in a QLR file in PyQGIS. I want to do the same as right-click and export to layer definition file. I know that I have to use QgsLayerDefinition....
1
vote
0answers
28 views

Setting project QGIS variables with PyQGIS

In a plugin development I have to store in a project variable the plugin version. To test if the variable already exists I wrote: project = QgsProject.instance() scope = QgsExpressionContextUtils....
3
votes
0answers
36 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
1answer
74 views

Connecting multiple polygons with lines using shortest distance as parameter

Is there any plugin in QGIS (or code) that is used to connect multiple polygons with lines using distance as parameter. Let say that I put 10 meters, than all polygons within that distance will be ...
1
vote
1answer
103 views

Using input vector field in QGIS python script

I have created a QGIS Graphic Model using built-in Graphic Modeler. My model is supposed ask the user for an input layer, an overlay layer, and fields from the overlay layer. The model then should ...
1
vote
1answer
30 views

Get layer by name, retrieve layer, in startup.py

I wrote a simple script in startup.py, but when I open a QGIS project, I appear a python error window. The "contratos" layer is a PostGIS layer. But I tried with a regular layer and the error persist....
2
votes
1answer
47 views

QGIS Layer Tree API crashing when removing layer

I'd like to change the order of layers in my layers panel using Python in the Python Console (this is a for a script not a plugin). Following a blog post here on the Layer Tree API for QGIS, the ...
4
votes
1answer
105 views

Passing variable to function when button has been clicked

I want the user to make a selection of a layer from a QgsMapLayerComboBox and setting up their settings they wish to use. After a click on a button, a function should be called which performs the work....
0
votes
0answers
40 views

Intersect lines in QGIS without Processing module

Currently I am able to perform intersection (split line at polygon boundary) between line and polygon using processing module in python script as QGIS module. Now I am interested, if there are another ...

1
3 4
5
6 7
103