I would like to calculate the distance between two lines and update this value to the attribute table of one of the line layers.So the mean distance between the blue lines and each of the red line segments in the following image: enter image description here

I have tried solving this with v.distance from GRASS. I have created the two following columns in the attribute table of my red lines: enter image description here

and run the following command: enter image description here

This creates a new vector layer containing my red lines without any quantitative information in the attribute table.

Can anyone tell me what I am doing wrong?

  • The values should be uploaded to columns in the "to" vector. Those columns must already exists in advance. Do you have columns named "dist" and "to_along" in the "to" line vector?
    – Micha
    Commented Sep 22, 2017 at 6:40
  • Yes, I had created those columns before (see second screenshot). However, it worked now (see answer below). Commented Sep 22, 2017 at 14:38

1 Answer 1


Now it works, I am not sure what I did differently yesterday. As Micha pointed out in the comment above, the columns in the vector layer to be updated have to exist already before running v.distance.

The following code snippet now worked for me (also within QGIS from the toolbox or with two columns to update):

                        {"from": red_lines,
                        "to": blue_lines,
                        "dmax": '-1',
                        "dmin": '-1',
                        "upload": 'dist',
                        "column": 'dist',
                        "GRASS_REGION_PARAMETER": "%f,%f,%f,%f" % (xmin, xmax, ymin, ymax),
                        "from_output": red_lines_update})

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.