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

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.