Monday, 13 February 2017

Sorting string column Qgis


I would like to order my field like "normal" but as this column is string it won't work. I got "Emplacement réservé 105";"Emplacement réservé 106"; .... before "Emplacement réservé 20".


What should I do? to have Emplacement réservé 10 Emplacement réservé 25 Emplacement réservé 99 Emplacement réservé 105 Emplacement réservé 105


Exemple



Answer



Since QGIS 2.16 you can sort by whatever expression you'd like.


Right click the attribute table header, click on Sort and enter the expression you want.


E.g. extract the interesting part with a regular expression


to_int(regexp_substr("your_column", '.*(\\d+)'))


enter image description here


In earlier versions of QGIS (2.14 LTR) the simplest way would be to create a new virtual field with the above expression and use this for sorting.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...