Is this you? As a journalist, you can create a free Muck Rack account to customize your profile, list your contact preferences, and upload a portfolio of your best work.
Claim your profile
Articles by QgsVector Layer
Changing data source for whole project using QGIS
When I receive a new mapping project, I receive them partly done, my job is to work with an editor to to prepare it for publication. I put the submitted QGZ and GPKG files in a folder called Original (these may be referred to but never modified). I then copy the QGZ and GPKG to a Working folder. Additionally, the original project name is never the name I use because I use the publication number. For example, I receive Toronto.qgz and Toronto.gpkg and put them in the Original folder.
How to save results in script created geopackage
I have a QGIS graphical modeler script. I want to save the results in an empty geopackage (just withone dummy layer). The PyQGIS script below works and creates the wanted geopackage, but now I want to tell the graphical model script I want to save the results in THIS particular file. In the modeler I need to specify the path where is as to be saved. How to link this to the beforehand created geopackage?
Error when exporting multiple shapefiles to GeoPackage using PyQGIS: "Opening of data source in update mode failed (OGR error)"
I'm trying to automate the process of exporting around 20 shapefiles from my QGIS project into a single GeoPackage using PyQGIS.
"Opening of data source in update mode failed (OGR error)" when exporting multiple shapefiles to GeoPackage using PyQGIS
See the following discussion for context: https://github.com/qgis/QGIS/issues/55398. Setting the actionOnExistingFile attribute of QgsVectorFileWriter.SaveVectorOptions to QgsVectorFileWriter.CreateOrOverwriteLayer when the file does not yet exist results in the error you describe.
How do I run GRASS8 in VS Code as part of PyQGIS standalone script?
I'm trying to run GRASS8 in a standalone PyQGIS script. I've imported the QGIS processing, do I need a separate import for GRASS8?
Exporting maps through layout manager with PyQGIS
I took up a challenge, automating many tasks which is repetative, using scripts. I've already managed to achieve minor success in certain processes with the help of ChatGPT (im no programmer). I'm working on a script which loops through all layers (while keeping OSM as a background) and exports these maps (in PDF) using particular symbology. So at the moment, I can do this much with my script.
Run standalone pyqgis script with processing algorithms from external plugins
Some of the external qgis plugins contain processing algorithms integrated by the processing toolbox after installation, e.g. the plugin "Shape Tools". How can the processing algorithms from external plugins be run from pyqgis standalone scripts?
Running PyQGIS processing algorithms within FME PythonCaller
Using FME Form 2024.1.2 and QGIS 3.34.4 with Python 3.9 the following script: import fme import fmeobjects import sys from qgis.core import QgsApplication, QgsVectorLayer, QgsProcessingFeedback class FeatureProcessor(object): """Template Class Interface: When using this class, make sure its name is set as the value of the 'Class to Process Features' transformer parameter.
Crash without error message when creating a QgsVectorLayer in pyqgis
I have a problem with a pyqgis script when trying to create polygon layers from specific gpkg-files. I have four gpkg-files; one containing a point layer, one containing a line layer and two containing polygon layers.
Adding attribute values to existing GeoPackage with PyQGIS
I have an existing GeoPackage and want to copy Features from another layer to this one using PyQGIS and execute it inside a QGIS Macro.
QGIS Python Script for loading MS-Server Tables and create relates and Attribute Form Widgets
I have the following Python script for QGIS3, which is supposed to load spatial and non-spatial tables into a new project. Relationships are then to be set and certain links are to be created in the attribute form. Loading the tables works so far, but I cannot access the relationships (as much as if I drag the tables into QGIS by hand.
Error when using vector layer merge tool in PyQgis: 'incorrect parameter value for LAYERS
I am attempting to use the QGIS tool to merge vector layers and then load the merged layer temporarily in QGIS after running the following Python code. However, I am encountering an error message. Could someone please review my code and identify where I might be going wrong?
Accessing plugins with python within QGIS
I'm trying to access QGIS plugins with python ( Inside of QGIS ), but I'm not getting anywhere. I've tried QGIS documentation I've found nothing, I have just this code snippet trying to access and run the plugin but it always gives me an error in pluginManager.
Amazon Location Service Plugin for QGIS released in OSS
Although I have written a QGIS plugin book and released several QGIS plugins in the past, I enjoyed developing QGIS for the first time in a long time. This is probably the first attempt in the world to develop a QGIS plugin using Amazon Location Service, and I have decided to release this plugin as OSS. This plugin has not yet implemented all the features, but I plan to add more. Location information technology is being used in a variety of fields.
How do I speed up selection of a large number of features
I'm looking for ways to speed up selection of a large number of features (10k+) from a list of attribute values. I'm developing a plugin to trace a pipe network, and select the tranversed pipes. The pipe 'graph' is stored as a LineString layer with PIPE_ID, START_NODE and END_NODE attributes. I have solved the problem of finding PIPE_IDs for the tranversed pipes using a cached graph. The bottleneck appears to be finding the feature IDs of features to select.
Why does PyQGIS start saying roo.children() is empty after a while?
I am working on a small extension to the QgsProject Class.
QGIS Script - Fundamental questions about creating layers
I'm searching all around how to create a new layer on a QGIS Script (that you can add to the tool bar). I see many things that don't work, or work partially, and I can't figure out what types and values are expected. So, regarding the following code where I try to create a new layer from scratch, how can I make it add the layer to the map?
Link my QGIS script with Qt Designer GUI
I would like to create a graphical user interface for my QGIS python script. I downloaded the Qt-designer, but am not sure how to connetc my script from QGIS with the Qt-designer. I would like to create a window where I can choose layers for point_lyr, point_lyr_wgf and polygon_lyr variables.
Iterating over the features of a vector layor then performing zonal statistics algorithm on each feature in pyqgis
I composed this script in pyqgis to perform the zonal statistics on a vector layer as for all its features at once, it works perfectly, when the script is finished, I inspected the attribute table and indeed it is fine for every feature in the vector layor.
Merge road layer.shp and underground bt layer.geojson
I would like to merge a road layer .shp and an btsouterrain.geoson network layer to create a single layer. This will allow me to form a unified network to calculate the shortest path between two points from two different layers of points (PDL and electrical_substation), using the newly merged layer.
Incorrect output when smoothing line that intersects multiline with PyQGIS
I wrote a such script to smooth my line. It checks whether a line of two points intersects the border of a polygon and, if not, then draws a line. This script works well for a simple example, but bad for this example. For some reason it always reduces the line to two points (start and end) and the intersection condition is not met. The boundary line is a Multiline in both cases. Can anyone help me fix the condition so that the script runs correctly?
Exploding lines with PyQGIS
Let's assume there is a polyline layer called 'to_explode' (three features) with its attribute tables, see the image below.
Loading CSV files using PyQGIS
This script works with older version of QGIS but not the latest one. What is wrong with this script? I do not think the space in the directory name is the cause.
SQL Filter WFS layer in QGIS does not work
I added a layer via python from qgis.core import QgsDataSourceUri, QgsVectorLayer, QgsProject dsu = QgsDataSourceUri() dsu.setParam( 'url', 'https://wfs-example-service/a/b/c/wfs' ) dsu.setParam( 'version', '2.0.0' ) dsu.setParam( 'typename', 'Flurstueck') dsu.setParam( 'maxNumFeatures', '10000') dsu.setParam( 'srsname', 'EPSG:25833') dsu.setParam( 'pageSize', '2000') dsu.setSql('SELECT * FROM Flurstueck WHERE st_intersects(Flurstueck.geometry, \'SRID=25833;POINT(-43.23456 72.4567772)\')')...
Converting layer with multiple geometry types into single layers using PyQGIS
There are probably plenty of approaches available to tackle your issue, especially based on pure Python. However, let's stick with PyQGIS and its troubleshooting. The most relevant tool in scope of PyQGIS is the "Filter by geometry type", that filters features by their geometry type and provides outputs based on whether they have a point, line or polygon geometry.
Problem with .bat file executing python qgis script - ModuleNotFoundError: No module named 'processing'
I have created a .bat file as follows: ''' @echo off SET QGIS_ROOT=C:\Program Files\QGIS 3.28.12 SET QT_DIR=Qt5 SET GRASS_DIR=grass83 SET PYTHON_DIR=Python39 call "%QGIS_ROOT%\bin\o4w_env.bat" call "%QGIS_ROOT%\apps\grass\%GRASS_DIR%\etc\env.bat" @echo off path %PATH%;%QGIS_ROOT%\apps\qgis-ltr\bin path %PATH%;%QGIS_ROOT%\apps\grass\%GRASS_DIR%\lib path %PATH%;%QGIS_ROOT%\apps\%QT_DIR%\bin path %PATH%;%QGIS_ROOT%\apps\%PYTHON_DIR%\Scripts set...
_core.QgsProcessingException: Unable to execute algorithm Incorrect parameter value for TARGET_LAYER
I am working on a QGIS plugin using Python with Plugin builder and QT designer with two algorithms inside "Points to Path" and "Append Features to Layer". My plugin takes a CSV and then converts it to a line using "Points to Path" and then I would like to automatically make a connection with my PostGreSQL database and add it to a table. It works well inside the python console but when trying to add this line to my CSR table it keeps failing and I don't know how to parametrize it well.
Adding values to new attribute field fails. How to fix this code?
I have written some code to edit layers in my QGIS project. I now added a new attribute field to my output layer and want to add values to it, which I calculated within the script. Each value is linked to a specific ID in the table of the output layer. I tried many things, but the new attribute field stays empty somehow.
Removing points outside of polygon but keeping points with the same feature ID using PyQGIS
There are some logic omissions and errors in the posted script.
How to make the output from Python appear as a layer in QGIS
I am working a plugin for QGIS, and I've run into an odd issue... My plugin opens and runs without errors, but the layers I am trying to create just don't show up. I tried using this method: viewshed_layer = QgsRasterLayer(viewshed_raster, "Viewshed") if viewshed_layer.isValid(): QgsProject.instance().addMapLayer(viewshed_layer) else: error_msg = "Failed to load viewshed.tif" QgsMessageLog.logMessage(error_msg, "ViewDrone", QgsMessageLog.ERROR) Is that wrong? Or should I look for other errors?
GDAL ViewshedGenerate resulting in TypeError: not a sequence
I am currently working on developing a plugin for QGIS and I keep on running into the same error related to the GDAL command ViewshedGenerate. I've tried multiple different solutions (including setting creationOptions = ['None'] as proposed in a question about a similar error) but so far nothing is working. I've left some of the methods I've tried as comments in the code.
QGIS python: QEventLoop: Cannot be used without QApplication
I am currently reading the PyQGIS Cookbook for developers. While I was reading chapter 5, Using Raster Layers, I had the idea of adding a TIFF file within QGIS project. The TIFF file has the projection EPSG:2964, and my other layers (just one) have the projection 4326.
Read Project File in QGIS Macro
One of the things I really like about ArcGIS Pro is that, when you start a new project, it prompts you to create a new .gdb associated with the project. I'm attempting to replicate this behavior in QGIS by having a macro in a project template - when the template is opened, it should prompt the user for a save location and name, and create a new .qgz project/GeoPackage with the selected name.
IDW processing not running as expected in standalone script
I'm trying to automate idw interpolations from my database using PyQGIS in a standalone script. I copied the python command from the GUI which is how I got the fields I am using for the algorithm.
Specifying categorical symbology in PyQGIS
I have a vector image that is set with a single symbology. I would like to update the file to categorical symbology based on either 1 or 0.
Run QGIS tool from standalone python keeps locks on files
Asked today Viewed 4 times I have a python application that runs some qgis processing tools. The tools are called in a loop and I am looking to clean up the tool outputs (shapefiles) in between each iteration. I have found that only a call to qgs.exitQgis() releases the locks on the shapefile (the output of the snap process). But if I try to do further processing or try to initialize qgis again, the python execution stops, no exception.
Selecting lines of shortest path between two points (QGIS)
I am looking for a method to automatically select the lines of a shortest path between two points. Theoretically it is the Road Graph plugin, which is now the "shortest path point to point" function in QGIS. My problem is that I don't want to create a new shapefile. I want to select the lines in the shapefile I am working with to insert data into the attribute table. How can I solve this problem? I tried using Python, but I am new to Python and the scripts I tried don't work.
For QGIS processing algorithm python scripts, how to limit selectable layers in algorithm input when using @alg decorators
Asked today Viewed 3 times When using the @alg decorator to scaffold a processing algorithm, we use the @alg.input to declare new widgets for the interface. We can declare these as alg.SOURCE for layers we use in the algorithm. Unlike the standard approach, there does not appear to be a place where we can identify allowable geometry types (Point/Line/Polygon) for the layer.
Can't load delimitedtext layer
Asked today Viewed 37 times I am on Linux Debian with Python Python 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] on linux Here is my code : # -*- coding: utf-8 -*- import sys import os from qgis.core import QgsApplication, QgsProject, QgsVectorLayer QgsApplication.setPrefixPath("/usr/lib/qgis/", True) # Initialisation de QGIS app = QgsApplication([], False) app.initQgis() # Obtention de l'instance du projet monProjet = QgsProject.instance() mypath = os.path.join('/home/toto/',...
Using polygon fill code in PyQGIS
Integer division truncates rows and cols rows = int(ymax - ymin)/spacing_y # Python 2: int division; Python 3: still float after int() The int() wraps only ymax - ymin, not the division result. In Python 3 this gives a float anyway. Should be: rows = int((ymax - ymin) / spacing_y) cols = int((xmax - xmin) / spacing_x) range() requires an int, but rows/cols may be float Follows from the above range(rows+1) will throw TypeError in Python 3 if rows is a float.
Problem with UI at my first simple qgis plugin
Asked today Viewed 5 times I am trying to develop my first simple qgis plugin, which just loads all shapefiles from a folder into the current project by opening a window and click there a button "import". the importing does work, if i click the thumbnail of the plugin in the qgis toolbar. But it does not open the user interface with my created button in qt designer. What am I doing wrong?
Qgis / PyQGIS automatically loading layers on startup (problem)
Asked today Viewed 3 times I made a small code to fetch some PostGIS layers into QGIS and apply them with qml style, like the following: import os from qgis.core import QgsVectorLayer, QgsDataSourceUri, QgsVectorLayer, QgsProject uri = QgsDataSourceUri() uri.setConnection(#CONN_INFO) city_filter = 'Cairu' uri.setDataSource("public", "dende_mp", "geom", f"nom_munici = '{city_filter}'") vlayer = QgsVectorLayer(uri.uri(False), f"car_{city_filter}", "postgres")...
How to Add a Feature class from a Geodatabase to Qgis using Pyqgis
Asked today Viewed 3 times Banging my head against the wall on this one: I've tried this method: (Adding feature class within file geodatabase in QGIS with Python?) uri = "C:/Temp/my.gdb|layername=fcName" layer = QgsVectorLayer(uri, "layer_name_you_like", "ogr") QgsProject.instance().addMapLayer(layer) and adding it as a default value: self.addParameter( QgsProcessingParameterFeatureSource( self.INPUT, self.tr('Input layer'), [QgsProcessing.TypeVectorPolygon],...
How to batch import .xyz files in Qgis?
Asked today Viewed 4 times I have about 200 .xyz files I want to import into my Qgis project. I've tried using this answer https://gis.stackexchange.com/a/310415 but haven't been able to make it work. I'm getting this exec(Path('C:/Users/AppData/Local/Temp/tmp8k1lnjji.py').read_text()) as an output and no error messages so it seems like Qgis is reading my files but not doing anything with them?
want to organize the fields with lable in Attribute table without changing in layer data in qgis using python
Asked today Viewed 4 times from qgis.core import QgsProject, QgsVectorLayer # Load the layer layer_name = 'fibre' layer = QgsProject.instance().mapLayersByName(layer_name)[0] # Define the desired field order field_order = ["CABLE_OWNER", "NETWORK_LEVEL", "PROJECT_NAME", 'PLANT', 'UPRN_ADDRESS'] # Create a new field list with the desired order fields = [layer.fields().field(field_name) for field_name in field_order] for field in layer.fields(): if field not in fields: fields.append(field) #...
Data Interoperability Tools Arcgis Pro
Explore data interoperability tools in ArcGIS Pro for seamless integration and enhanced data management capabilities. The framework for autonomous intelligence The Spatial Analysis Toolbox in ArcGIS Pro provides a comprehensive suite of tools designed for advanced geospatial analysis. This toolbox includes both built-in and customizable geoprocessing tools that cater to a wide range of analytical needs. Built-in Tools ArcGIS Pro offers a variety of built-in tools that facilitate spatial analysis.
Python Gis Tools For Data Analysis
Explore essential Python GIS tools for effective data analysis, enhancing your data visualization and spatial analysis capabilities. The framework for autonomous intelligence QGIS is a powerful open-source GIS platform that provides extensive capabilities for managing, analyzing, and visualizing geospatial data. The spatial analysis toolbox within QGIS is a comprehensive suite of tools designed to facilitate various geoprocessing tasks, including spatial analysis and raster processing.
Show More
loading
Actions
Is this you?
As a journalist, you can create a free Muck Rack account to customize your profile, list your contact preferences, and upload a portfolio of your best work.Get in touch with QgsVector
Contact QgsVector, search articles and posts on X, monitor coverage, and track replies from one place.
Learn more about Muck Rack