How to get the nearest line from a point?

Given a point (long and lat) within a country for example, how could I know which is the nearest line (like a coastline or international border)?

So basically I want to select the nearest line from a given point. The nearest line could be in all directions or a particular direction.

mapproject -L computes the closest distance from point to line. But the lines must be passed in an ASCII multi-segment file (but not in Julia and gmtmex, ofc)

Ok. Thanks.

And them how can I get the segment (from the multi-segment input). Should I use that distance and 'gmt select -L`, right?

Yes you would have to use gmt select -L but I don’t see how to do it (get the solution) without doing some programming/scripting. It turns out that this is not very different from the answer to this question (point in which polygon) in the Julia forum.

Basically one must search the minimum distance between a point and all lines in the multi-segment, and preferably use a first scan with BoundingBoxes to avoid the more expensive dist-to-line algorithm.

Now I leave it to the bash-lovers to solve it in the shell.

EDIT: Aren’t you in fact looking for the the point in which polygon problem?

Thanks Joaquim. I will have a look.

FYI, I am curious if it possible to create polygons (like DCW) from the GSHHG (or any other data set that replaces it).
My idea if to give GMT a point (like the centroid of a country), 2) search the nearest segments (in the coastline or international border) in all directions, 3) create a close polygon.

1 Like

Short answer is NO. Long answer is also NO. Very long answer is who knows, if with a lot of work. The problem is that GSHHG is organized by bins for performance sake, and those bins ignore administrative limits.

Same issue as above.

Agree with Joaquim on this. The information you need is not available in GSHHG or DCW. And if I remember right, even GADM does not have flags to tell if a segment is coastline or political - is that right?

AFAIK, all is political in GADM

Are you saying NO to my long-term idea? If want to get the closest line from another multi-segment data table?

I’m saying NO to the above.