4

I have a shapefile, which contains track points of a gpx file. Every track point has a number in its "number" field that tells the numeric name of the track the point belongs to. So points are clustered in a way. Unfortunately, there is no information about the order of the points (track segment) in a group. I have an unclear idea of using Python and a nested For-loop but my Python knowledge is super-limited. This VBA-ish method is the way I think it could work (I'm really sorry, I still have a lot to learn)

For n = 1 To 'max number of groups'
    fcount = 'number of features in a group' 
    For m = 1 To fcount
        track_seg = m           #field name where result goes       
    Next m
Next n

And this would be the preferred output in QGIS:

(Number one: start point; last number: end point).

enter image description here

  • The problem description is still unclear to me. Please confirm: 1. In your data, there is no column "track_seg" as shown in the screenshot? 2. You can only rely on the order of features in the attribute table? 3. You want to fill a "track_seg" column based on the order of features in the attribute table? – underdark Mar 26 '17 at 10:55
  • 1) There is a column "track_seg" but it's empty. In this picture, I filled it manually to show the desired output. 2) Yes 3) Yes, and using "number" field, which groups the points. So in group 1: start filling "track_seg" from 1 to n (where n=max number of points in a group; in this case to 5), in group 2: start filling from 1 to n again and so on.. – Skye Mar 26 '17 at 12:17
  • @Skye Does the line in the attached image exist? I mean, do you have a point layer and a linestring layer, or a point layer only? If you have the line, it should be possible doing the task, otherwise I think it won't be impossible establishing which is the point to start from. – mgri Mar 26 '17 at 14:39
  • Both exist. Points are the track points of a gpx and lines are the tracks. – Skye Mar 26 '17 at 15:04
1

I found a solution to my problem, it might be useful in the future for others, too.

Not the most elegant way, but it works:

  • I exported my table to a .csv file. Then, opened it in excel.

  • Track_seg column is from B2 and the groups' column ("number") is from D2. I used this formula in cell B2 and copied down:

    =COUNTIF(D$2:D2,D2)

  • After that I saved this table, returned to QGIS, created a Table Join using ID field and used Field Calculator to populate the appropriate column.

If somebody has a more elegant way of solving, please feel free to share your idea.

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.