Tuesday, 21 April 2015

Sorting string column in QGIS Print Composer?


Previously asked a the same generic question (Sorting string column Qgis), but would need to know a solution in Print Composer. A added an atribute table in my print composer, and I need to sort the field.


I would like to order my field like "normal" but as this column is string and it doesn't work out. 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

Answer



Using the integer field you created from your previous question, you can sort the Attribute Table depending on the field by going to:


Item properties > Main properties > Attributes...




Edit:


I can think of a couple of options. The first is to create a virtual field using the answers from your previous question. This is only saved in the project file and not the shapefile itself.


Another method is to add a new field to the Attribute Table from the Print Composer which saves you from adding it to the layer itself and lets you sort your table. To do this:






  1. Go to:


    Item properties > Main properties > Attributes...


    Then click the 'plus' button to add a new column:


    Add field








  1. Highlight the first box in the new row and click the epsilon button:


    Add expression



    Use an expression like:


    to_int(regexp_substr("TXT", 'ER (.*)'))

    Then click OK. The expression will be shown as a heading for the field but you can rename this or set it empty if you so wish.








  1. Then from the Sorting tab, choose the field name with the expression, select how you wish to order it and then click the plus button.



    Add new sorting field







  1. Finall click OK and hopefully your table will include this new field and be sorted accordingly.


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...