3

To get the distance of each polygon centroid from a line, I have tried the Distance to nearest hub algorithm from the Processing Toolbox. The distances I got from the algorithm did not seem correct, upon checking manually. I later tried the v.distance GRASS command from within the Toolbox with the following settings:

v.distance settings

It could be that I am not specifying the options correctly - for example, my "To" layer is a line and I have set the "Column where values specified by ' upload'..." to the "Descriptio" field. If this means that the calculated distances will be uploaded into the field then it could be the source of the issue. However, there is no option to create a new field to hold the distances (besides, a new layer is anyways created so I dont quite understand this setting). Nevertheless, running this command gives an error and QGIS stops working:

v.distance error

I dont know what the error is referring to. Is there some other plugin/algorithm that I can use? Alternatively, what are the correct settings for Distance to nearest hub and v.distance? I would like to achieve this entirely within QGIS, but am open to using R as well.

PS: I am running the latest version of QGIS (2.4 Chugiak) on Win 7 x64. I have already referred to the following questions on GIS SE:

Shortest distance from point to line (big dataset)

Measuring the distance between lines and points in QGIS

UPDATE: I could not get this to work from within QGIS despite trying several permutations of the GRASS v.distance settings. I finally used the gDistance function from the rgeos R package to obtain the result. However, while I have solved my problem for now, I would still like to know if one can do this is QGIS.

  • look at the original GRASS GIS: v.distance – gene Jul 3 '14 at 17:07
  • @gene thanks for the link. the GRASS help page says that the column should already exist in the "To" layer. I created a new column of type double and ran it again with the same error. Since the error has to do with GRASS's inability to "open a vector map on Level 2" I think its an unrelated issue although I'm afraid I have no idea what that means. – avg Jul 3 '14 at 18:38
  • Use directly GRASS GIS – gene Jul 3 '14 at 19:17
  • First note that v.distance (in GRASS 6.4, which is what QGIS uses) finds the distance only from points to lines. So you need to specify the type=centroid option if your (from) layer is polygons. Next you do need to create the target attribute column in your "to" layer (the lines) in advance. – Micha Jul 4 '14 at 13:29
  • @Micha Yes, I knew that v.distance works only with points and hence I am working with the polygon centroids as a separate point layer. I have also created the requisite column in my lines layer and still cannot get it to work. – avg Jul 7 '14 at 14:26
2

The GRASS v.distance function does currently not work from QGIS Processing. See GRASS in QGIS not working (windows XP). You will have to run it through the GRASS plugin.

Update: You could also try the NNJoin plugin. It provides an option to use the centroids of the geometries of polygon (or line) input layers. It may be slow for large datasets.

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.