7 votes

Calculating two columns at once in QGIS

QGIS has an algorithm for that : Statistics by categories (official documentation) You have to select your layer, your category field (here "Cover") and the field to calculate statistics (...
user avatar
  • 11.8k
6 votes
Accepted

Using QGIS field calculator to create an 'fid' column according to a value from another column

Hacky solution using the field calculator: array_find( array_agg( expression := to_int(substr("Row name", 5))*10*maximum("Col")+"Col", order_by := to_int(...
user avatar
  • 23.3k
5 votes
Accepted

Displaying milliseconds in Attribute Table using PyQGIS

The comment by @Matt was already pointing in a correct direction. QgsDateTimeFieldFormatter is indeed needed to modify the display of DateTime values. The following code example replaces the default ...
user avatar
  • 1,454
5 votes
Accepted

Converting number with leading zeros in integer in QGIS

Try this expression with the to_int() function: to_int("baumnummer") -- to_int('000001') -> 1 If you wish to maintain the string field type, you could expand the expression above with ...
user avatar
  • 23k
4 votes
Accepted

Converting text field with special characters to field with floats in QGIS

regexp_substr( "stringfield", '(-?\\d+\\.?\\d*)') https://www.tutorialspoint.com/How-to-extract-numbers-from-a-string-in-Python
user avatar
  • 51.4k
4 votes
Accepted

Is there non spatial Virtual Layer in QGIS?

As was mentioned by @J.Monticolo in his comment it is possible to exclude the geometry simply by choosing 'No geometry' in the 'Geometry' tab Also as was mentioned by @MrXsquared in his/her comment: ...
user avatar
  • 23k
4 votes
Accepted

Renaming categorical attribute values in QGIS attribute table: merge two different strings to the same name

Just run Field calculator, update the field by typing this expression: if ( "Species" in ('DD', 'Delphinus Delphinus'), 'Delphinus Delphinus', "Species" ) Here I ...
user avatar
  • 40.1k
2 votes

Counting number of selected features in QGIS

This works fine for me: from qgis.core import * import qgis.utils layer = iface.activeLayer() features = layer.selectedFeatures() print ("Total count", layer.featureCount()) print (...
user avatar
1 vote

Merging Attribute Table Field Values for Same File in QGIS

one way to do this is to concatenate fields together in the QGIS Field Calculator, using the following equation: "field1" || "field2" or to put a space between your fields: &...
user avatar
1 vote

Categorizing field and summing attributes for label in QGIS

Use QGIS expressions with the aggregate function sum(), grouping it by the common part of the "CFSAUID" attribute. For this, define an expression that returns this common part, here ...
user avatar
  • 40.1k
1 vote

Counting number of selected features in QGIS

There are several methods that I may refer you to: 1. Press Shift + F6 to open attribute table with selected features only. There will be two values that represent the number of selected features: '...
user avatar
  • 23k

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