Hot answers tagged

21 votes
Accepted

Showing the number of currently selected layers in QGIS

You can use this script. It adds a toolbar as seen in the image and shows how many layers are selected. label = QLabel("Selected Layers Count:") count = QLabel() tree_view = iface....
Kadir Şahbaz's user avatar
15 votes

Showing the number of currently selected layers in QGIS

To extend the great solution by @Kadir Şahbaz, you could do something like this to get a count per group: p = QgsProject.instance() root = p.layerTreeRoot() view = iface.layerTreeView() ## TOOLBAR tb ...
Matt's user avatar
  • 14.2k
11 votes
Accepted

Adding different types of geometry to layer in QGIS

If you mean adding them to a QGIS layer, the answer is 'No'. It is not possible. This is the nature of the QGIS layer. But somehow (maybe by a script) you may export layers, which have different ...
Kadir Şahbaz's user avatar
11 votes

Rotating features with multiple geometries in one layer using PyQGIS

There are several things that I would improve: do not forget to start/startEditing, end/endEditCommand(), and commit/commitChanges() editings use the setGeometry() method properly, otherwise the ...
Taras's user avatar
  • 29.9k
10 votes
Accepted

Hiding/showing layers in legend does not work in QGIS standalone

QgsLayerTreeMapCanvasBridge must be in global scope. But you define bridge in add_legend method's scope. Therefore, variable bridge is gone after add_legend finished. One of the solutions: Add bridge ...
Kadir Şahbaz's user avatar
10 votes

Points not showing on map on QGIS

Look at the layer's order, it is because OpenStreetMap layer is covering everything. Just drag down the OpenStreetMap to the bottom of the layer list. It should fix your problem.
GforGIS's user avatar
  • 2,430
9 votes
Accepted

Zooming to each vector layer extent, one at a time, using PyQGIS

You can solve your issue using QTimer which controls when to execute functions and it's asynchronous, i.e., it allows other functions to continue to run (think of a map.refresh()) while waiting some ...
Kadir Şahbaz's user avatar
8 votes
Accepted

Copying layer styles using PyQGIS

You could use the setActiveLayer() method of the QgisInterface class. One way to set up an iterable object containing source and destination layers is to use a list of sub-lists or tuples, where the ...
Ben W's user avatar
  • 20.2k
7 votes
Accepted

Exporting selected attributes to Excel from specific layer using PyQGIS

No need to programmatically select your layer in the layers panel- you can access the layer you want to export simply by its name. To export the layer to a .xlsx, you can call the 'Export to ...
Ben W's user avatar
  • 20.2k
7 votes
Accepted

Filtering Data to Categorize Points in QGIS

For use of 'NULL' you will need to use 'IS' not '='. Your query will become: if("FIELD C" IS NULL,1,2)
Cushen's user avatar
  • 2,843
7 votes

Adding non-spatial SQLite query to QGIS

There are at least four options: the three options before loading the data as a layer, the last one after the layer is loaded. Option 1: Data source Mananger Filter Use Data Source manager to load ...
Babel's user avatar
  • 63.1k
7 votes

Changing feature in one layer with feature from another layer in QGIS

You can select the feature, then choose Edit > Copy Features and paste it in the target layer with Edit > Paste Features. Ensure the target layer has editing enabled. As @J.R commented, delete ...
Matt's user avatar
  • 14.2k
7 votes

Generating geodata models for layers and their attributes in QGIS

Here is an automated solution that requires no expression and no manual intervention. It makes pages and adds necessary text as HTML table to the related pages automatically. Just change LAYOUT_NAME. ...
Kadir Şahbaz's user avatar
6 votes
Accepted

QGIS delimited text layer is not visible

You have the X (longitude) & Y (latitude) coordinates reversed. And the coordinates are DD (decimal degrees) not DMS (degrees, minutes, seconds)
user2856's user avatar
  • 64k
6 votes

Getting field names of layer using PyQGIS

Another approach is to use the attributeAliases() method: Returns a map of field name to attribute alias. from qgis.utils import iface layer = iface.activeLayer() field_names = list(layer....
Taras's user avatar
  • 29.9k
6 votes
Accepted

Changing columns position in attributes table using PyQGIS

The order of the fields must be ordered in the qml file as in the second example. If you add the file RBAL_BYSAT_TEMP.shp to QGIS by drag-and-drop you will see that the order is as you want. Applying ...
Kadir Şahbaz's user avatar
6 votes

Separating columns of layer and exporting set of columns in a new QGIS layer

If its only a few and automating it is too much hassle, use Layer... Save As.. and choose a name and select the columns you want to save in the dialog:
Spacedman's user avatar
  • 61.5k
6 votes

Rule-based parent child symbol layer view in QGIS

Sort of workaround solution: Create a Virtual layer through Layer > Add Layer > Add/Edit Virtual Layer with the following SQL code : WITH RECURSIVE org(fid, unit, parent, level, geom) AS ( ...
J. Monticolo's user avatar
  • 15.5k
6 votes
Accepted

Rule-based parent child symbol layer view in QGIS

A very interesting questions, that no doubt is beyond built-in functionality. I would split this problem in to 3 parts. To go from your data to a structure that is appropriate for a rule-based tree ...
Mathias's user avatar
  • 247
6 votes

Prioritise label by field containing data importance in the data QGIS

You need to use data-driven label priority, in the layer's Label settings, Placement sub-tab. There's a slider for Priority there which sets priority for all the label of the layer, but to its right ...
Houska's user avatar
  • 7,678
6 votes

Activating two layers at the same time with PyQGIS

The best way to work with any non-trivial implementation of a QgsMapTool is to create a sub-class. Below is a fairly minimal example. The way this deals with changing between source and target layers, ...
Ben W's user avatar
  • 20.2k
6 votes
Accepted

Using QGIS Geometry Generator to create labels between associated features in different layers

Prerequisite For this solution to work, the point layer must have a field (in this example called buffer_id) that contains the id of the joined buffer polygon. The solution was implemented in QGIS 3....
Matt's user avatar
  • 14.2k
6 votes
Accepted

Performing the same mathematical operation on many attributes at once with QGIS

Another option is to use Menu Processing > Toolbox > Refactor Fields. In the field Source Expression, include your mathematical operation. In the field "Name", you can change the field ...
Babel's user avatar
  • 63.1k
6 votes
Accepted

TypeError when extracting vertices based on selection in QgsProcessingFeatureSourceDefinition using PyQGIS

I could get the same error: Traceback (most recent call last): File "C:\PROGRA~1\QGIS32~1.0\apps\Python39\lib\code.py", line 90, in runcode exec(code, self.locals) File "<...
Taras's user avatar
  • 29.9k
5 votes
Accepted

Exporting points as points, text as text (when exporting to svg)

You have to set this while exporting to SVG: Then after opening the SVG in AI you have to ungroup the exported text and points:
eurojam's user avatar
  • 9,530
5 votes
Accepted

QGIS Reproject a set of points in CSV to another CRS

Load the csv as a Delimited Text As mentioned in the comments by J.R. - Do some visual checks if the data is where it should be - if they are off check the CRS or if Lat/Lng are swapped etc. Export ...
Bernd Loigge's user avatar
  • 2,191
5 votes

How to export layer without losing formatting in QGIS

You can also save your data in a geopackage. In a geopackage, you can also save the symbology of the layers. So at the end, your colleagues just need to open the layer, and the default symbology is ...
katagena's user avatar
  • 1,544
5 votes

Reprojecting layer using PyQGIS

If you do not want to use Processing Tools you can do it like: layer = iface.activeLayer() source_crs = QgsCoordinateReferenceSystem(layer.crs().authid()) target_crs = QgsCoordinateReferenceSystem(&...
MrXsquared's user avatar
  • 32.6k
5 votes
Accepted

Interactively create route that snaps to route layer in QGIS

QGIS has en editing tool call Automatic tracing. Here the documentation section of this tool : Enable the Tracing tool (in the Snapping toolbar) by pushing the icon or pressing T key. Snap to a ...
J. Monticolo's user avatar
  • 15.5k
5 votes

Interactively create route that snaps to route layer in QGIS

Expanding the solution by @Dror Bogin you can use this expression together with array_foreach() to include not just two points, but any number of points - in the following example points 1 to 9 (first ...
Babel's user avatar
  • 63.1k

Only top scored, non community-wiki answers of a minimum length are eligible