I need to create plugin to QGIS that will draw buffers about width equal 1/2 length each line.

Example (my amateur sketch in MS Paint): enter image description here

So, around each lines be created square

I searched good solution but I found only plugin Buffer by percentage (it works only with polygon) and a few threads about buffer around point but it's not enough for me.

Maybe you have an idea how it could be solved?

I don't need all code, I just don't know what I should do now.

  • What's wrong with calculating the length of your line and using a flat cap buffer of width of length/2 ?
    – J.R
    Commented Sep 12, 2019 at 11:29

2 Answers 2


You can use the buffer geoprocessing tool.

Make sure not to enter a fixed distance, but instead to select an expression and to use half the geometry length (length($geometry)/2)

enter image description here

  • Ok, it works if I have a few lines, but I have one polyline. Maybe I should try to split this polyline to lines and later trying this method...and later changing all for code. Thanks very much
    – Robert
    Commented Sep 12, 2019 at 12:27
  • Use processing. You can write simple schema witch input as line, line to segments algorithm and at the end buffer.
    – GSienko
    Commented Sep 12, 2019 at 16:09

I think the provision is already there in QGIS.


  1. Go to Processing > Toolbox
  2. Search for Buffer

This should give you the expected result.

  • On this website don't have anything about percentage buffer. I don't have problem with create buffer about specific distance. I want add line layer as input layer (red line on my picture) and get polygon as output layer (area marked green lines)
    – Robert
    Commented Sep 12, 2019 at 11: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.