As of May 31, 2023, we have updated our Code of Conduct.

New answers tagged

2 votes
Accepted

Summing length of lines of a specific category from another layer in QGIS

First solution: use overlay_intersects() I recommend using overlay_intersects() function (available since QGIS 3.16). It is easier to handle when it involves (as here) spatial relationship (take into ...
Babel's user avatar
  • 61.1k
5 votes

Creating hyperlink in the attribute table using QGIS

You need to do the following steps: Add a new field with the name Link or any other name you like, a type of string, and put the length to equal 300 characters since you have long links. Copy the ...
ahmadhanb's user avatar
  • 39.6k
3 votes
Accepted

Creating hyperlink in the attribute table using QGIS

Create a text attribute field, insert the URL. In Layer properties > Attributes Form tab, choose the field, set the Widget type to Text Edit and check the boxes Multiline and html. Open the ...
Babel's user avatar
  • 61.1k
1 vote

Copy/paste the JOIN settings in the layer properties from a layer to another like you do with styles using QGIS

The following PyQGIS code might solve this challenge for you: # Set the original layer containing the join to be copied to other layers sourceLayer = iface.activeLayer() # The join properties to be ...
Cornelis S's user avatar
4 votes

Duplicating rows according to field values in QGIS

The SQLite way, for reference: Unfortunately, SQLite neither supports arrays natively, nor their unnesting into sets of rows. The only, recommended yet slightly cumbersome way is a RECURSIVE CTE: WITH ...
geozelot's user avatar
  • 28.1k
1 vote

Getting dictionary for each feature with their attribute values using PyQGIS

Another solution utilizes the attributeMap() method of the QgsFeature class. Returns the feature's attributes as a map of field name to value. from qgis.utils import iface layer = iface.activeLayer(...
Taras's user avatar
  • 28.9k
2 votes
Accepted

Duplicating rows according to field values in QGIS

Let's assume there is a polyline layer called 'lines' with three features in it, see the image below. Step 1. Duplicate geometries as many times as needed by means of the "Array of translated ...
Taras's user avatar
  • 28.9k
0 votes

Merging Attribute Table Field Values for Same File in QGIS

Be sure to only have the identical layers loaded in the QGIS project as this soultion is based on automatically looping through all layers in the project, using @layers variable (this returns a list ...
Babel's user avatar
  • 61.1k
3 votes
Accepted

Converting column with category names to numeric codes in QGIS Field Calculator

If you have a long list of values and want to avoid adding each one manually, create an array of all unique values with concatenate_unique() and string_to_array(). For each field than check at which ...
Babel's user avatar
  • 61.1k
4 votes

Converting column with category names to numeric codes in QGIS Field Calculator

Try the map() in combination with the map_get() and coalesce(): coalesce(map_get(map('Foo',1,'Bar',2,'Boo',3,'Far',4), "category"), 0)
Taras's user avatar
  • 28.9k
3 votes

Exporting attribute table to CSV via pure Python in QGIS

I use this: import csv outFolder = r'/home/lissiklaus/Downloads/tmp/csv/' filename = 'countries.csv' outPath = f"{outFolder}{filename}" layer = iface.activeLayer() header = [field.name() ...
Klaus's user avatar
  • 307
6 votes
Accepted

Exporting attribute table to CSV via pure Python in QGIS

You can use .getFeatures() to iterate over each feature and .attributes() to fetch each feature's attributes: layer = iface.activeLayer() fieldnames = [field.name() for field in layer.fields()] #If ...
BERA's user avatar
  • 63.9k
0 votes

Use previous entry as default in attribute table

I have the same problem in QField since one of the last updates i guess. but only regarding check boxes when i check a box the next added feature will automatically show the box as checked. Funny ...
Jonas's user avatar
  • 21
4 votes
Accepted

Adding automatic numbering of the "id" field in QGIS

The first feature returns a NULL for maximum("id") as there are no id values to calculate a maximum on. To get around this, use the coalesce() function which returns the first non-null value ...
she_weeds's user avatar
  • 10k
0 votes
Accepted

QGIS form: relation value

Keep the "old" field with the old observers, then create a new field with value relation that you use for new oberservs: those you take with value relation from the table. So you have a ...
Babel's user avatar
  • 61.1k

Top 50 recent answers are included