1

I have a field with names, a string field, and I want to create another one with serial content following the alphabetical order.

I have this:


|Field1|

| B |

| C |

| A |

| D |

And I want to reach this:


|Field1| Field2 |

| A | 1 |

| B | 2 |

| C | 3 |

| D | 4 |

The MMQGIS plugin offers a tool to sort Shapefiles, but is this operation not possible directly in the field calculator? I'm very interested to know how to make this to make a model in the graphical modeller

asked Apr 12, 2018 at 9:58
1
  • related answer for QGIS3 Commented Apr 12, 2018 at 12:31

1 Answer 1

1

As a workaround for QGIS 2.x, try

  • Toolbox -> QGIS Geoalgorithms-> Execute SQL
    • Additional input datasources -> choose your layer
    • SQL Query -> SELECT * FROM input1 ORDER BY Field1

(This creates a new temporary layer)

  • Field Calculator -> Create a new field -> @row_number

or

  • Layer -> Add Layer -> Add/Edit Virtual Layer

    • Import -> choose your layer

    • Query -> SELECT * FROM <your_layer_name> ORDER BY Field1

  • add @row_number as above

answered Apr 12, 2018 at 13:00
1
  • ...seems odd that I don't know a more elegant solution to this, despite working with QGIS for ages. anybody else? Commented Apr 12, 2018 at 13:14

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.