Say I have a shapefile representing the highway network in South America and want to find the minimum geographic distance from that network to another point on the continent. Is there no simple way to do this with the available geospatial packages ?
I understand that I can use nearestPoints() in LibGEOS.jl to find the point in the network closest to the point of interest under a naive Eucludean interpretation of latitude and longitude, and then use another package to compute the distance between the two points in a coordinate reference system such as WGS 1984. But technically thatβs not quite right since the point returned by nearestPoints() might not actually be the nearest point in WGS 1984.
In R, the sf package provides st_distance(), which at least computes great circle distances between various kinds of geometry objects.
The GMT.jl module mapproject can do that. Unfortunately, being a such multi-functionality program I have not yet translated the terse GMT syntax to the verbose version of GMT.jl. The work is done by option -G and in GMT.jl it would be something like
using GMT
D = gmtread("the_shape_file");
mapproject(D, G=(lon,lat)) # Here (lon,lat) is your "point on the continent"
Iβm not sure what a MultiLineString is. But in order to find the distance between, e.g., a line segment and a point, pointwise distances are not sufficient. You also need to determine the actual closest point along the segment.
The missing part is that the closest point might not be an endpoint.
Yes. Thereβs a non-trivial algorithmic step in picking the nearest point in the network and doing that properly in spherical/ellipsoidal coordinates.
Thank you @joa-quim. I tried this. My actual shapefile has 542 entries, each represented with a vector of coordinate pairs. E.g., the first entry has 94 coordinate pairs. Do I understand right that mapproject() is augmenting this data structure with a 3rd column, which holds the distance to each coordinate pair?
If so, then this is not quite the correct algorithm, right? The minimum of the distances to the vertices is not necessarily the minimum distance to the network.
Sorry, itβs not option G itβs option L, which in GMT.jl is aliased to dist2line. (read the linked description of that option)
I know what you are after (I needed that operation several times before) and Iβm sure GMT does it with ellipsoidal accuracy if needed. See this small example that is computing the closest point along the great circle line between [0 0] and [1 1] from point at [0.5 0.5]