Contents
How to calculate distance from point to LineString in R?
While sf package don’t have a built-in function or geosphere is not compatible with sf objects I would use a wrapper around geosphere::dist2Line function: just getting the matrix of coordinates instead using the entire sf object. I also tried @jsta answer based on sampling the line and I compared the differences between both approaches.
Where are the point and line files located?
The point and line files are currently in geographic coordinates (crs = 4326), but I can reproject them if need be. Based on this question ( How to calculate distance from POINT to LINESTRING in R using `sf` library and get all POINT features from LINESTRING where distances were calculated?)
How to find the nearest line segment to a point?
For example: dist = geosphere::dist2Line (p=st_coordinates (pixels), line = st_coordinates (lines) [,1:2]) But that just gives you the distance from the point to the line. It doesn’t tell you which line segment is closest.
Based on this question ( How to calculate distance from POINT to LINESTRING in R using `sf` library and get all POINT features from LINESTRING where distances were calculated?) I was thinking of using dist2line from geosphere.
How to find nearest line segment to each point in R?
If you are using Mac OS or Windows OS check this post Efficient spatial joining for large dataset in R to build/configure your cluster. Try the reproducible and commented example below. At the end you have the nearest line segment ID ( segnum) to each point ( system.index ).
How to get nearest points between pairs of geometries?
… logical; if FALSE (default) return nearest points between all pairs, if TRUE, return nearest points between subsequent pairs. an sfc object with all two-point LINESTRING geometries of point pairs from the first to the second geometry, of length x * y, with y cycling fastest.
How to find the nearest record of a location?
It will return however many “closest” records you want (the value of k) as well as the distance to each of them. Note: despite being an approximate nearest neighbour, the results are stable on repeated runs of the same data. It doesn’t include a random selection of points or anything.
Which is nearest point to reach in rgeos?
EDIT As suggested by Spacedman’s comment I used rgeos::gNearestPoints. It provided a the nearest point intersecting the reach for the site/reach I provided above, however for another site it provides a nearest point that is still a small distance from the reach: