TransWikia.com

Number a point layer starting from the furthest north point following a linestring

Geographic Information Systems Asked on July 18, 2021

How can I number a point layer starting from the furthest north point following a linestring clockwise? In the image bellow I have two layers, a line layer and a point layer, and how I would like to number it. Is there a way to do it? My knowledge on virtual layers are very limited to find a solution.

enter image description here

One Answer

You can use an expression to create a new field with field-calculatot that re-counts the vertices, creating a new index, starting from the northernmost point (see at the bottom for explanation). Use this expression to create a new field named, let's say, index_new:

if (
    vertex_index < 
    aggregate( 
        @layer, 
        'max',
        vertex_index,
        $y = maximum( $y)
    ),
    vertex_index + ( aggregate (
        @layer,
        'count',
        vertex_index
    ) - aggregate ( 
            @layer, 
            'max',
            vertex_index,
            $y = maximum( $y)
    )),
    vertex_index - aggregate (
        @layer, 
        'max',
        vertex_index,
        $y = maximum( $y)
    )
)

Original setting - be aware that in my case, I had a closed line with identical start- and end-points, so one vertex is double:

enter image description here

And this is how it looks afterwards - the same vertex is double, but got two new index-numbers:

enter image description here

Explanation: To calculate the vertex_index-no of the northernmost point, use an aggregate function. The function looks in the current layer (@layer)for the maximum value ('max') in the field vertex_index but limited to the case where the y-coordinate ($y)corresponds (=) to the max. value of all y-coordinates (maximum( $y)):

aggregate( 
    @layer, 
    'max',
    vertex_index,
    $y = maximum( $y)
)

Than calculate the number of vertices you have, using again aggregate:

aggregate( 
    @layer,
    'count',
    vertex_index
)

Now you can combine both with an if-condition: for vertices with indices smaller than the northernmost point and for all other points.

Correct answer by Babel on July 18, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP