# Measuring distance to coast in specific direction using PyQGIS? [closed]

I have a point layer and want to know the distance to the coastline (line or polygon layer) from each point in a series of directions (0, 10, 20, 30 degrees, etc).

I have found this python script (How to visualize updating lines of bearing from a point) that draws radial lines from a point. Using those I can find intersection points using the intersect tool in Geoprocessing. then, I can manually figure out which point along each line is the closest to the initial point... This is not very straightforward and I have several hundred point...

It seems it should be easy to code a python script... any easy solutions?

A strikingly similar Q/A is here. Their question discusses finding the shortest path from a point to a coastline and the answer to their question gives a bit more detail on how to use the GRASS v.distance tool. Give it a shot.

Basically, input your points as the 'from' layer and the coast as the 'to' layer. A new vector map can be created with lines connecting to the nearest points on the to layer.

I know you initially asked about using a series of directions, but further down the question you mention that you will 'manually figure out which point along each line is the closest to the initial point.' So, the above should answer the 'closest line from point to coast' while below is a possible programmatic workflow for using the code sample you linked.

``````1) Clip the radial lines at the coastline

2) Do a series of selections to find the lines touching both the point and the coastline

2.a) Select those lines touching the coastline

2.b) Using 2.a selection set: select those lines that touch the point

3) Sort that subset of lines based on length

4) Line at the top is the shortest from point to coastline.
``````

You can programatically loop through each point creating the spokes for each one and running this process on each point.

• I tried clipping radial lines at the coastline, but that didn't seem to work. Instead, I used qgis:lineintersections to create a point shapefile with the intersections (note that there are more than one intersection per direction because of islands), then qgis:distancematrix to figure out the distances between initial point and all the intersection points in all the directions (direction is an attribute). This can all be done in a loop. the only part that I can't figure out is how to pick the shortest distance for each direction... any min function by attribute I could use? Jun 21, 2016 at 17:59

Yes, you can get the distance to coast (in the continental US) but using this website: https://www.distancetocoast.com/?search=Coconut+Grove%2C+Miami%2C+FL%2C+USA

• While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. Feb 15, 2019 at 8:27