I have a layer of ~2 million line segments representing rivers, and a layer of ~300 000 line segments representing the coastline. I want to extract the river outlets.

I've tried a bunch of different approaches. It seems like the best way forward is:

  1. Extract the river segment endpoints to reduce the number of points to consider
  2. Compute the distance from the endpoints to the coastline
  3. Discard endpoints that are too far from the coastline, as these are clearly not river outlets
  4. Of the remaining enpoints, choose (for each river name) the point that is closest to the coastline

The problem is bullet point 2. I've tried the builtin Qgis plugin "distance to nearest hub", but it only gives me distance from points to the coastline segments centroid.

There are a lot or related questions on stackexchange, but I haven't yet found a method that works for this large dataset. I've tried the NNJoin plugin, but it never terminates so it probably does not scale well.

Suggestions for plugins, python code or completely other approaches are welcome!


2 Answers 2


Look at the Shortest Line Between Features tool. The end points of the output are on the coastline.

enter image description here


Eventually, I used the "Join attributes by nearest" tool in QGis. This did the trick. Also, I created a spatial index for both layers. Don't know if this made a difference, but the speed was acceptable.

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.