0

I a trying to segment lines with specific values that are stored in a field. For example, I need my line 1 which is ~84m long, to be segmented into two segment that are 31m and 53m long. I have a layer where I have one feature per line, with its length, and another one where I have one feature for each segment that I would like; like here:

fields

The data is a plantation map from a tree nursery. They lay it basically like "the 15 first trees of the line 1 are from this species, the 25 following are from that species" and I'm trying to "zone" the lines by species.

I don't know which layer I should work with... I tried with v.segment but couldn't get it to work... Any idea?

6
  • 1
    I assume you mean that for line 1, which is 88.664m long, you would like it split into segments that are 31.749m and 52.915m? If so, you should put that in the question. It took me a while to work out, so it's probably going to be hard for others to work out what you are asking. Feb 6 at 22:35
  • Yes it is exactly what I meant, sorry I struggled to put that clearly
    – basile
    Feb 7 at 10:59
  • Check out this question and the comment in relation to linear referencing gis.stackexchange.com/q/475057/98784
    – she_weeds
    Feb 7 at 23:26
  • Are your lines straight or not? Consider posting a sample of data somewhere. Feb 7 at 23:45
  • Yes, all straight lines. Both layers here: filetransfer.fr/download.php?file=LO6T0AQ87R
    – basile
    Feb 8 at 10:05

2 Answers 2

0

It can be done using the Split Lines by Maximum Length processing algorithm. Use the layer that has one feature per line; since you are splitting the lines only in two, you can use either of the 2 possible values in the section field. In the algorithm window, use the data-defined override button to set the Maximum line length parameter to the section field value:

enter image description here

Note: this method on works for splitting the line into 2 inequal parts, or 2 or more equal parts. Splitting into 3 or more inequal parts would require a different solution.

3
  • Yes, I need more than 2 segments for some lines (like the line 2 that has 3 sections)...
    – basile
    Feb 7 at 10:58
  • @basile Well then, that is trickier because then the order of the segments comes into play as well. What determines that order? Say line-2 runs between points A and B, what determines which segment starts at A, which is the middle one and which ends at B? Please try to edit your question and add this info, along with the context of your use-case. That is, what would be the purpose of segmenting the lines? Perhaps there is a different, easier solution that achieves the same result. Feb 7 at 12:22
  • question edited. Let's take an exemple for line 1 : There shoul be 40 trees in total, 25 from species A and 15 from species B. So the "section" field that I have calculated for line 1 is 15/40 from the total length.
    – basile
    Feb 7 at 12:55
0

Update: I managed to do it with the v.segment tools from GRASS. I had issues creating the .txt needed but in the end it did exactly what I needed. So the txt file needs to be ordered that way with Tab separations: L []

here is mine: (the "-" sign is for the segmentation to start at the end node of the line) also the txt file needs to be in a directory with no spaces in the name.

txt file

So the sections after the first one need to be added to the previous, so that the total of the sections is equal to the total lenght of the line.

2
  • It's great to answer your own question, but if you don't explain in more detail then your answer will get marked down. For example, showing a sample of your text file, and describing the issues you had creating it and how you overcame them may help the next person who has this problem. Feb 9 at 23:34
  • edited with the solution
    – basile
    Feb 15 at 10:32

Your Answer

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

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