Basically, I've used a buffer to find all airbases within 100nmi of a coastline. Now what I'd like to do for each of these points is draw a line a) to the nearest point on the coastline, and b) extending for another 100nmi out to sea. Is there a straightforward way to do this?

EDIT: Babel has provided a really good solution and now I'm realizing there's a second issue here - I want to avoid any two bases connecting to a single point. Is there a way to take the results here but distribute them along that coastline? For instance, in the picture here, I've got three bases connecting to two points, but I'd like three relatively evenly spaced ones. Thoughts? map with lines and points)

1 Answer 1


You can do that directly on the point layer of the airbases, using QGIS expressions with "Geometry generator" or "Geometry by expression" (see here for the differences).

Use this expression:

extend (
    make_line (
        closest_point (
            overlay_nearest (
  • Replace coastline on line 6 with the name of your line layer representing the coastline.
  • Replace 100 in line 8 to change the maximum distance the points (airbases) can be away from the coastline and on the second last line for another value for the distance the line extends to the sea.

Only points within the defined distance from the coastline (light blue buffer, for visualization purpose only) are connected to the coastline and extended to the sea:

enter image description here

  • Oh man, this is fantastic. I assume the units here (the "100" etc in your example) are whatever the default is for the projection?
    – Graham J.
    Feb 14, 2022 at 20:41
  • 1
    Yes, that's true
    – Babel
    Feb 15, 2022 at 7:03
  • Hmmm....now I get the whole thing crashing when I try to run the expression. I've increased the size of the airbase dataset a bit, but not significantly; any idea why it wouldn't work now?
    – Graham J.
    Feb 16, 2022 at 22:00
  • It's difficult to say from far away....
    – Babel
    Feb 17, 2022 at 8:09

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.