# Renumbering a lot of cross sections - Access and changing polyline IDs

I have a poly line shape which represents cross sections along a river. Thses cross sections are numbered and it appears in the map. The numbering happens from downstream to upstream. In a specific point I have to add anew cross section (see Fig 1). Afterwards I have the problem that the cross sections must be numbered from that point to the upstrem (see Fig 2). I have more than 1000 cross sections. How can I do it automatically.  ## 1 Answer

My suggestion is to (1) sort the attribute table of cross sections according to the distance from the river outlet (end point- downstream). and (2) renumber.

Below is just about (1), and more specifically, about the distance of each cross section from the end point of the river. (See red arrows). Please note:

• Your attached picture shows that the river and cross-sections are on the same layer. Please remove the river (sorry...) and move it to a new layer (let's say `river` layer).
• This workflow is for single river. If you have multiple rivers, please repeat the process as per each river (according to `river` and `id`).

Then, given you have:

• Cross-section layer (line strings), and
• `river`: River layer (line strings) with river id (`id`)

Please open the attribute table of `Cross-section` layer and start the Field Calculator to create a new Decimal number field with an expression:

``````distance(end_point(geometry(get_feature('river', 'id',  '1'))),
intersection(geometry(get_feature('river', 'id',  '1')), \$geometry))
``````

This may look complicated, but it is just measuring the distance (`dist()`) between the river outlet (=`end_point()`) and the intersecting point of each cross-section and the river (= `intersection()`).

(The above example is for a case `river` id = 1. If your `river` layer has `uid` starting with `0`, then it will be `get_feature('river', 'uid', '0')` to access the first river).

After getting the distance data, use it to sort the attribute table.

If you are using QGIS 3.0, then `Add autoincremental field` will be useful. Or you may want to use `MMQGIS` plugin (sort function). Anyway, once you have ordered table, giving a sequential number would be relatively easy.

Above, just a partial answer but hope this helps.