4

I have a line(multiline) layer in QGIS 3.22. I need to place a point in the middle.

I've tried using the algorithms: "interpolate point on line" and "points along geometry", by using as distance the expression $length/2. Both work fine with lines but not with multilines.

Is there any other algorithm or easy way to do it? (I'm not a programmer) Or, how can I convert the multiline to a string line to use this algorithms? (not single lines)

2

1 Answer 1

5

line_interpolate_point($geometry,$length/2), respectively $length/2 should work fine, see:

enter image description here

Note that MultiLineStrings do not necessarily have a logical order of their paths, so the center of it may lay somewhere else than you excpect, just as in my image. The red labels indicate the part number and the arrow the line/parts direction. You could try to combine the order_parts() expression together with the above, if you can find some suiting order logic.

If you prefer single parts you can run "Multipart to singleparts" from processing toolbox.

5
  • In most cases it works fine. Much better than the algorithms in my question. And how to convert the multiline in a stringline?
    – david
    Commented Oct 10, 2022 at 19:01
  • you can run "Multipart to singleparts" from processing toolbox.
    – MrXsquared
    Commented Oct 10, 2022 at 19:03
  • It does'nt work: it converts the multiline to single lines. I need the polyline to work.
    – david
    Commented Oct 10, 2022 at 19:10
  • Please define "stringline".
    – MrXsquared
    Commented Oct 10, 2022 at 19:15
  • Each multiline entity has X segments. When converting with "multiline to single parts" I get X single entities from each multiline. I would need a different kind of entity than the multiline but with the same X segments to work. If the previous is not possible, can you tell me how to use the order_parts() in your previous code?
    – david
    Commented Oct 10, 2022 at 19:20

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.