4

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.

avg
  • 141
  • 4
  • look at the original GRASS GIS: v.distance – gene Jul 03 '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 03 '14 at 18:38
  • Use directly GRASS GIS – gene Jul 03 '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 04 '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 07 '14 at 14:26
  • @Micha can you provide a reason why one needs to use GRASS directly? Is the QGIS version of the plugin "incomplete"? – avg Jul 07 '14 at 14:27
  • sorry, I meant @gene, can you provide a reason why one needs to use GRASS directly? Is the QGIS version of the plugin "incomplete"? – avg Jul 07 '14 at 15:27
  • Because GRASS GIS is not QGIS and you need to understand the commands of GRASS GIS. – gene Jul 07 '14 at 15:53
  • That is not a useful answer. I am, of course, aware that these are two different systems. However, when it is possible to run the plugin from within QGIS complete with a GUI, one would be given to believe that it provides the same functionality as running GRASS from the command line. While I am not averse to doing that, I stated in my question that I wanted to accomplish the task from within QGIS as far as possible when a plugin is available in the Processing Toolbox, hence my follow-up question about whether this functionality is "incomplete". – avg Jul 07 '14 at 16:09
  • The GRASS plugin in QGIS (and the whole Processing menu for that matter) are meant to be a bit more "user friendly" than the full GRASS/SAGA/OTB packages. As such some less used options are left out. So, you might say that the QGIS implementation is "incomplete". I wouldn't put it that way, just more accessible. – Micha Jul 08 '14 at 11:49

1 Answers1

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.

Håvard Tveite
  • 3,256
  • 17
  • 32