A very, very FAST and easy method to sort a shapefile layer( using various fields) .
1 - Export shapefile to CSV (select good separator, like semicolon) and add GEOMETRY using "layer options" -> "AS WKT"
2 - Open file.csv with LIBREOFFICE (calc) and use MENU->DATA->SORT (very intuitive, powerfull and VERY FAST (Sort on the fly 50000 features using 3 columns like sort-key, ascending and descending options, and i have a very slow notebook ;) )
3 - Save again file from LIBREOFFICE (calc) as "Text CSV" ( mark "Edit filter settings" and choose separator as 'semicolon', don't matter warning from libreoffice, save like CSV and select 'semicolon' as separator )
4 - From Qgis open the new file.csv (and sorted) from 'Add Layer" menu -> Add Delimiter Text Layer.
PROS:
- Very,very fast, sort from various fields
- Works ok with UTF_8 encoded data
CONS:
- Need LIBREOFFICE (but is it open source software)
Alternative method to sort (sustitute points 2 and 3, and is the most fast) using console (BASH)
Open console and go where you have file.csv
Suppose you want sort file with the key:
field6(desc)+field1(ascen)+field3(desce)
so the command will be:
sort -t';' -k6,6r -k1,1 -k3,3r file.csv > file_sort.csv
NOTES:
- you can add -kn,n for every column number 'n' (field) you needed add to your "sort key"
- adding 'r' after every n,n will sort in reverse mode (descent)
- Must pass the character separator used into csv file with -t param