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.
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:
And this is how it looks afterwards - the same vertex is double, but got two new index-numbers:
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
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP