[GIS] Distance to Nearest Hub QGIS not working when ‘hub’ is a line

distanceqgisvector

QGIS 2.18.20 working in CRS: WGS 84/UTM Zone 35S (EPSG:32735 OTF), with shapefiles of map features (roads, river, point water sources) reprojected from WGS84 EPSG:4326.

All shapefiles have been reprojected (in order to be able to work in metres not degrees). Map features originally from GPS source, input to qgis using lat/long coordinates.

I'm trying to run Distance To Nearest Hub analysis for animal sightings (300+ points in one layer) to the various features in my map (see list above). The analysis works well for the point data (e.g. Source= sighting point, Hub= water source point) but not for the line files (road, river, fence).

For the lines, it just seems to choose a central point to that feature and calculate the distance to that one point from the source (sighting) points (see screenshot)enter image description here.

I've tried adding geom info to the line shapefiles but they just add in length and the 'Distance to nearest Hub' analysis ends the same.

Any ideas?

Best Answer

Using Distance to Nearest Hub tool, I reproduced the same situation as you have posted.

enter image description here

My suggestion is to use a GRASS tool v.distance which can be found under ( Processing Toolbox | GRASS GIS 7 | Vector ).

From is your animal siting points and To is the line layer such as the rivers.

enter image description here

To be honest, using v.distance through QGIS processing toolbox is still tricky and challenging. (You may encounter errors by running it in default setting). My workaround is to remove cat in the 'upload' field and leave it blank.

enter image description here

As you can imagine, this does not give you the distance of each line. To obtain the distance from each animal observation to the nearby river, open the attribute table of Distance (output by v.distance) and use the Field calculator to calculate $length.

Related Question