3

I have a node layer with several thousand points. Each one has a unique attribute "N".

I also have a list of N values which make up the points to which I would draw a line:

19523,19581,19662,19746,11057,19825,19851,19848,19889,11044,24010,24029,24049,24165,24248,24420,24722,24730,24527,24634,24667,27681,24661,25303,24773,24855,24833,24969,24983,25032,25076,300727,25153,300728,28406,300729,28456,300730,28521,28559,25295,28692,28700,28698,28789,28802,28833,28795,28923,29037,29070,25262,25261,29165,29174,29184,25292,29227,29219,29319,10699,29392,29427,10698

I would like to be able to draw a line along the points with the "N" values in the list above.

Is this possible using "Points to Path" or any other geoprocessing tool?

1
  • That should be possible, what format are your points in? Have a read of gis.stackexchange.com/questions/92751/… and group your lines by N value to separate the lines... the only difficulty is if your points aren't sorted you'll get worthless scribbles, if they are sorted (like a GPS track log) then that post should work for you. May 6, 2021 at 7:05

2 Answers 2

5

Let's assume there is a point layer called 'random_points_test', see image below.

input

Here a path using this order 4,8,1,9,2 for the "id"-field will be created.

  1. Apply RMC over the layer > Filter... with "id" IN (4,8,1,9,2) (or "Select Features by Expression")

    step_1

  2. Apply the "Point to Path" geoalgorithm (if features were preselected then tick the 'Selected features only') using array_find(array(4,8,1,9,2), "id") expression in the 'Order expression [optional]'-field and get the output

    step_2

2
  • This was the method I tried in the first instance, but I didn't know I needed to put the +1 on the end of the expression. I don't really understand why this fixes the issue; what is the +1 doing? May 6, 2021 at 23:12
  • 1
    Actually on the step 2, array_find(array(4,8,1,9,2), "id") shall also do the job. I just wanted to go more secured way that is why I added +1.
    – Taras
    May 7, 2021 at 5:47
5

To connect points in the order of a an attribute value, you can use QGIS expressions with either Geometry generator or Geometry by Expression. Use an expression like the following one, where order is the name of the attribute field (your N values). See below if you first have to bring your N values in the correct order.

make_line (
    geometry (
        get_feature (
            @layer, 
            'order',
            order
        )
    ),
    geometry (
        get_feature (
            @layer, 
            'order',
            order+1
        )
    )
)

Screenshot: points are connected based on the value in the order attribute using the expression from above:

enter image description here

If the sequence of the points is not ascending from one to the next number, but quite randomly (as your numbers seem to suggest), than first add another attribute for the sort-order based on the list of the sequence. There are at least two possibilities for this:

  1. You could edit your list in a software like Excel, load it to QGIS and make a table join to your points, based on the N-values as unique id field.

    enter image description here

  2. Based on an array of your ordered N-values (as in your question), use field calculator to identify at what position (index) the respective value can be found: this returns the order in which you want to connect the points:

    array_find (
        array (19523,19581,19662,19746,11057,19825,19851,19848,19889,11044),
        N
    )
    

    Screenshot: points ordered ascending. However, your list suggests that you have a custom defined order to connect the points. The expression from above retrieves the postion of each N value in the sort order (array) and returns this value a new attribute named array_index: enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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