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:
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:
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.
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.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.