Skip to main content

All Questions

Tagged with or
Filter by
Sorted by
Tagged with
10 votes
2 answers
4k views

Reprojecting layer using PyQGIS

I'm trying to find a very simple solution to reproject a vector layer into a temporary layer in PyQGIS, however documentation is really extensive and I'm fairly new to PyQGIS; the only answer I've ...
Elio Diaz's user avatar
  • 3,528
10 votes
3 answers
10k views

Using QGIS Zonal Stats Plugin from Python Console?

I am using the Zonal Stats plugin in QGIS to extract raster statistics from overlaying polygons (I have shapefiles of species distribution and I want to extract environmental data from within each ...
Thomas's user avatar
  • 567
10 votes
2 answers
2k views

Setting QGIS to "show feature count" always when layer is loaded?

I am using QGIS 3. I know that i can right click the layer and check the "show feature" option but is it possible to show enable this function by default when any layer is loaded ? I know that we ...
Abhijit Gujar's user avatar
10 votes
1 answer
201 views

Explaining long computing time of Python code

I have a Python code adding information to a layer if its features are overlayed by other features. The base layer has 1200 features and is 10 MB. The 4 layers for the overlay have roughly 40 MB ...
MrSalamikuchen's user avatar
10 votes
1 answer
1k views

Selecting features with equal field value interactively on QGIS map

Is it possible to automate the following procedure with graphical modeler in qgis 3.4 or is it easier to perform such action with a python script using PyQGIS? Identify a feature (a line) in a vector ...
Alexander's user avatar
  • 113
10 votes
1 answer
16k views

Removing a vector layer from QGIS [duplicate]

Considering my program is generating a shapefile that has to be added to the "Layers" tab in QGIS interface. However, once the utility of the layer is completed, I need to remove the layer in the ...
Akhil's user avatar
  • 1,445
10 votes
1 answer
4k views

Getting canvas' extent coordinates using PyQGIS

I'm trying get the extents of the current map canvas. CRS is 22700 BNG. My code: canvas = iface.mapCanvas() print(canvas) vLayer = iface.activeLayer() extents = vLayer.extent() print(extents) Which ...
Ben Mayo's user avatar
  • 955
10 votes
2 answers
6k views

Returning latitude and longitude of point using PyQGIS [closed]

I have a point layer, that I'd like to return the Longitude, latitude using the PyQGIS. How do I use QgsPoint to do that?
dassouki's user avatar
  • 8,563
10 votes
3 answers
17k views

Loading raster layer in a standalone PyQGIS script

I need to load a raster file from the provided file path. I wish to use it further in the Raster Calculator. I wrote a function which converts string (I assume it is a file path) to a raster object. ...
matandked's user avatar
  • 681
10 votes
2 answers
6k views

Does mapCanvas().refresh() not work in QGIS 2.6?

Before I used the function qgis.utils.iface.mapCanvas().refresh() to reload the map canvas after for example a layer color was changed from a plugin. But this is not working with QGIS 2.6 for me. ...
Martin's user avatar
  • 2,918
10 votes
3 answers
6k views

Is it possible to change legend symbols in the QGIS print composer legend?

I have some layers with very complex data-defined symbols. If I use a legend in the print composer these symbols are not drawn correctly. Is there a way to change the legend-symbols with pyqgis, so I ...
Thomas B's user avatar
  • 8,936
10 votes
1 answer
1k views

Selecting column like Primary Key in View from PostGIS using PyQGIS?

Postgresql doesn't support Primary Key in views. When I load a postGIS view in QGIS "manually", I can choose the column that will be the Primary Key, but I would like to know if I can select a column ...
exodehm's user avatar
  • 939
10 votes
1 answer
1k views

Is it possible to have dynamic layer names in QGIS project?

I have a QGIS project with layers, based on PostGIS SQL queries that use current date. Since the data in the database changes, these queries return different data every new day. Is it possible to ...
mofoyoda's user avatar
  • 893
10 votes
1 answer
18k views

Getting feature count of QgsVectorLayer using PyQGIS?

I'm using this code to get features from QgsVectorLayer QgsVectorDataProvider* provider=theVectorLayer->dataProvider(); if(!provider) { return; ...
bossman's user avatar
  • 233
10 votes
2 answers
9k views

How to compile QtDesigner user interface (.ui) and resource (.qrc) files with QGIS 3 on Windows?

I tried to transpose the QGIS 2 process with no success. I first had to edit C:\Program Files\QGIS 2.99\etc\ini\python-core.bat which contains references to Python27 instead of Python36. I run C:\...
sigeal's user avatar
  • 879
10 votes
2 answers
899 views

QGIS crashes when doing a rollback after modifying values of an user-added feature with pyQGIS

I'm developing an addon for QGIS that needs to assign a UUID to any feature as soon as it is added to the layer. I'm using the featureAdded signal to write the UUID in the corresponding field of the ...
mhm's user avatar
  • 281
10 votes
1 answer
704 views

How to create a geometry generator symbol using PyQGIS

I am trying to use PyQGIS to convert a Fill Symbol Layer into a geometry generator Symbol Layer in a rule-based renderer with 300 rules. I am able to iterate over the rules and return each rule's ...
Alexandre Neto's user avatar
10 votes
4 answers
2k views

Is there is a signal in QGIS when a project is about to be closed?

Is there is a signal in QGIS emitted when a project is about to be closed (QGIS closing or some other project opening)? I want to programmatically save changes in layers if they are in edit mode.
Феус Боок's user avatar
10 votes
1 answer
1k views

Exposing variables to the Python Console from Plugin in QGIS

I have a QGIS plugin that performs a long-running operation, eventually producing and loading new shapefiles into QGIS. (I have this as a plugin rather than just a function that can be called from the ...
ajd's user avatar
  • 265
10 votes
1 answer
2k views

Getting log message from QGIS processing framework?

I run Python processing algorithms externally, and I want to get the log output I see when I run it from the QGIS 3 GUI at the log tab as shown in the screenshot: I want to get the full grey log ...
ODstuck's user avatar
  • 661
10 votes
1 answer
684 views

Programmatically turn on/off panels with PyQGIS

In QGIS, with right-click somewhere in the toolbar area panels can be toggled on/off like shown in the screenshot below (the GPS Information Panel for instance). I need to do this programmatically, ...
Jochen Schwarze's user avatar
10 votes
1 answer
2k views

Register custom qgsfunction in pyqgis

I'm using pyqgis within an standalone application. Now I wanted to create a custom expression to to use as filterExpression in rule of ruleBasedRendererV2. (I tried the renderer with existing ...
Henhuy's user avatar
  • 906
10 votes
2 answers
7k views

Creating memory layer and populate fields using PyQGIS

Seems like a basic operation using PyQGIS but can't see what I am missing. I want to create a memory layer with the exact same features and attributes from a shapefile. I have looked several posts ...
Joseph's user avatar
  • 76.3k
10 votes
1 answer
6k views

Using in-memory vector layer with QGIS processing / SEXTANTE

I'm trying to run the qgis:clip algorithm from console, but am getting an error when using an in-memory layer as the overlay parameter. Is this to be expected, or am I doing something wrong? Code: ...
user avatar
10 votes
1 answer
15k views

Why can't I import my script from the python console?

i am working with the qgis python console. I usually store all my python scripts into ~/Scripts/python I do have set the PYTHONPATH to ~/Scripts/python in my .bashrc However, I can not manage to ...
Renaud's user avatar
  • 871
10 votes
1 answer
3k views

Method for generating wedge buffer in PyQGIS

Is there any method generating a wedge buffer, as in Creating wedge buffers from many to one in QGIS, using QGIS Python API? I made a search in QGIS API Documentation and GIS SE. I'm not looking for a ...
Kadir Şahbaz's user avatar
10 votes
1 answer
3k views

Listing project layers in standalone PyQGIS script

I'm trying to load an existing .qgs project and get a list of the layers inside. I seem to be able to open the project, but I can't get the list of layers. I'm a little confused as to the basic PyQGIS ...
KJYDavis's user avatar
  • 693
10 votes
1 answer
7k views

When iterating over a vector layer with pyqgis, how do I check whether a feature is selected?

While iterating over a vector layer using the following code (summerized from the example in the pyqgis cookbook), is there a way to check whether a feature is selected? provider = vlayer....
Cyrus's user avatar
  • 1,498
10 votes
1 answer
3k views

Selecting subgroup in Layers panel using PyQGIS

I can select a group layer (for example C) using the following script. But I can only select groups in root level (A or C). I am struggling to select subgroups. I play with the script, but no success. ...
Kadir Şahbaz's user avatar
10 votes
1 answer
3k views

Adding PostGIS layer from QGIS Python plugin

I try to develop a plugin to add postgis layers to qgis from a plugin as part of learning python. The code for adding a postgis layer is taken from the cookbook and work fine if I run it from the ...
geogrow's user avatar
  • 1,765
10 votes
2 answers
1k views

Closing attribute table with PyQGIS

I have a QGIS 2.18.0 plugin which updates a join between two layers (spatial and non-spatial layer). QGIS crashes when I run the plugin and the attribute table of the joined layer is open. There is no ...
Stefan's user avatar
  • 4,474
10 votes
1 answer
3k views

Automatic pyqgis categorized renderer classification [duplicate]

I have some layers in my project and I would like to alter their styles, since ranges of values for underlying columns have changed. Normally it would require to enter each layer style settings ...
wastek's user avatar
  • 303
10 votes
3 answers
10k views

Setting the extent for a QGIS map using python

I am writing a stand-alone application in Python/QGIS that simply creates maps. I want to load vector/raster layers, set symbology, set extent At the moment, that is all! Currently I am just using ...
Becky's user avatar
  • 637
10 votes
1 answer
2k views

Zooming feature without selecting it using PyQGIS

When I need to zoom to a feature, I have to select it first using layer.select(feature.id()) then I can zoom using mapCanvas.zoomToSelected(layer). layer = iface.activeLayer() layer.select(1) iface....
Kadir Şahbaz's user avatar
10 votes
1 answer
3k views

Accessing iface PyQGIS API from Standalone Python script (outside QGIS environment)?

I want to call PyQGIS API from my standalone Python script, outside QGIS environment. I can not, as 'iface' is not available. I have done necessary import / initialization : from qgis.core import * ...
Krisanu Roy's user avatar
10 votes
1 answer
4k views

Creating raster layer from numpy array using pyqgis?

I am working on a plugin for Qgis to calculate spatial Kernel density maps. I have all the calculations working, all I am missing is a way to turn a Numpy Array, with density values into a multiband ...
fccoelho's user avatar
  • 1,247
10 votes
2 answers
4k views

processing.getObject() in QGIS 3

It seems that processing.getObject() is no longer available in QGIS. from PyQt5.QtCore import * from qgis.core import * #... layer = processing.getObject(layer) # -> ...module 'processing' has no ...
Lunar Sea's user avatar
  • 2,016
10 votes
2 answers
1k views

Switch QGIS proxy settings programatically

I am using QGIS at two offices with different proxy-servers. At the moment I have to change the proxy settings manually every time i switch the office. I was wondering if its possible to change the ...
Thomas B's user avatar
  • 8,936
10 votes
1 answer
3k views

Passing Geometry object to processing tool instead of Layer

In ArcPy, you can pass a geometry object as parameter to geoprocessing tool: import arcpy coordinates = [[20, 30], [30, 30], [30, 20], [20, 20]] array = arcpy.Array([arcpy.Point(x, y) for x, y in ...
Kadir Şahbaz's user avatar
10 votes
1 answer
2k views

Splitting lines/creating vertex at intersection using PyQGIS?

I am looking for an easy way or function to split 2 previously selected line features (generate vertex) at intersecting points (or touching points). See the following picture: I am developing a ...
akgis's user avatar
  • 101
10 votes
5 answers
1k views

Minimum wall-thickness of a non convex polygon with holes

What is the most efficient way to find the minimal wall-thickness (value and location) of a complex, non convex polygon area including holes? See example of a polygon in blue, with the minimum wall-...
Oliver Staubli's user avatar
10 votes
0 answers
378 views

Defining partial or complete overlap with QgsSpatialIndex

I'm working on adding some functionality to a QGIS plugin. It currently uses a QgsSpatialIndex to efficiently compute whether the features of a vector layer intersect (potentially millions) of ...
alphabetasoup's user avatar
10 votes
0 answers
5k views

QVariant is not defined when using addAttributes [closed]

When I try to add a field programmatically with the following code: import os.path from PyQt4 import QtGui, QtCore legend = qgis.utils.iface.legendInterface() allLayers = legend.layers() for i in ...
Jon Gottsegen's user avatar
9 votes
5 answers
3k views

Getting user's QGIS version using PyQGIS

I am trying to write a QGIS plugin, which should work on QGIS 2 and QGIS 3. How can I find out which QGIS version the user is using, so the right imports are made?
Blinxen's user avatar
  • 723
9 votes
3 answers
35k views

Change Shapefile data source encoding?

I tried to change the only the shapefile datasource encoding through properties and also How to encode shapefiles from LATIN1 to UTF-8? but it doesn't change it. Without saving the QGIS project can'...
Muhammad Faizan Khan's user avatar
9 votes
2 answers
11k views

Activating layer by its name in PyQGIS

I'm writing a script that requires the attributes of different layers to work, and I would like to know how to call a layer that is not the currently active one and get its features. For example, I ...
PabloQG's user avatar
  • 309
9 votes
3 answers
5k views

Getting number of features in the Attribute table using PyQGIS

I have a layer and I would like to access the number of rows the attribute table has from my code. Is there a way to do that without doing it like this: num_of_features = 0 for feat in layer....
Adrian's user avatar
  • 91
9 votes
3 answers
8k views

Accessing attribute data type in PyQGIS

I've been developing a Plugin on the QGIS platform using PyQGIS. So far plugin does the following: You can select any feature of the already loaded vector layer in QGIS. After selection, the plugin ...
kyuss's user avatar
  • 155
9 votes
3 answers
2k views

Getting provider name of layer using PyQGIS

In QGIS 3.16.5-Hannover, with PyQGIS I want to get the provider name of a selected layer. I need to know if it's an ESRI Shapefile layer or a PostGIS layer for example. I don't see how to get this ...
GeoGyro's user avatar
  • 1,656
9 votes
4 answers
20k views

Deleting variables from the Python Console in a programmatic way?

I often use the Python Console for running some lines of code and I also use some prints for checking the validity of the results. If I run this sample code: a = 2 b = 4 res = a + b print res it ...
mgri's user avatar
  • 16.3k

1
3 4
5
6 7
158